Skip to content

Commit f32e6e6

Browse files
committed
Added more logging and fixed upgrade procedure
1 parent 3ec68be commit f32e6e6

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

updater/updater_macos.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727

2828
"github.com/arduino/go-paths-helper"
2929
"github.com/codeclysm/extract/v3"
30+
"github.com/sirupsen/logrus"
3031
)
3132

3233
func start(src string) string {
@@ -58,12 +59,17 @@ func checkForUpdates(currentVersion string, updateAPIURL, updateBinURL string, c
5859
}
5960

6061
tmp := paths.TempDir().Join("arduino-create-agent")
62+
if err := tmp.MkdirAll(); err != nil {
63+
return "", err
64+
}
6165
tmpZip := tmp.Join("update.zip")
6266
tmpAppPath := tmp.Join("ArduinoCreateAgent-update.app")
6367
defer tmp.RemoveAll()
6468

6569
// Download the update.
66-
download, err := fetch(updateBinURL + cmdName + "/" + plat + "/" + info.Version + "/" + cmdName)
70+
downloadURL := updateBinURL + cmdName + "/" + info.Version + "/ArduinoCreateAgent.app_notarized.zip"
71+
logrus.WithField("url", downloadURL).Info("Downloading update")
72+
download, err := fetch(downloadURL)
6773
if err != nil {
6874
return "", err
6975
}
@@ -87,6 +93,7 @@ func checkForUpdates(currentVersion string, updateAPIURL, updateBinURL string, c
8793
}
8894

8995
// Unzip the update
96+
logrus.WithField("tmpDir", tmpAppPath).Info("Unzipping update")
9097
if err := tmpAppPath.MkdirAll(); err != nil {
9198
return "", fmt.Errorf("could not create tmp dir to unzip update: %w", err)
9299
}
@@ -101,11 +108,13 @@ func checkForUpdates(currentVersion string, updateAPIURL, updateBinURL string, c
101108
}
102109

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

108116
// Install new app
117+
logrus.WithField("from", tmpAppPath).WithField("to", currentAppPath).Info("Copying updated app")
109118
if err := tmpAppPath.CopyDirTo(currentAppPath); err != nil {
110119
// Try rollback changes
111120
_ = currentAppPath.RemoveAll()
@@ -114,8 +123,11 @@ func checkForUpdates(currentVersion string, updateAPIURL, updateBinURL string, c
114123
}
115124

116125
// Remove old app
126+
logrus.WithField("to", oldAppPath).Info("Removing old app")
117127
_ = oldAppPath.RemoveAll()
118128

119129
// Restart agent
120-
return currentAppPath.Join("Contents", "MacOS", "Arduino_Create_Agent").String(), nil
130+
newExecutable := currentAppPath.Join("Contents", "MacOS", "Arduino_Create_Agent")
131+
logrus.WithField("path", newExecutable).Info("Running new app")
132+
return newExecutable.String(), nil
121133
}

0 commit comments

Comments
 (0)