From b339dab29f6e9bc061edf56662f7c3467374d695 Mon Sep 17 00:00:00 2001 From: HikariKnight <2557889+HikariKnight@users.noreply.github.com> Date: Sat, 8 Apr 2023 18:00:19 +0200 Subject: [PATCH] fix the downloader not overwriting the old archive --- internal/ls_iommu_downloader/ls_iommu_downloader.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/internal/ls_iommu_downloader/ls_iommu_downloader.go b/internal/ls_iommu_downloader/ls_iommu_downloader.go index 61810b1..0ed0042 100644 --- a/internal/ls_iommu_downloader/ls_iommu_downloader.go +++ b/internal/ls_iommu_downloader/ls_iommu_downloader.go @@ -175,14 +175,21 @@ func downloadNewVersion(path, fileName, downloadUrl string) { grabClient := grab.NewClient() req, _ := grab.NewRequest(fileName, downloadUrl) + // Remove old archive + os.Remove(fileName) + // Download ls-iommu download := grabClient.Do(req) // check for errors if err := download.Err(); err != nil { fmt.Fprintf(os.Stderr, "Download failed: %v\n", err) - os.Exit(1) + if _, err := os.Stat("utils/ls-iommu"); errors.Is(err, os.ErrNotExist) { + log.Fatal("If the above error is 404, then we could not communicate with the GitHub API\n Please manually download and extract ls-iommu to: utils/\nYou can download it from: https://github.com/HikariKnight/ls-iommu/releases") + } else { + fmt.Println("Existing ls-iommu binary detected in \"utils/\", will use that instead as the GitHub API did not respond.") + } + } else { + fmt.Printf("Download saved to ./%v \n", download.Filename) } - - fmt.Printf("Download saved to ./%v \n", download.Filename) }