Skip to content

Commit e7570e2

Browse files
Create client inside DownloadImage function
1 parent c307f49 commit e7570e2

File tree

3 files changed

+7
-16
lines changed

3 files changed

+7
-16
lines changed

download.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ func runDownloadCommand(ctx context.Context, args []string, destDir string) {
5252
feedback.Fatal(i18n.Tr("error: %s is not a directory. Please, select an existing directory.", destDir), feedback.ErrBadArgument)
5353
}
5454

55-
client := updater.NewClient()
56-
downloadPath, _, err := updater.DownloadImage(ctx, client, targetVersion, downloadPath)
55+
downloadPath, _, err := updater.DownloadImage(ctx, targetVersion, downloadPath)
5756
if err != nil {
5857
feedback.Fatal(i18n.Tr("error downloading the image: %v", err), feedback.ErrBadArgument)
5958
}

flash.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ func runFlashCommand(ctx context.Context, args []string, forceYes bool, tempDir
104104
}
105105

106106
if !imagePath.Exist() {
107-
client := updater.NewClient()
108-
109107
temp, err := updater.SetTempDir("download-", tempDir)
110108
if err != nil {
111109
feedback.Fatal(i18n.Tr("error creating a temporary directory to extract the archive: %v", err), feedback.ErrBadArgument)
@@ -121,14 +119,13 @@ func runFlashCommand(ctx context.Context, args []string, forceYes bool, tempDir
121119
feedback.Fatal(i18n.Tr("download and extraction requires up to %d GiB of free space", DownloadDiskSpace), feedback.ErrBadArgument)
122120
}
123121

124-
tempImagePath, v, err := updater.DownloadAndExtract(ctx, client, version, temp)
122+
feedback.Print(i18n.Tr("Checking for Debian image releases"))
123+
tempImagePath, v, err := updater.DownloadAndExtract(ctx, version, temp)
125124

126125
if err != nil {
127126
feedback.Fatal(i18n.Tr("could not download and extract the image: %v", err), feedback.ErrBadArgument)
128127
}
129128

130-
defer func() { _ = tempImagePath.Parent().RemoveAll() }()
131-
132129
version = v
133130
imagePath = tempImagePath
134131
} else if !imagePath.IsDir() {

updater/download_image.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,12 @@ type Release struct {
4646
// DownloadConfirmCB is a function that is called when a Debian image is ready to be downloaded.
4747
type DownloadConfirmCB func(target string) (bool, error)
4848

49-
func DownloadAndExtract(ctx context.Context, client *Client, targetVersion string, temp *paths.Path) (*paths.Path, string, error) {
50-
tmpZip, version, err := DownloadImage(ctx, client, targetVersion, temp)
49+
func DownloadAndExtract(ctx context.Context, targetVersion string, temp *paths.Path) (*paths.Path, string, error) {
50+
tmpZip, version, err := DownloadImage(ctx, targetVersion, temp)
5151
if err != nil {
5252
return nil, "", fmt.Errorf("error downloading the image: %v", err)
5353
}
5454

55-
// Download not confirmed
56-
if tmpZip == nil {
57-
return nil, "", nil
58-
}
59-
6055
err = ExtractImage(ctx, tmpZip, tmpZip.Parent())
6156
if err != nil {
6257
return nil, "", fmt.Errorf("error extracting the image: %v", err)
@@ -69,10 +64,10 @@ func DownloadAndExtract(ctx context.Context, client *Client, targetVersion strin
6964
return imagePath, version, nil
7065
}
7166

72-
func DownloadImage(ctx context.Context, client *Client, targetVersion string, downloadPath *paths.Path) (*paths.Path, string, error) {
67+
func DownloadImage(ctx context.Context, targetVersion string, downloadPath *paths.Path) (*paths.Path, string, error) {
7368
var err error
7469

75-
feedback.Print(i18n.Tr("Checking for Debian image releases"))
70+
client := NewClient()
7671
manifest, err := client.GetInfoManifest(ctx)
7772
if err != nil {
7873
return nil, "", err

0 commit comments

Comments
 (0)