File tree 3 files changed +22
-22
lines changed
3 files changed +22
-22
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import (
19
19
20
20
"github.com/arduino/arduino-create-agent/systray"
21
21
"github.com/arduino/arduino-create-agent/tools"
22
+ "github.com/arduino/arduino-create-agent/updater"
22
23
"github.com/arduino/arduino-create-agent/utilities"
23
24
v2 "github.com/arduino/arduino-create-agent/v2"
24
25
"github.com/gin-gonic/gin"
@@ -130,22 +131,15 @@ func main() {
130
131
131
132
// If the executable is temporary, copy it to the full path, then restart
132
133
if strings .Contains (path , "-temp" ) {
133
- correctPath := strings .Replace (path , "-temp" , "" , - 1 )
134
- err := copyExe (path , correctPath )
134
+ err := copyExe (path , updater .BinPath (path ))
135
135
if err != nil {
136
136
panic (err )
137
137
}
138
138
139
139
Systray .Restart ()
140
140
} else {
141
141
// Otherwise copy to a path with -temp suffix
142
- correctPath := path
143
- if filepath .Ext (path ) == "exe" {
144
- path = strings .Replace (path , ".exe" , "-temp.exe" , - 1 )
145
- } else {
146
- path = path + "-temp"
147
- }
148
- err := copyExe (path , correctPath )
142
+ err := copyExe (path , updater .TempPath (path ))
149
143
if err != nil {
150
144
panic (err )
151
145
}
Original file line number Diff line number Diff line change 30
30
package main
31
31
32
32
import (
33
- "path/filepath"
34
- "strings"
35
-
36
33
"github.com/arduino/arduino-create-agent/updater"
37
34
"github.com/gin-gonic/gin"
38
35
"github.com/kardianos/osext"
@@ -63,11 +60,7 @@ func updateHandler(c *gin.Context) {
63
60
return
64
61
}
65
62
66
- if filepath .Ext (path ) == "exe" {
67
- path = strings .Replace (path , ".exe" , "-temp.exe" , - 1 )
68
- } else {
69
- path = path + "-temp"
70
- }
63
+ path = updater .TempPath (path )
71
64
72
65
c .JSON (200 , gin.H {"success" : "Please wait a moment while the agent reboots itself" })
73
66
Systray .Update (path )
Original file line number Diff line number Diff line change @@ -57,6 +57,22 @@ const devValidTime = 7 * 24 * time.Hour
57
57
var errHashMismatch = errors .New ("new file hash mismatch after patch" )
58
58
var up = update .New ()
59
59
60
+ // TempPath generates a temporary path for the executable
61
+ func TempPath (path string ) string {
62
+ if filepath .Ext (path ) == "exe" {
63
+ path = strings .Replace (path , ".exe" , "-temp.exe" , - 1 )
64
+ } else {
65
+ path = path + "-temp"
66
+ }
67
+
68
+ return path
69
+ }
70
+
71
+ // TempPath generates the proper path for a temporary executable
72
+ func BinPath (path string ) string {
73
+ return strings .Replace (path , "-temp" , "" , - 1 )
74
+ }
75
+
60
76
// Updater is the configuration and runtime data for doing an update.
61
77
//
62
78
// Note that ApiURL, BinURL and DiffURL should have the same value if all files are available at the same location.
@@ -203,11 +219,8 @@ func (u *Updater) update() error {
203
219
if err != nil {
204
220
return err
205
221
}
206
- if filepath .Ext (path ) == "exe" {
207
- path = strings .Replace (path , ".exe" , "-temp.exe" , - 1 )
208
- } else {
209
- path = path + "-temp"
210
- }
222
+
223
+ path = TempPath (path )
211
224
212
225
old , err := os .Open (path )
213
226
if err != nil {
You can’t perform that action at this time.
0 commit comments