@@ -25,6 +25,7 @@ import (
25
25
26
26
"github.com/arduino/go-paths-helper"
27
27
"github.com/codeclysm/extract/v3"
28
+ "github.com/sirupsen/logrus"
28
29
)
29
30
30
31
func start (src string ) string {
@@ -56,12 +57,17 @@ func checkForUpdates(currentVersion string, updateAPIURL, updateBinURL string, c
56
57
}
57
58
58
59
tmp := paths .TempDir ().Join ("arduino-create-agent" )
60
+ if err := tmp .MkdirAll (); err != nil {
61
+ return "" , err
62
+ }
59
63
tmpZip := tmp .Join ("update.zip" )
60
64
tmpAppPath := tmp .Join ("ArduinoCreateAgent-update.app" )
61
65
defer tmp .RemoveAll ()
62
66
63
67
// 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 )
65
71
if err != nil {
66
72
return "" , err
67
73
}
@@ -85,6 +91,7 @@ func checkForUpdates(currentVersion string, updateAPIURL, updateBinURL string, c
85
91
}
86
92
87
93
// Unzip the update
94
+ logrus .WithField ("tmpDir" , tmpAppPath ).Info ("Unzipping update" )
88
95
if err := tmpAppPath .MkdirAll (); err != nil {
89
96
return "" , fmt .Errorf ("could not create tmp dir to unzip update: %w" , err )
90
97
}
@@ -99,11 +106,13 @@ func checkForUpdates(currentVersion string, updateAPIURL, updateBinURL string, c
99
106
}
100
107
101
108
// Rename current app as .old
109
+ logrus .WithField ("from" , currentAppPath ).WithField ("to" , oldAppPath ).Info ("Renaming old app" )
102
110
if err := currentAppPath .Rename (oldAppPath ); err != nil {
103
111
return "" , fmt .Errorf ("could not rename old app as .old: %w" , err )
104
112
}
105
113
106
114
// Install new app
115
+ logrus .WithField ("from" , tmpAppPath ).WithField ("to" , currentAppPath ).Info ("Copying updated app" )
107
116
if err := tmpAppPath .CopyDirTo (currentAppPath ); err != nil {
108
117
// Try rollback changes
109
118
_ = currentAppPath .RemoveAll ()
@@ -112,8 +121,11 @@ func checkForUpdates(currentVersion string, updateAPIURL, updateBinURL string, c
112
121
}
113
122
114
123
// Remove old app
124
+ logrus .WithField ("to" , oldAppPath ).Info ("Removing old app" )
115
125
_ = oldAppPath .RemoveAll ()
116
126
117
127
// 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
119
131
}
0 commit comments