Skip to content

Commit f10d5f8

Browse files
committed
crashreports are now created in .arduino-create/logs to preserve macos bundle integrity
1 parent ab56744 commit f10d5f8

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

main.go

+8-12
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"io/ioutil"
2525
"os"
2626
"os/user"
27-
"path/filepath"
2827
"runtime"
2928
"runtime/debug"
3029
"strconv"
@@ -239,9 +238,10 @@ func loop() {
239238

240239
// Instantiate Tools
241240
usr, _ := user.Current()
242-
directory := filepath.Join(usr.HomeDir, ".arduino-create")
241+
usrDir := paths.New(usr.HomeDir)
242+
agentDir := usrDir.Join(".arduino-create")
243243
Tools = tools.Tools{
244-
Directory: directory,
244+
Directory: agentDir.String(),
245245
IndexURL: *indexURL,
246246
Logger: func(msg string) {
247247
mapD := map[string]string{"DownloadStatus": "Pending", "Msg": msg}
@@ -331,16 +331,12 @@ func loop() {
331331
// save crashreport to file
332332
if *crashreport {
333333
logFilename := "crashreport_" + time.Now().Format("20060102150405") + ".log"
334-
currDir, err := os.Getwd()
335-
if err != nil {
336-
panic(err)
337-
}
338334
// 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()
342338
}
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)
344340
if err != nil {
345341
log.Print("Cannot create file used for crash-report")
346342
} else {
@@ -399,7 +395,7 @@ func loop() {
399395
r.POST("/update", updateHandler)
400396

401397
// Mount goa handlers
402-
goa := v2.Server(directory)
398+
goa := v2.Server(agentDir.String())
403399
r.Any("/v2/*path", gin.WrapH(goa))
404400

405401
go func() {

0 commit comments

Comments
 (0)