Skip to content

Commit e939816

Browse files
Remove callback function and download archives automatically
1 parent 9790b3e commit e939816

File tree

3 files changed

+5
-27
lines changed

3 files changed

+5
-27
lines changed

download.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func runDownloadCommand(ctx context.Context, args []string, destDir string) {
5353
}
5454

5555
client := updater.NewClient()
56-
downloadPath, _, err := updater.DownloadImage(ctx, client, targetVersion, nil, true, downloadPath)
56+
downloadPath, _, err := updater.DownloadImage(ctx, client, targetVersion, downloadPath)
5757
if err != nil {
5858
feedback.Fatal(i18n.Tr("error downloading the image: %v", err), feedback.ErrBadArgument)
5959
}

updater/download_image.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ 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, upgradeConfirmCb DownloadConfirmCB, forceYes bool, temp *paths.Path) (*paths.Path, string, error) {
50-
tmpZip, version, err := DownloadImage(ctx, client, targetVersion, upgradeConfirmCb, forceYes, temp)
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)
5151
if err != nil {
5252
return nil, "", fmt.Errorf("error downloading the image: %v", err)
5353
}
@@ -69,7 +69,7 @@ func DownloadAndExtract(ctx context.Context, client *Client, targetVersion strin
6969
return imagePath, version, nil
7070
}
7171

72-
func DownloadImage(ctx context.Context, client *Client, targetVersion string, upgradeConfirmCb DownloadConfirmCB, forceYes bool, downloadPath *paths.Path) (*paths.Path, string, error) {
72+
func DownloadImage(ctx context.Context, client *Client, targetVersion string, downloadPath *paths.Path) (*paths.Path, string, error) {
7373
var err error
7474

7575
feedback.Print(i18n.Tr("Checking for Debian image releases"))
@@ -94,17 +94,6 @@ func DownloadImage(ctx context.Context, client *Client, targetVersion string, up
9494
return nil, "", fmt.Errorf("could not find Debian image %s", targetVersion)
9595
}
9696

97-
if !forceYes {
98-
res, err := upgradeConfirmCb(rel.Version)
99-
if err != nil {
100-
return nil, "", err
101-
}
102-
if !res {
103-
feedback.Print(i18n.Tr("Download not confirmed by user, exiting"))
104-
return nil, "", nil
105-
}
106-
}
107-
10897
download, size, err := client.FetchZip(ctx, rel.Url)
10998
if err != nil {
11099
return nil, "", fmt.Errorf("could not fetch Debian image: %w", err)

updater/flasher.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,7 @@ func Flash(ctx context.Context, imagePath *paths.Path, version string, forceYes
5252
return fmt.Errorf("download and extraction requires up to %d GiB of free space", DownloadDiskSpace)
5353
}
5454

55-
tempImagePath, v, err := DownloadAndExtract(ctx, client, version, func(target string) (bool, error) {
56-
feedback.Printf("Found Debian image version: %s", target)
57-
feedback.Printf("Do you want to download it? (yes/no)")
58-
59-
var yesInput string
60-
_, err := fmt.Scanf("%s\n", &yesInput)
61-
if err != nil {
62-
return false, err
63-
}
64-
yes := strings.ToLower(yesInput) == "yes" || strings.ToLower(yesInput) == "y"
65-
return yes, nil
66-
}, forceYes, temp)
55+
tempImagePath, v, err := DownloadAndExtract(ctx, client, version, temp)
6756

6857
if err != nil {
6958
return fmt.Errorf("could not download and extract the image: %v", err)

0 commit comments

Comments
 (0)