@@ -27,15 +27,11 @@ import (
2727 "github.com/arduino/go-paths-helper"
2828 "github.com/codeclysm/extract/v4"
2929 "github.com/schollz/progressbar/v3"
30- "github.com/shirou/gopsutil/v4/disk"
3130
3231 "github.com/arduino/arduino-flasher-cli/feedback"
3332 "github.com/arduino/arduino-flasher-cli/i18n"
3433)
3534
36- const GiB = uint64 (1024 * 1024 * 1024 )
37- const NeededDiskSpace = uint64 (15 )
38-
3935type Manifest struct {
4036 Latest Release `json:"latest"`
4137 Releases []Release `json:"releases"`
@@ -50,8 +46,8 @@ type Release struct {
5046// DownloadConfirmCB is a function that is called when a Debian image is ready to be downloaded.
5147type DownloadConfirmCB func (target string ) (bool , error )
5248
53- func DownloadAndExtract (client * Client , targetVersion string , upgradeConfirmCb DownloadConfirmCB , forceYes bool , tempDir string ) (* paths.Path , string , error ) {
54- tmpZip , version , err := DownloadImage (client , targetVersion , upgradeConfirmCb , forceYes , tempDir , nil )
49+ func DownloadAndExtract (client * Client , targetVersion string , upgradeConfirmCb DownloadConfirmCB , forceYes bool , temp * paths. Path ) (* paths.Path , string , error ) {
50+ tmpZip , version , err := DownloadImage (client , targetVersion , upgradeConfirmCb , forceYes , temp )
5551 if err != nil {
5652 return nil , "" , fmt .Errorf ("error downloading the image: %v" , err )
5753 }
@@ -73,7 +69,7 @@ func DownloadAndExtract(client *Client, targetVersion string, upgradeConfirmCb D
7369 return imagePath , version , nil
7470}
7571
76- func DownloadImage (client * Client , targetVersion string , upgradeConfirmCb DownloadConfirmCB , forceYes bool , tempDir string , downloadPath * paths.Path ) (* paths.Path , string , error ) {
72+ func DownloadImage (client * Client , targetVersion string , upgradeConfirmCb DownloadConfirmCB , forceYes bool , downloadPath * paths.Path ) (* paths.Path , string , error ) {
7773 var err error
7874
7975 feedback .Print (i18n .Tr ("Checking for Debian image releases" ))
@@ -115,14 +111,6 @@ func DownloadImage(client *Client, targetVersion string, upgradeConfirmCb Downlo
115111 }
116112 defer download .Close ()
117113
118- // Download the zip
119- if downloadPath == nil {
120- downloadPath , err = SetTempDir ("download-" , tempDir )
121- if err != nil {
122- return nil , "" , fmt .Errorf ("could not create temporary download directory: %w" , err )
123- }
124- }
125-
126114 tmpZip := downloadPath .Join ("arduino-unoq-debian-image-" + rel .Version + ".tar.zst" )
127115 tmpZipFile , err := tmpZip .Create ()
128116 if err != nil {
@@ -191,14 +179,5 @@ func SetTempDir(prefix string, tempDir string) (*paths.Path, error) {
191179 return nil , fmt .Errorf ("could not create .cache directory: %w" , err )
192180 }
193181
194- // Check if there is enough free disk space before downloading/extracting an image
195- d , err := disk .Usage (temp .String ())
196- if err != nil {
197- return nil , err
198- }
199- if d .Free / GiB < NeededDiskSpace {
200- return nil , fmt .Errorf ("aborting: download and extraction requires up to %d GiB of free space" , NeededDiskSpace )
201- }
202-
203182 return temp , nil
204183}
0 commit comments