fix: plugin/updater: can fail if update happens while the new file is uploading

Massimo Melina committed Aug 20, 2023 at 15:22 UTC c5a361b78f3aef3bc365f5359bcc388f96f643b3
1 file changed +4 -3
plugins/updater-disabled/plugin.js
+4 -3
@@ -5,11 +5,12 @@ Its capability is to offer automatic restart when an update is available in the
5 Tip: In my case I'm uploading "hfs.exe-new" over ftp, and it's a bit slow, so to avoid the plugin to catch
6 an unfinished file, I do the upload using a temporary name, and only when it's done I rename it to "hfs.exe-new".
7 */
8 -exports.version = 0.2
8 +exports.version = 0.3
9 exports.description = "automatic restart when an update is available in the form of hfs.exe-new file"
10 exports.apiRequired = 3 // api.log
11
12 const NEW = 'hfs.exe-new'
13 +const UPDATING = 'hfs.exe-updating'
14 const BATCH_NAME = 'run-updater.bat'
15 const BATCH = `@echo off
16 :loop
@@ -19,7 +20,7 @@ hfs %*
20 endlocal
21 if exist hfs.exe-new (
22 move /y hfs.exe hfs.exe-old
22 - move /y ${NEW} hfs.exe
23 + move /y ${UPDATING} hfs.exe
24 goto loop
25 )
26 `
@@ -33,7 +34,7 @@ exports.init = async api => {
34
35 api.log("ready")
36 const timer = setInterval(() => {
36 - fs.access(NEW, fs.constants.W_OK, err => {
37 + fs.rename(NEW, UPDATING, err => {
38 if (err) return
39 api.log("exiting for update")
40 process.exit(0)