fix: upload in a to-be-created folder was skipping check of available-space
Massimo Melina committed
May 30, 2024 at 19:23 UTC
4e0c565bc67f217edf4a5e3b957354996f58877c
1 file changed
+4
-1
src/util-os.ts
+4
-1
@@ -1,4 +1,5 @@
1
-import { resolve } from 'path'
1
+import { dirname, resolve } from 'path'
2
+import { existsSync } from 'fs'
3
import { exec, execSync } from 'child_process'
4
import { onlyTruthy, splitAt, try_ } from './misc'
5
import _ from 'lodash'
@@ -15,6 +16,8 @@ export function getDiskSpaceSync(path: string) {
16
throw Error('miss')
17
return { free: Number(one.FreeSpace), total: Number(one.Size) }
18
}
19
+ while (path && !existsSync(path))
20
+ path = dirname(path)
21
const out = try_(() => execSync(`df -k "${path}"`).toString(),
22
err => { throw err.status === 1 ? Error('miss') : err.status === 127 ? Error('unsupported') : err })
23
if (!out?.startsWith('Filesystem'))