|
54 | 54 |
|
55 | 55 | // the important folders of the agent
|
56 | 56 | var (
|
57 |
| - src, _ = os.Executable() |
58 |
| - srcPath = paths.New(src) // The path of the agent's binary |
59 |
| - srcDir = srcPath.Parent() // The directory of the agent's binary |
60 | 57 | usr, _ = user.Current()
|
61 | 58 | usrDir = paths.New(usr.HomeDir) // The user folder, on linux/macos /home/<usr>/
|
62 | 59 | agentDir = usrDir.Join(".arduino-create")
|
@@ -172,19 +169,18 @@ func main() {
|
172 | 169 | }
|
173 | 170 |
|
174 | 171 | // If the executable is temporary, copy it to the full path, then restart
|
175 |
| - if strings.Contains(srcPath.String(), "-temp") { |
176 |
| - newPath := updater.BinPath(srcPath.String()) |
177 |
| - err := copyExe(srcPath.String(), newPath) |
178 |
| - if err != nil { |
| 172 | + if src, err := os.Executable(); err != nil { |
| 173 | + panic(err) |
| 174 | + } else if strings.Contains(src, "-temp") { |
| 175 | + newPath := updater.RemoveTempSuffixFromPath(src) |
| 176 | + if err := copyExe(src, newPath); err != nil { |
179 | 177 | log.Println("Copy error: ", err)
|
180 | 178 | panic(err)
|
181 | 179 | }
|
182 |
| - |
183 | 180 | Systray.RestartWith(newPath)
|
184 | 181 | } else {
|
185 | 182 | // Otherwise copy to a path with -temp suffix
|
186 |
| - err := copyExe(srcPath.String(), updater.TempPath(srcPath.String())) |
187 |
| - if err != nil { |
| 183 | + if err := copyExe(src, updater.AddTempSuffixToPath(src)); err != nil { |
188 | 184 | panic(err)
|
189 | 185 | }
|
190 | 186 | Systray.Start()
|
@@ -230,7 +226,9 @@ func loop() {
|
230 | 226 | log.Infof("using config from default: %s", configPath)
|
231 | 227 | // take the config from the old folder where the agent's binary sits
|
232 | 228 | } else {
|
233 |
| - oldConfigPath := srcDir.Join("config.ini") |
| 229 | + // Fall back to the old config.ini location |
| 230 | + src, _ := os.Executable() |
| 231 | + oldConfigPath := paths.New(src).Parent().Join("config.ini") |
234 | 232 | if oldConfigPath.Exist() {
|
235 | 233 | err := oldConfigPath.CopyTo(agentDir.Join("config.ini"))
|
236 | 234 | if err != nil {
|
|
0 commit comments