@samitouri / QOSami-HFS / commits / 5d571cb4

rename hfs-update.zip after applying

Massimo Melina committed Sep 24, 2024 at 23:41 UTC 5d571cb4aeebb895f7e1bace2bcd112e5f03345e
1 file changed +6 -2
src/update.ts
+6 -2
@@ -7,7 +7,7 @@ import { spawn, spawnSync } from 'child_process'
7 import { DAY, exists, debounceAsync, httpStream, unzip, prefix, xlate, HOUR } from './misc'
8 import { createReadStream, renameSync, unlinkSync } from 'fs'
9 import { pluginsWatcher } from './plugins'
10 -import { chmod, stat } from 'fs/promises'
10 +import { chmod, rename, stat } from 'fs/promises'
11 import { Readable } from 'stream'
12 import open from 'open'
13 import { currentVersion, defineConfig, versionToScalar } from './config'
@@ -104,8 +104,9 @@ export async function updateSupported() {
104
105 export async function update(tagOrUrl: string='') {
106 if (!await updateSupported()) throw "only binary versions supports automatic update for now"
107 + let doingLocal = ''
108 let updateSource: Readable | false = tagOrUrl.includes('://') ? await httpStream(tagOrUrl)
108 - : await localUpdateAvailable() && createReadStream(LOCAL_UPDATE)
109 + : await localUpdateAvailable() && createReadStream(doingLocal=LOCAL_UPDATE)
110 if (!updateSource) {
111 if (/^\d/.test(tagOrUrl)) // work even if the tag is passed without the initial 'v' (useful for console commands)
112 tagOrUrl = 'v' + tagOrUrl
@@ -149,6 +150,9 @@ export async function update(tagOrUrl: string='') {
150 catch {}
151 renameSync(bin, oldBin)
152 console.log("launching new version in background", newBinFile)
153 + if (doingLocal)
154 + try { renameSync(doingLocal, 'old-' + doingLocal) }
155 + catch(e) { console.warn(e) }
156 launch(newBin, ['--updating', binFile], { sync: true }) // sync necessary to work on Mac by double-click
157 })
158 console.log("quitting")