Use longest suffix match to pick up checksum

This commit is contained in:
Andrey Smirnov
2017-05-22 23:28:13 +03:00
parent c026106352
commit f0360cf2d3
2 changed files with 31 additions and 4 deletions
+10 -4
View File
@@ -47,15 +47,21 @@ func DownloadTryCompression(downloader aptly.Downloader, url string, expectedChe
tryURL := url + method.extenstion
foundChecksum := false
for suffix, expected := range expectedChecksums {
bestSuffix := ""
for suffix := range expectedChecksums {
if strings.HasSuffix(tryURL, suffix) {
file, err = DownloadTempWithChecksum(downloader, tryURL, &expected, ignoreMismatch, maxTries)
foundChecksum = true
break
if len(suffix) > len(bestSuffix) {
bestSuffix = suffix
}
}
}
if !foundChecksum {
if foundChecksum {
expected := expectedChecksums[bestSuffix]
file, err = DownloadTempWithChecksum(downloader, tryURL, &expected, ignoreMismatch, maxTries)
} else {
if !ignoreMismatch {
continue
}