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