fix: run-updater not working #114

Massimo Melina committed Feb 22, 2023 at 22:41 UTC 05a89616864257a9d8e5aa0a2b7b6a2217713b65
2 files changed +7 -7
src/const.ts
+3 -3
@@ -44,8 +44,8 @@ export const HTTP_FOOL = 418
44 export const HTTP_SERVER_ERROR = 500
45
46 export const IS_WINDOWS = process.platform === 'win32'
47 -const IS_BINARY = !basename(process.argv0).includes('node') // this won't be node if pkg was used
48 -export const APP_PATH = dirname(IS_BINARY ? process.argv0 : __dirname)
47 +export const IS_BINARY = !basename(process.execPath).includes('node') // this won't be node if pkg was used
48 +export const APP_PATH = dirname(IS_BINARY ? process.execPath : __dirname)
49
50 // we want this to be the first stuff to be printed, then we print it in this module, that is executed at the beginning
51 if (DEV) console.clear()
@@ -57,7 +57,7 @@ console.log('version', VERSION||'-')
57 console.log('build', BUILD_TIMESTAMP||'-')
58 if (argv.cwd)
59 process.chdir(argv.cwd)
60 -else if (!process.argv0.endsWith('.exe')) { // still considering whether to use this behavior with Windows users, who may be less accustomed to it
60 +else if (!process.execPath.endsWith('.exe')) { // still considering whether to use this behavior with Windows users, who may be less accustomed to it
61 const dir = join(homedir(), '.hfs')
62 try { mkdirSync(dir) }
63 catch(e: any) {
src/update.ts
+4 -4
@@ -1,7 +1,7 @@
1 // This file is part of HFS - Copyright 2021-2023, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
2
3 import { getRepoInfo } from './github'
4 -import { argv, IS_WINDOWS, VERSION } from './const'
4 +import { argv, IS_BINARY, IS_WINDOWS, VERSION } from './const'
5 import { basename, dirname, join } from 'path'
6 import { spawn } from 'child_process'
7 import { httpsStream, onProcessExit, unzip } from './misc'
@@ -19,7 +19,7 @@ export async function getUpdate() {
19 }
20
21 export async function update() {
22 - if (process.argv0.endsWith('node'))
22 + if (!IS_BINARY)
23 throw "only binary versions are supported for now"
24 const update = await getUpdate()
25 const assetSearch = ({ win32: 'windows', darwin: 'mac', linux: 'linux' } as any)[process.platform]
@@ -30,7 +30,7 @@ export async function update() {
30 throw "asset not found"
31 const url = asset.browser_download_url
32 console.log("downloading", url)
33 - const bin = process.argv0
33 + const bin = process.execPath
34 const binPath = dirname(bin)
35 const binFile = basename(bin)
36 const newBinFile = 'new-' + binFile
@@ -63,7 +63,7 @@ export async function update() {
63 }
64
65 if (argv.updating) { // we were launched with a temporary name, restore original name to avoid breaking references
66 - const bin = process.argv0
66 + const bin = process.execPath
67 renameSync(bin, join(dirname(bin), argv.updating))
68 console.log("renamed binary file to", argv.updating)
69 }