Skip to content

Commit ce7ed4e

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

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"
@@ -240,9 +239,10 @@ func loop() {
240239

241240
// Instantiate Tools
242241
usr, _ := user.Current()
243-
directory := filepath.Join(usr.HomeDir, ".arduino-create")
242+
usrDir := paths.New(usr.HomeDir)
243+
agentDir := usrDir.Join(".arduino-create")
244244
Tools = tools.Tools{
245-
Directory: directory,
245+
Directory: agentDir.String(),
246246
IndexURL: *indexURL,
247247
Logger: func(msg string) {
248248
mapD := map[string]string{"DownloadStatus": "Pending", "Msg": msg}
@@ -332,16 +332,12 @@ func loop() {
332332
// save crashreport to file
333333
if *crashreport {
334334
logFilename := "crashreport_" + time.Now().Format("20060102150405") + ".log"
335-
currDir, err := osext.ExecutableFolder()
336-
if err != nil {
337-
panic(err)
338-
}
339335
// 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()
343339
}
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)
345341
if err != nil {
346342
log.Print("Cannot create file used for crash-report")
347343
} else {
@@ -400,7 +396,7 @@ func loop() {
400396
r.POST("/update", updateHandler)
401397

402398
// Mount goa handlers
403-
goa := v2.Server(directory)
399+
goa := v2.Server(agentDir.String())
404400
r.Any("/v2/*path", gin.WrapH(goa))
405401

406402
go func() {

0 commit comments

Comments
 (0)