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