diff options
author | Julian Andres Klode <julian.klode@canonical.com> | 2019-04-30 11:50:11 +0200 |
---|---|---|
committer | Julian Andres Klode <julian.klode@canonical.com> | 2019-04-30 17:42:14 +0200 |
commit | 4fa03143eee3776e2fa8fbd59d3cbaea40be0871 (patch) | |
tree | b5111308d3c356677ee8d72fbd5df93d4128acaa | |
parent | cccef6ca60c2775e918d964fdad1afc1dcad4d0e (diff) |
apt-helper: Support multiple hashes for a file
This just peels supported hashes of the command-line until
we reach a non-hash. For legacy compatability support, the
first hash may be an empty string.
-rw-r--r-- | cmdline/apt-helper.cc | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/cmdline/apt-helper.cc b/cmdline/apt-helper.cc index beac0efba..119cbc4c8 100644 --- a/cmdline/apt-helper.cc +++ b/cmdline/apt-helper.cc @@ -63,14 +63,36 @@ static bool DoDownloadFile(CommandLine &CmdL) /*{{{*/ { std::string download_uri = CmdL.FileList[fileind + 1]; std::string targetfile = CmdL.FileList[fileind + 2]; - std::string hash; - if (CmdL.FileSize() > fileind + 3) - hash = CmdL.FileList[fileind + 3]; + HashStringList hashes; + + fileind += 2; + + // An empty string counts as a hash for compatability reasons + if (CmdL.FileSize() > fileind + 1 && *CmdL.FileList[fileind + 1] == '\0') + fileind++; + + /* Let's start looking for hashes */ + for (auto i = fileind + 1; CmdL.FileSize() > i; i++) + { + bool isAHash = false; + + for (auto HashP = HashString::SupportedHashes(); *HashP != nullptr; HashP++) + { + if (APT::String::Startswith(CmdL.FileList[i], *HashP)) + isAHash = true; + } + + if (!isAHash) + break; + + hashes.push_back(HashString(CmdL.FileList[i])); + fileind++; + } + // we use download_uri as descr and targetfile as short-descr - new pkgAcqFile(&Fetcher, download_uri, hash, 0, download_uri, targetfile, - "dest-dir-ignored", targetfile); + new pkgAcqFile(&Fetcher, download_uri, hashes, 0, download_uri, targetfile, + "dest-dir-ignored", targetfile); targetfiles.push_back(targetfile); - fileind += 3; } bool Failed = false; |