fix: update console command was not working twice in a row

Massimo Melina committed Apr 23, 2023 at 20:29 UTC 5a3c767519599b8c9a53bf32e6aea85014fc2f50
1 file changed +9 -1
src/update.ts
+9 -1
@@ -62,6 +62,14 @@ export async function update() {
62
63 if (argv.updating) { // we were launched with a temporary name, restore original name to avoid breaking references
64 const bin = process.execPath
65 - renameSync(bin, join(dirname(bin), argv.updating))
65 + const dest = join(dirname(bin), argv.updating)
66 + renameSync(bin, dest)
67 console.log("renamed binary file to", argv.updating)
68 + // have to relaunch with new name, or otherwise next update will fail with EBUSY on hfs.exe
69 + onProcessExit(() => {
70 + spawn(dest, [], { detached: true, shell: true })
71 + .on('error', console.error)
72 + })
73 + console.log('restarting')
74 + process.exit()
75 }