Skip to content

Commit

Permalink
properly clean-up temp files. /tmp/fwuploader was removed in the wr…
Browse files Browse the repository at this point in the history
…ong place
  • Loading branch information
umbynos committed Jun 14, 2023
1 parent 858912a commit 2631352
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions cli/certificates/flash.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/arduino/arduino-fwuploader/cli/arguments"
"github.com/arduino/arduino-fwuploader/cli/common"
"github.com/arduino/arduino-fwuploader/cli/feedback"
"github.com/arduino/arduino-fwuploader/cli/globals"
"github.com/arduino/arduino-fwuploader/flasher"
"github.com/arduino/arduino-fwuploader/indexes/download"
"github.com/arduino/go-paths-helper"
Expand Down Expand Up @@ -61,6 +62,8 @@ func NewFlashCommand() *cobra.Command {
}

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

packageIndex, firmwareIndex := common.InitIndexes()
common.CheckFlags(commonFlags.Fqbn, commonFlags.Address)
Expand Down
3 changes: 3 additions & 0 deletions cli/firmware/flash.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/arduino/arduino-fwuploader/cli/arguments"
"github.com/arduino/arduino-fwuploader/cli/common"
"github.com/arduino/arduino-fwuploader/cli/feedback"
"github.com/arduino/arduino-fwuploader/cli/globals"
"github.com/arduino/arduino-fwuploader/flasher"
"github.com/arduino/arduino-fwuploader/indexes/download"
"github.com/arduino/arduino-fwuploader/indexes/firmwareindex"
Expand Down Expand Up @@ -65,6 +66,8 @@ func NewFlashCommand() *cobra.Command {
}

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

packageIndex, firmwareIndex := common.InitIndexes()
common.CheckFlags(commonFlags.Fqbn, commonFlags.Address)
Expand Down
3 changes: 3 additions & 0 deletions cli/firmware/getversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"github.com/arduino/arduino-fwuploader/cli/common"
"github.com/arduino/arduino-fwuploader/cli/feedback"
"github.com/arduino/arduino-fwuploader/cli/globals"
"github.com/arduino/arduino-fwuploader/flasher"
"github.com/arduino/arduino-fwuploader/indexes/download"
"github.com/arduino/arduino-fwuploader/indexes/firmwareindex"
Expand All @@ -53,6 +54,8 @@ func NewGetVersionCommand() *cobra.Command {
}

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

packageIndex, firmwareIndex := common.InitIndexes()
common.CheckFlags(commonFlags.Fqbn, commonFlags.Address)
Expand Down
1 change: 1 addition & 0 deletions indexes/download/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func DownloadTool(toolRelease *cores.ToolRelease) (*paths.Path, error) {
logrus.Error(err)
return nil, err
}
defer downloadsDir.RemoveAll()
d, err := downloader.Download(archivePath.String(), resource.URL, downloader.NoResume)
if err != nil {
logrus.Error(err)
Expand Down
1 change: 0 additions & 1 deletion indexes/indexes.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ func GetPackageIndex() (*packageindex.Index, error) {

// GetFirmwareIndex downloads and loads the arduino-fwuploader module_firmware_index.json
func GetFirmwareIndex() (*firmwareindex.Index, error) {
defer globals.FwUploaderPath.RemoveAll()
indexPath, err := download.DownloadIndex(globals.ModuleFirmwareIndexGZURL)
if err != nil {
logrus.Error(err)
Expand Down
2 changes: 0 additions & 2 deletions indexes/indexes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"testing"

"github.com/arduino/arduino-cli/arduino/cores/packageindex"
"github.com/arduino/arduino-fwuploader/cli/globals"
"github.com/arduino/go-paths-helper"
"github.com/stretchr/testify/require"
)
Expand All @@ -48,5 +47,4 @@ func TestGetFirmwareIndex(t *testing.T) {
index, err := GetFirmwareIndex()
require.NoError(t, err)
require.NotNil(t, index)
require.NoDirExists(t, globals.FwUploaderPath.String())
}

0 comments on commit 2631352

Please sign in to comment.