From 966d9fcb4cd8db82b4fbbc65b791221418c9042e Mon Sep 17 00:00:00 2001 From: Matteo Pologruto Date: Mon, 9 Jan 2023 16:30:10 +0100 Subject: [PATCH 1/2] Clean up temporary files on exit Temporary files and directories created when the index is downloaded are now correctly cleaned up on exit. --- indexes/download/download.go | 2 +- indexes/indexes.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/indexes/download/download.go b/indexes/download/download.go index 707b6889..3c648c0a 100644 --- a/indexes/download/download.go +++ b/indexes/download/download.go @@ -229,7 +229,7 @@ func DownloadIndex(indexURL string) (*paths.Path, error) { if err != nil { return nil, err } - defer tempDir.Remove() + defer tempDir.RemoveAll() // Download index tmpGZIndex := tempDir.Join("index.gz") diff --git a/indexes/indexes.go b/indexes/indexes.go index 63bda944..106eb109 100644 --- a/indexes/indexes.go +++ b/indexes/indexes.go @@ -89,6 +89,7 @@ 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) From b3306eb36a074972e7c899ed5226053694564b7a Mon Sep 17 00:00:00 2001 From: Matteo Pologruto Date: Mon, 9 Jan 2023 16:37:38 +0100 Subject: [PATCH 2/2] Add test to check if `fwuploader` dir is correctly removed on exit --- indexes/indexes_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/indexes/indexes_test.go b/indexes/indexes_test.go index df0f3f33..440ea553 100644 --- a/indexes/indexes_test.go +++ b/indexes/indexes_test.go @@ -22,6 +22,7 @@ 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" ) @@ -47,4 +48,5 @@ func TestGetFirmwareIndex(t *testing.T) { index, err := GetFirmwareIndex() require.NoError(t, err) require.NotNil(t, index) + require.NoDirExists(t, globals.FwUploaderPath.String()) }