@samitouri / QOSami-HFS / commits / 45cce4d2

fix: remote-execution with upload permissions on mac+linux. Thanks to @charmindoge for reporting

Massimo Melina committed Jul 2, 2024 at 21:25 UTC 45cce4d2d87f1e97c8c0e3b6e575cf1864e326c7
1 file changed +4 -3
src/util-os.ts
+4 -3
@@ -1,6 +1,6 @@
1 import { dirname, resolve } from 'path'
2 import { existsSync } from 'fs'
3 -import { exec, ExecOptions, execSync } from 'child_process'
3 +import { exec, ExecOptions, execSync, spawnSync } from 'child_process'
4 import { exists, onlyTruthy, prefix, splitAt } from './misc'
5 import _ from 'lodash'
6 import { pid } from 'node:process'
@@ -10,17 +10,18 @@ import { IS_WINDOWS } from './const'
10 const DF_TIMEOUT = 2000
11 const LOGICALDISK_TIMEOUT = DF_TIMEOUT
12
13 +// not using statfsSync because it's not available in node 18.5.0 (latest version with pkg)
14 export function getDiskSpaceSync(path: string) {
15 if (IS_WINDOWS)
16 return parseLogicaldisk(execSync(makeLogicaldisk(path), { timeout: LOGICALDISK_TIMEOUT }).toString())[0]
17 while (path && !existsSync(path))
18 path = dirname(path)
18 - try { return parseDfResult(execSync(`df -k ${bashEscape(path)}`, { timeout: DF_TIMEOUT }).toString())[0] }
19 + try { return parseDfResult(spawnSync('df', ['-k', path], { timeout: DF_TIMEOUT }).stdout.toString())[0] }
20 catch(e: any) { throw parseDfResult(e) }
21 }
22
23 export function bashEscape(par: string) {
23 - return `"${par.replaceAll('"', '\\"')}"`
24 + return `'${par.replaceAll(/(["'$`\\])/g, "\\$1")}'`
25 }
26
27 export function cmdEscape(par: string) {