Skip to content

Commit 377e91b

Browse files
Create client inside DownloadImage function
1 parent e939816 commit 377e91b

File tree

3 files changed

+6
-21
lines changed

3 files changed

+6
-21
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
}

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

updater/flasher.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ const ExtractDiskSpace = uint64(10)
3535

3636
func Flash(ctx context.Context, imagePath *paths.Path, version string, forceYes bool, tempDir string) error {
3737
if !imagePath.Exist() {
38-
client := NewClient()
39-
4038
temp, err := SetTempDir("download-", tempDir)
4139
if err != nil {
4240
return fmt.Errorf("error creating a temporary directory to extract the archive: %v", err)
@@ -52,19 +50,12 @@ func Flash(ctx context.Context, imagePath *paths.Path, version string, forceYes
5250
return fmt.Errorf("download and extraction requires up to %d GiB of free space", DownloadDiskSpace)
5351
}
5452

55-
tempImagePath, v, err := DownloadAndExtract(ctx, client, version, temp)
53+
tempImagePath, v, err := DownloadAndExtract(ctx, version, temp)
5654

5755
if err != nil {
5856
return fmt.Errorf("could not download and extract the image: %v", err)
5957
}
6058

61-
// Download not confirmed
62-
if tempImagePath == nil {
63-
return nil
64-
}
65-
66-
defer func() { _ = tempImagePath.Parent().RemoveAll() }()
67-
6859
version = v
6960
imagePath = tempImagePath
7061
} else if !imagePath.IsDir() {

0 commit comments

Comments
 (0)