@@ -46,8 +46,8 @@ type Release struct {
4646// DownloadConfirmCB is a function that is called when a Debian image is ready to be downloaded.
4747type DownloadConfirmCB func (target string ) (bool ,error )
4848
49- func DownloadAndExtract (client * Client ,targetVersion string ,upgradeConfirmCb DownloadConfirmCB ,forceYes bool ) (* paths.Path ,string ,error ) {
50- tmpZip ,version ,err := DownloadImage (client ,targetVersion ,upgradeConfirmCb ,forceYes )
49+ func DownloadAndExtract (client * Client ,targetVersion string ,upgradeConfirmCb DownloadConfirmCB ,forceYes bool , tempDir string ) (* paths.Path ,string ,error ) {
50+ tmpZip ,version ,err := DownloadImage (client ,targetVersion ,upgradeConfirmCb ,forceYes , tempDir )
5151if err != nil {
5252return nil ,"" ,fmt .Errorf ("error downloading the image: %v" ,err )
5353}
@@ -69,7 +69,7 @@ func DownloadAndExtract(client *Client, targetVersion string, upgradeConfirmCb D
6969return imagePath ,version ,nil
7070}
7171
72- func DownloadImage (client * Client ,targetVersion string ,upgradeConfirmCb DownloadConfirmCB ,forceYes bool ) (* paths.Path ,string ,error ) {
72+ func DownloadImage (client * Client ,targetVersion string ,upgradeConfirmCb DownloadConfirmCB ,forceYes bool , tempDir string ) (* paths.Path ,string ,error ) {
7373var err error
7474
7575feedback .Print (i18n .Tr ("Checking for Debian image releases" ))
@@ -112,7 +112,7 @@ func DownloadImage(client *Client, targetVersion string, upgradeConfirmCb Downlo
112112defer download .Close ()
113113
114114// Download the zip
115- temp ,err := GetTempDir ("download-" )
115+ temp ,err := GetTempDir ("download-" , tempDir )
116116if err != nil {
117117return nil ,"" ,fmt .Errorf ("could not create temporary download directory: %w" ,err )
118118}
@@ -166,14 +166,18 @@ func ExtractImage(archive, temp *paths.Path) error {
166166
167167// GetTempDir returns a temporary directory inside the user's cache directory.
168168// The caller is responsible for removing the directory when no longer needed.
169- func GetTempDir (prefix string ) (* paths.Path ,error ) {
170- userCacheDir ,err := os .UserCacheDir ()
171- if err != nil {
172- return nil ,fmt .Errorf ("could not get user's cache directory: %w" ,err )
173- }
169+ func GetTempDir (prefix string ,tempDir string ) (* paths.Path ,error ) {
170+ cacheDir := paths .New (tempDir )
171+
172+ if cacheDir == nil {
173+ userCacheDir ,err := os .UserCacheDir ()
174+ if err != nil {
175+ return nil ,fmt .Errorf ("could not get user's cache directory: %w" ,err )
176+ }
174177
175- cacheDir := paths .New (userCacheDir ,"arduino-flasher-cli" )
176- _ = cacheDir .MkdirAll ()
178+ cacheDir = paths .New (userCacheDir ,"arduino-flasher-cli" )
179+ _ = cacheDir .MkdirAll ()
180+ }
177181
178182temp ,err := paths .MkTempDir (cacheDir .String (),prefix )
179183if err != nil {