From 9496ad3a7b16413025588a955500c2311c5db38a Mon Sep 17 00:00:00 2001 From: comp500 Date: Sun, 8 Oct 2023 14:53:07 +0100 Subject: [PATCH] Pass through warnings from UpdateIndex, don't fetch sha256 if we already have it --- core/download.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/core/download.go b/core/download.go index 066d956..a926089 100644 --- a/core/download.go +++ b/core/download.go @@ -122,6 +122,7 @@ func reuseExistingFile(cacheHandle *CacheIndexHandle, hashesToObtain []string, m file, err := cacheHandle.Open() if err == nil { remainingHashes := cacheHandle.GetRemainingHashes(hashesToObtain) + var warnings []error if len(remainingHashes) > 0 { err = teeHashes(remainingHashes, cacheHandle.Hashes, io.Discard, file) if err != nil { @@ -133,13 +134,14 @@ func reuseExistingFile(cacheHandle *CacheIndexHandle, hashesToObtain []string, m _ = file.Close() return CompletedDownload{}, fmt.Errorf("failed to seek file %s in cache: %w", cacheHandle.Path(), err) } - cacheHandle.UpdateIndex() + warnings = cacheHandle.UpdateIndex() } return CompletedDownload{ - File: file, - Mod: mod, - Hashes: cacheHandle.Hashes, + File: file, + Mod: mod, + Hashes: cacheHandle.Hashes, + Warnings: warnings, }, nil } else { return CompletedDownload{}, fmt.Errorf("failed to read file %s from cache: %w", cacheHandle.Path(), err) @@ -228,7 +230,10 @@ func getHashListsForDownload(hashesToObtain []string, validateHashFormat string, hashes := make(map[string]string) hashes[validateHashFormat] = validateHash - cl := []string{cacheHashFormat} + var cl []string + if cacheHashFormat != validateHashFormat { + cl = append(cl, cacheHashFormat) + } for _, v := range hashesToObtain { if v != validateHashFormat && v != cacheHashFormat { cl = append(cl, v)