@samitouri / QOSami-HFS / commits / 5c55c59e

fix: update not working if hfs is in a path with a space

Massimo Melina committed Jul 2, 2024 at 18:14 UTC 5c55c59e8d62f20687101e87f225480d76535e66
2 files changed +8 -4
src/update.ts
+3 -3
@@ -7,11 +7,11 @@ import { spawn, spawnSync } from 'child_process'
7 import { exists, httpStream, prefix, unzip, xlate } from './misc'
8 import { createReadStream, renameSync, unlinkSync } from 'fs'
9 import { pluginsWatcher } from './plugins'
10 -import { access, chmod, stat } from 'fs/promises'
10 +import { chmod, stat } from 'fs/promises'
11 import { Readable } from 'stream'
12 import open from 'open'
13 import { currentVersion, defineConfig, versionToScalar } from './config'
14 -import { RUNNING_AS_SERVICE } from './util-os'
14 +import { cmdEscape, RUNNING_AS_SERVICE } from './util-os'
15 import { onProcessExit } from './first'
16
17 const updateToBeta = defineConfig('update_to_beta', false)
@@ -129,7 +129,7 @@ export async function update(tagOrUrl: string='') {
129 }
130
131 function launch(cmd: string, pars: string[]=[], options?: { sync: boolean } & Parameters<typeof spawn>[2]) {
132 - return (options?.sync ? spawnSync : spawn)(cmd, pars, { detached: true, shell: true, stdio: [0,1,2], ...options })
132 + return (options?.sync ? spawnSync : spawn)(cmdEscape(cmd), pars, { detached: true, shell: true, stdio: [0,1,2], ...options })
133 }
134
135 if (argv.updating) { // we were launched with a temporary name, restore original name to avoid breaking references
src/util-os.ts
+5 -1
@@ -19,7 +19,11 @@ export function getDiskSpaceSync(path: string) {
19 catch(e: any) { throw parseDfResult(e) }
20 }
21
22 -function bashEscape(par: string) {
22 +export function bashEscape(par: string) {
23 + return `"${par.replaceAll('"', '\\"')}"`
24 +}
25 +
26 +export function cmdEscape(par: string) {
27 return `"${par.replaceAll('"', '\\"')}"`
28 }
29