From 463848eaa023206d81ba0330f47785c4448060fc Mon Sep 17 00:00:00 2001 From: Draylar Date: Mon, 19 Oct 2020 17:20:07 -0500 Subject: [PATCH] Print error when a file hash only matches when uppercase --- core/mod.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/mod.go b/core/mod.go index 16b1384..d955bc5 100644 --- a/core/mod.go +++ b/core/mod.go @@ -148,8 +148,14 @@ func (m Mod) DownloadFile(dest io.Writer) error { } calculatedHash := hex.EncodeToString(h.Sum(nil)) - if calculatedHash != m.Download.Hash && strings.ToUpper(calculatedHash) != m.Download.Hash { + + // Check if the hash of the downloaded file matches the expected hash. + // Also check if the uppercase version of the expected hash matches. + if(strings.ToUpper(calculatedHash) != m.Download.Hash) { + return errors.New(fmt.Sprintf("Hash of saved file %s only matches when uppercased. Consider changing this to prevent future issues.", m.GetFilePath())) + } else if calculatedHash != m.Download.Hash { return errors.New(fmt.Sprintf("hash of saved file is invalid!\n .toml hash: %s\n download hash: %s", calculatedHash, m.Download.Hash)) } + return nil }