Skip to content

Commit d28cb56

Browse files
committed
make the important folders of the agent global
1 parent e9b64d7 commit d28cb56

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

main.go

+14-17
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ var (
5252
requiredToolsAPILevel = "v1"
5353
)
5454

55+
// the important folders of the agent
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+
usr, _ = user.Current()
61+
usrDir = paths.New(usr.HomeDir) // The user folder, on linux/macos /home/<usr>/
62+
agentDir = usrDir.Join(".arduino-create")
63+
)
64+
5565
// regular flags
5666
var (
5767
hibernate = flag.Bool("hibernate", false, "start hibernated")
@@ -149,15 +159,10 @@ func main() {
149159
AdditionalConfig: *additionalConfig,
150160
}
151161

152-
path, err := os.Executable()
153-
if err != nil {
154-
panic(err)
155-
}
156-
157162
// If the executable is temporary, copy it to the full path, then restart
158-
if strings.Contains(path, "-temp") {
159-
newPath := updater.BinPath(path)
160-
err := copyExe(path, newPath)
163+
if strings.Contains(srcPath.String(), "-temp") {
164+
newPath := updater.BinPath(srcPath.String())
165+
err := copyExe(srcPath.String(), newPath)
161166
if err != nil {
162167
log.Println("Copy error: ", err)
163168
panic(err)
@@ -166,7 +171,7 @@ func main() {
166171
Systray.Update(newPath)
167172
} else {
168173
// Otherwise copy to a path with -temp suffix
169-
err := copyExe(path, updater.TempPath(path))
174+
err := copyExe(srcPath.String(), updater.TempPath(srcPath.String()))
170175
if err != nil {
171176
panic(err)
172177
}
@@ -196,14 +201,6 @@ func loop() {
196201
log.SetLevel(log.InfoLevel)
197202
log.SetOutput(os.Stdout)
198203

199-
// the important folders of the agent
200-
src, _ := os.Executable()
201-
srcPath := paths.New(src) // The path of the agent's binary
202-
srcDir := srcPath.Parent() // The directory of the agent's binary
203-
usr, _ := user.Current()
204-
usrDir := paths.New(usr.HomeDir) // The user folder, on linux/macos /home/<usr>/
205-
agentDir := usrDir.Join(".arduino-create")
206-
207204
// Instantiate Tools
208205
Tools = tools.Tools{
209206
Directory: agentDir.String(),

0 commit comments

Comments
 (0)