Skip to content

Commit 2631352

Browse files
committed
properly clean-up temp files. /tmp/fwuploader was removed in the wrong place
1 parent 858912a commit 2631352

File tree

6 files changed

+10
-3
lines changed

6 files changed

+10
-3
lines changed

Diff for: cli/certificates/flash.go

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/arduino/arduino-fwuploader/cli/arguments"
2929
"github.com/arduino/arduino-fwuploader/cli/common"
3030
"github.com/arduino/arduino-fwuploader/cli/feedback"
31+
"github.com/arduino/arduino-fwuploader/cli/globals"
3132
"github.com/arduino/arduino-fwuploader/flasher"
3233
"github.com/arduino/arduino-fwuploader/indexes/download"
3334
"github.com/arduino/go-paths-helper"
@@ -61,6 +62,8 @@ func NewFlashCommand() *cobra.Command {
6162
}
6263

6364
func runFlash(cmd *cobra.Command, args []string) {
65+
// at the end cleanup the fwuploader temp dir
66+
defer globals.FwUploaderPath.RemoveAll()
6467

6568
packageIndex, firmwareIndex := common.InitIndexes()
6669
common.CheckFlags(commonFlags.Fqbn, commonFlags.Address)

Diff for: cli/firmware/flash.go

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/arduino/arduino-fwuploader/cli/arguments"
2929
"github.com/arduino/arduino-fwuploader/cli/common"
3030
"github.com/arduino/arduino-fwuploader/cli/feedback"
31+
"github.com/arduino/arduino-fwuploader/cli/globals"
3132
"github.com/arduino/arduino-fwuploader/flasher"
3233
"github.com/arduino/arduino-fwuploader/indexes/download"
3334
"github.com/arduino/arduino-fwuploader/indexes/firmwareindex"
@@ -65,6 +66,8 @@ func NewFlashCommand() *cobra.Command {
6566
}
6667

6768
func runFlash(cmd *cobra.Command, args []string) {
69+
// at the end cleanup the fwuploader temp dir
70+
defer globals.FwUploaderPath.RemoveAll()
6871

6972
packageIndex, firmwareIndex := common.InitIndexes()
7073
common.CheckFlags(commonFlags.Fqbn, commonFlags.Address)

Diff for: cli/firmware/getversion.go

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727

2828
"github.com/arduino/arduino-fwuploader/cli/common"
2929
"github.com/arduino/arduino-fwuploader/cli/feedback"
30+
"github.com/arduino/arduino-fwuploader/cli/globals"
3031
"github.com/arduino/arduino-fwuploader/flasher"
3132
"github.com/arduino/arduino-fwuploader/indexes/download"
3233
"github.com/arduino/arduino-fwuploader/indexes/firmwareindex"
@@ -53,6 +54,8 @@ func NewGetVersionCommand() *cobra.Command {
5354
}
5455

5556
func runGetVersion(cmd *cobra.Command, args []string) {
57+
// at the end cleanup the fwuploader temp dir
58+
defer globals.FwUploaderPath.RemoveAll()
5659

5760
packageIndex, firmwareIndex := common.InitIndexes()
5861
common.CheckFlags(commonFlags.Fqbn, commonFlags.Address)

Diff for: indexes/download/download.go

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func DownloadTool(toolRelease *cores.ToolRelease) (*paths.Path, error) {
5959
logrus.Error(err)
6060
return nil, err
6161
}
62+
defer downloadsDir.RemoveAll()
6263
d, err := downloader.Download(archivePath.String(), resource.URL, downloader.NoResume)
6364
if err != nil {
6465
logrus.Error(err)

Diff for: indexes/indexes.go

-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ func GetPackageIndex() (*packageindex.Index, error) {
8989

9090
// GetFirmwareIndex downloads and loads the arduino-fwuploader module_firmware_index.json
9191
func GetFirmwareIndex() (*firmwareindex.Index, error) {
92-
defer globals.FwUploaderPath.RemoveAll()
9392
indexPath, err := download.DownloadIndex(globals.ModuleFirmwareIndexGZURL)
9493
if err != nil {
9594
logrus.Error(err)

Diff for: indexes/indexes_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"testing"
2323

2424
"github.com/arduino/arduino-cli/arduino/cores/packageindex"
25-
"github.com/arduino/arduino-fwuploader/cli/globals"
2625
"github.com/arduino/go-paths-helper"
2726
"github.com/stretchr/testify/require"
2827
)
@@ -48,5 +47,4 @@ func TestGetFirmwareIndex(t *testing.T) {
4847
index, err := GetFirmwareIndex()
4948
require.NoError(t, err)
5049
require.NotNil(t, index)
51-
require.NoDirExists(t, globals.FwUploaderPath.String())
5250
}

0 commit comments

Comments
 (0)