@samitouri / QOSami-HFS / commits / 4eda08f9

sounder: have a timeout for disk-space check

Massimo Melina committed Jun 24, 2024 at 12:30 UTC 4eda08f94204822cbd95cd7b05be78c82ea49c5e
1 file changed +3 -2
src/util-os.ts
+3 -2
@@ -8,9 +8,10 @@ import { promisify } from 'util'
8 import { IS_WINDOWS } from './const'
9
10 export function getDiskSpaceSync(path: string) {
11 + const timeout = 1000
12 if (IS_WINDOWS) {
13 const drive = resolve(path).slice(0, 2).toUpperCase()
13 - const out = execSync('wmic logicaldisk get Size,FreeSpace,Name /format:list').toString().replace(/\r/g, '')
14 + const out = execSync('wmic logicaldisk get Size,FreeSpace,Name /format:list', { timeout }).toString().replace(/\r/g, '')
15 const one = parseKeyValueObjects(out).find(x => x.Name === drive)
16 if (!one)
17 throw Error('miss')
@@ -18,7 +19,7 @@ export function getDiskSpaceSync(path: string) {
19 }
20 while (path && !existsSync(path))
21 path = dirname(path)
21 - const out = try_(() => execSync(`df -k "${path}"`).toString(),
22 + const out = try_(() => execSync(`df -k "${path}"`, { timeout }).toString(),
23 err => { throw err.status === 1 ? Error('miss') : err.status === 127 ? Error('unsupported') : err })
24 if (!out?.startsWith('Filesystem'))
25 throw Error('unsupported')