Skip to content

Commit 8429a38

Browse files
committed
Always complete the old auto-upgrade procedure
This is required for clients upgrading from versions <=1.2.7
1 parent 599a221 commit 8429a38

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

updater/updater.go

+18
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ import (
2222
"fmt"
2323
"io"
2424
"net/http"
25+
"path/filepath"
2526
"runtime"
27+
"strings"
2628

2729
log "github.com/sirupsen/logrus"
2830
)
@@ -77,3 +79,19 @@ func fetch(url string) (io.ReadCloser, error) {
7779
}
7880
return resp.Body, nil
7981
}
82+
83+
// addTempSuffixToPath adds the "-temp" suffix to the path to an executable file (a ".exe" extension is replaced with "-temp.exe")
84+
func addTempSuffixToPath(path string) string {
85+
if filepath.Ext(path) == "exe" {
86+
path = strings.Replace(path, ".exe", "-temp.exe", -1)
87+
} else {
88+
path = path + "-temp"
89+
}
90+
91+
return path
92+
}
93+
94+
// removeTempSuffixFromPath removes "-temp" suffix from the path to an executable file (a "-temp.exe" extension is replaced with ".exe")
95+
func removeTempSuffixFromPath(path string) string {
96+
return strings.Replace(path, "-temp", "", -1)
97+
}

updater/updater_darwin.go

+15
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,21 @@ import (
5353
)
5454

5555
func start(src string) string {
56+
if strings.Contains(src, "-temp") {
57+
// This is required to transition from the previous auto-update system to the new one.
58+
// Updating from version <=1.2.7 will produce the `ArduinoCreateAgent-temp` file and we should
59+
// complete the upgrade by copying the `ArduinoCreateAgent-temp` executable back to the original.
60+
//
61+
// This procedure will be automatically skipped starting from version >1.2.7.
62+
63+
newPath := removeTempSuffixFromPath(src)
64+
if err := copyExe(src, newPath); err != nil {
65+
log.Println("Copy error: ", err)
66+
panic(err)
67+
}
68+
return newPath
69+
}
70+
5671
return ""
5772
}
5873

updater/updater_default.go

-16
Original file line numberDiff line numberDiff line change
@@ -111,22 +111,6 @@ func copyExe(from, to string) error {
111111
return nil
112112
}
113113

114-
// addTempSuffixToPath adds the "-temp" suffix to the path to an executable file (a ".exe" extension is replaced with "-temp.exe")
115-
func addTempSuffixToPath(path string) string {
116-
if filepath.Ext(path) == "exe" {
117-
path = strings.Replace(path, ".exe", "-temp.exe", -1)
118-
} else {
119-
path = path + "-temp"
120-
}
121-
122-
return path
123-
}
124-
125-
// removeTempSuffixFromPath removes "-temp" suffix from the path to an executable file (a "-temp.exe" extension is replaced with ".exe")
126-
func removeTempSuffixFromPath(path string) string {
127-
return strings.Replace(path, "-temp", "", -1)
128-
}
129-
130114
// Updater is the configuration and runtime data for doing an update.
131115
//
132116
// Note that ApiURL, BinURL and DiffURL should have the same value if all files are available at the same location.

0 commit comments

Comments
 (0)