@@ -24,7 +24,6 @@ import (
24
24
"io/ioutil"
25
25
"os"
26
26
"os/user"
27
- "path/filepath"
28
27
"runtime"
29
28
"runtime/debug"
30
29
"strconv"
@@ -240,9 +239,10 @@ func loop() {
240
239
241
240
// Instantiate Tools
242
241
usr , _ := user .Current ()
243
- directory := filepath .Join (usr .HomeDir , ".arduino-create" )
242
+ usrDir := paths .New (usr .HomeDir )
243
+ agentDir := usrDir .Join (".arduino-create" )
244
244
Tools = tools.Tools {
245
- Directory : directory ,
245
+ Directory : agentDir . String () ,
246
246
IndexURL : * indexURL ,
247
247
Logger : func (msg string ) {
248
248
mapD := map [string ]string {"DownloadStatus" : "Pending" , "Msg" : msg }
@@ -332,16 +332,12 @@ func loop() {
332
332
// save crashreport to file
333
333
if * crashreport {
334
334
logFilename := "crashreport_" + time .Now ().Format ("20060102150405" ) + ".log"
335
- currDir , err := osext .ExecutableFolder ()
336
- if err != nil {
337
- panic (err )
338
- }
339
335
// handle logs directory creation
340
- logsDir := filepath .Join (currDir , "logs" )
341
- if _ , err := os . Stat ( logsDir ); os . IsNotExist ( err ) {
342
- os .Mkdir (logsDir , 0700 )
336
+ logsDir := agentDir .Join ("logs" )
337
+ if logsDir . NotExist ( ) {
338
+ logsDir .Mkdir ()
343
339
}
344
- logFile , err := os .OpenFile (filepath .Join (logsDir , logFilename ), os .O_WRONLY | os .O_CREATE | os .O_SYNC | os .O_APPEND , 0644 )
340
+ logFile , err := os .OpenFile (logsDir .Join (logFilename ). String ( ), os .O_WRONLY | os .O_CREATE | os .O_SYNC | os .O_APPEND , 0644 )
345
341
if err != nil {
346
342
log .Print ("Cannot create file used for crash-report" )
347
343
} else {
@@ -400,7 +396,7 @@ func loop() {
400
396
r .POST ("/update" , updateHandler )
401
397
402
398
// Mount goa handlers
403
- goa := v2 .Server (directory )
399
+ goa := v2 .Server (agentDir . String () )
404
400
r .Any ("/v2/*path" , gin .WrapH (goa ))
405
401
406
402
go func () {
0 commit comments