Skip to content

Commit 12502c8

Browse files
committed
Added more logging and fixed upgrade procedure
1 parent c8f0207 commit 12502c8

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

updater/updater_darwin.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
"github.com/arduino/go-paths-helper"
2727
"github.com/codeclysm/extract/v3"
28+
"github.com/sirupsen/logrus"
2829
)
2930

3031
func start(src string) string {
@@ -56,12 +57,17 @@ func checkForUpdates(currentVersion string, updateAPIURL, updateBinURL string, c
5657
}
5758

5859
tmp := paths.TempDir().Join("arduino-create-agent")
60+
if err := tmp.MkdirAll(); err != nil {
61+
return "", err
62+
}
5963
tmpZip := tmp.Join("update.zip")
6064
tmpAppPath := tmp.Join("ArduinoCreateAgent-update.app")
6165
defer tmp.RemoveAll()
6266

6367
// Download the update.
64-
download, err := fetch(updateBinURL + cmdName + "/" + plat + "/" + info.Version + "/" + cmdName)
68+
downloadURL := updateBinURL + cmdName + "/" + info.Version + "/ArduinoCreateAgent.app_notarized.zip"
69+
logrus.WithField("url", downloadURL).Info("Downloading update")
70+
download, err := fetch(downloadURL)
6571
if err != nil {
6672
return "", err
6773
}
@@ -85,6 +91,7 @@ func checkForUpdates(currentVersion string, updateAPIURL, updateBinURL string, c
8591
}
8692

8793
// Unzip the update
94+
logrus.WithField("tmpDir", tmpAppPath).Info("Unzipping update")
8895
if err := tmpAppPath.MkdirAll(); err != nil {
8996
return "", fmt.Errorf("could not create tmp dir to unzip update: %w", err)
9097
}
@@ -99,11 +106,13 @@ func checkForUpdates(currentVersion string, updateAPIURL, updateBinURL string, c
99106
}
100107

101108
// Rename current app as .old
109+
logrus.WithField("from", currentAppPath).WithField("to", oldAppPath).Info("Renaming old app")
102110
if err := currentAppPath.Rename(oldAppPath); err != nil {
103111
return "", fmt.Errorf("could not rename old app as .old: %w", err)
104112
}
105113

106114
// Install new app
115+
logrus.WithField("from", tmpAppPath).WithField("to", currentAppPath).Info("Copying updated app")
107116
if err := tmpAppPath.CopyDirTo(currentAppPath); err != nil {
108117
// Try rollback changes
109118
_ = currentAppPath.RemoveAll()
@@ -112,8 +121,11 @@ func checkForUpdates(currentVersion string, updateAPIURL, updateBinURL string, c
112121
}
113122

114123
// Remove old app
124+
logrus.WithField("to", oldAppPath).Info("Removing old app")
115125
_ = oldAppPath.RemoveAll()
116126

117127
// Restart agent
118-
return currentAppPath.Join("Contents", "MacOS", "Arduino_Create_Agent").String(), nil
128+
newExecutable := currentAppPath.Join("Contents", "MacOS", "Arduino_Create_Agent")
129+
logrus.WithField("path", newExecutable).Info("Running new app")
130+
return newExecutable.String(), nil
119131
}

0 commit comments

Comments
 (0)