From 95c4f3142ab110ee74f276de1c960417808008ee Mon Sep 17 00:00:00 2001 From: lucarin91 Date: Wed, 15 Oct 2025 16:10:05 +0200 Subject: [PATCH 1/2] fix: download stuff into cached dir --- updater/download_image.go | 19 ++++++++++++++++++- updater/flasher.go | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/updater/download_image.go b/updater/download_image.go index b5a3170..0355ae6 100644 --- a/updater/download_image.go +++ b/updater/download_image.go @@ -22,6 +22,7 @@ import ( "encoding/hex" "fmt" "io" + "os" "github.com/arduino/go-paths-helper" "github.com/codeclysm/extract/v4" @@ -108,7 +109,7 @@ func DownloadImage(client *Client, targetVersion string, upgradeConfirmCb Downlo defer download.Close() // Download the zip - temp, err := paths.MkTempDir("", "flasher-updater-") + temp, err := GetTempDir("download-") if err != nil { return nil, "", fmt.Errorf("could not create temporary download directory: %w", err) } @@ -159,3 +160,19 @@ func ExtractImage(archive, temp *paths.Path) error { } return nil } + +// GetTempDir returns a temporary directory inside the user's cache directory. +// The caller is responsible for removing the directory when no longer needed. +func GetTempDir(prefix string) (*paths.Path, error) { + cacheDir, err := os.UserCacheDir() + if err != nil { + return nil, fmt.Errorf("could not get user's cache directory: %w", err) + } + + _ = paths.New(cacheDir, "arduino-flasher-cli").MkdirAll() + temp, err := paths.MkTempDir(cacheDir, prefix) + if err != nil { + return nil, fmt.Errorf("could not create .cache directory: %w", err) + } + return temp, nil +} diff --git a/updater/flasher.go b/updater/flasher.go index 98284e9..f8edac2 100644 --- a/updater/flasher.go +++ b/updater/flasher.go @@ -58,7 +58,7 @@ func Flash(ctx context.Context, imagePath *paths.Path, version string, forceYes imagePath = tempImagePath } else if !imagePath.IsDir() { - temp, err := paths.MkTempDir("", "debian-image-") + temp, err := GetTempDir("extract-") if err != nil { return fmt.Errorf("error creating a temporary directory to extract the archive: %v", err) } From 649d526216aa8cb7f70b8328b5e74f571069d5b2 Mon Sep 17 00:00:00 2001 From: lucarin91 Date: Wed, 15 Oct 2025 16:17:21 +0200 Subject: [PATCH 2/2] fixup! fix: download stuff into cached dir --- updater/download_image.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/updater/download_image.go b/updater/download_image.go index 0355ae6..8c8b603 100644 --- a/updater/download_image.go +++ b/updater/download_image.go @@ -164,13 +164,15 @@ func ExtractImage(archive, temp *paths.Path) error { // GetTempDir returns a temporary directory inside the user's cache directory. // The caller is responsible for removing the directory when no longer needed. func GetTempDir(prefix string) (*paths.Path, error) { - cacheDir, err := os.UserCacheDir() + userCacheDir, err := os.UserCacheDir() if err != nil { return nil, fmt.Errorf("could not get user's cache directory: %w", err) } - _ = paths.New(cacheDir, "arduino-flasher-cli").MkdirAll() - temp, err := paths.MkTempDir(cacheDir, prefix) + cacheDir := paths.New(userCacheDir, "arduino-flasher-cli") + _ = cacheDir.MkdirAll() + + temp, err := paths.MkTempDir(cacheDir.String(), prefix) if err != nil { return nil, fmt.Errorf("could not create .cache directory: %w", err) }