Skip to content

Commit 1c0d413

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 1c0d413

File tree

3 files changed

+50
-30
lines changed

3 files changed

+50
-30
lines changed

updater/updater.go

+33
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ import (
2222
"fmt"
2323
"io"
2424
"net/http"
25+
"os"
26+
"path/filepath"
2527
"runtime"
28+
"strings"
2629

2730
log "github.com/sirupsen/logrus"
2831
)
@@ -77,3 +80,33 @@ func fetch(url string) (io.ReadCloser, error) {
7780
}
7881
return resp.Body, nil
7982
}
83+
84+
// addTempSuffixToPath adds the "-temp" suffix to the path to an executable file (a ".exe" extension is replaced with "-temp.exe")
85+
func addTempSuffixToPath(path string) string {
86+
if filepath.Ext(path) == "exe" {
87+
path = strings.Replace(path, ".exe", "-temp.exe", -1)
88+
} else {
89+
path = path + "-temp"
90+
}
91+
92+
return path
93+
}
94+
95+
// removeTempSuffixFromPath removes "-temp" suffix from the path to an executable file (a "-temp.exe" extension is replaced with ".exe")
96+
func removeTempSuffixFromPath(path string) string {
97+
return strings.Replace(path, "-temp", "", -1)
98+
}
99+
100+
func copyExe(from, to string) error {
101+
data, err := os.ReadFile(from)
102+
if err != nil {
103+
log.Println("Cannot read file: ", from)
104+
return err
105+
}
106+
err = os.WriteFile(to, data, 0755)
107+
if err != nil {
108+
log.Println("Cannot write file: ", to)
109+
return err
110+
}
111+
return nil
112+
}

updater/updater_darwin.go

+17
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,30 @@ import (
4646
"io"
4747
"os"
4848
"runtime"
49+
"strings"
4950

5051
"github.com/arduino/go-paths-helper"
5152
"github.com/codeclysm/extract/v3"
5253
"github.com/sirupsen/logrus"
54+
log "github.com/sirupsen/logrus"
5355
)
5456

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

updater/updater_default.go

-30
Original file line numberDiff line numberDiff line change
@@ -97,36 +97,6 @@ func checkForUpdates(currentVersion string, updateURL string, cmdName string) (s
9797
return addTempSuffixToPath(path), nil
9898
}
9999

100-
func copyExe(from, to string) error {
101-
data, err := os.ReadFile(from)
102-
if err != nil {
103-
log.Println("Cannot read file: ", from)
104-
return err
105-
}
106-
err = os.WriteFile(to, data, 0755)
107-
if err != nil {
108-
log.Println("Cannot write file: ", to)
109-
return err
110-
}
111-
return nil
112-
}
113-
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-
130100
// Updater is the configuration and runtime data for doing an update.
131101
//
132102
// 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)