From 05fae6fae95d8ef6690f3d56863e3bb6a44d424c Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 1 Apr 2022 11:37:26 +0200 Subject: Parse Checksum fields via pkgTagSection::Key, too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We abstract hashes a fair bit to be able to add new ones eventually, which lead us to building the field names on the fly. We can do better through by keeping a central place for these names, too, which even helps in reducing code as we don't need the MD5 → Files dance anymore. --- apt-pkg/indexcopy.cc | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'apt-pkg/indexcopy.cc') diff --git a/apt-pkg/indexcopy.cc b/apt-pkg/indexcopy.cc index 82baba337..0d569265d 100644 --- a/apt-pkg/indexcopy.cc +++ b/apt-pkg/indexcopy.cc @@ -437,22 +437,14 @@ bool PackageCopy::RewriteEntry(FileFd &Target,string const &File) /* */ bool SourceCopy::GetFile(string &File,unsigned long long &Size) { - string Files; - - for (char const *const *type = HashString::SupportedHashes(); *type != NULL; ++type) + std::string Files; + for (auto hashinfo : HashString::SupportedHashesInfo()) { - // derive field from checksum type - std::string checksumField("Checksums-"); - if (strcmp(*type, "MD5Sum") == 0) - checksumField = "Files"; // historic name for MD5 checksums - else - checksumField.append(*type); - - Files = Section->FindS(checksumField); - if (Files.empty() == false) + Files = Section->Find(hashinfo.chksumskey).to_string(); + if (not Files.empty()) break; } - if (Files.empty() == true) + if (Files.empty()) return false; // Read the first file triplet -- cgit v1.2.3-70-g09d2