summaryrefslogtreecommitdiff
path: root/apt-pkg/deb
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2022-04-01 11:37:26 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2022-04-01 14:16:19 +0200
commit05fae6fae95d8ef6690f3d56863e3bb6a44d424c (patch)
treec948709ce9b2e4f4bc6e11138c3c21671d3baf37 /apt-pkg/deb
parent472376be6818b5ea43250abcbecfcab53b4a729a (diff)
Parse Checksum fields via pkgTagSection::Key, too
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.
Diffstat (limited to 'apt-pkg/deb')
-rw-r--r--apt-pkg/deb/debmetaindex.cc7
-rw-r--r--apt-pkg/deb/debsrcrecords.cc21
2 files changed, 10 insertions, 18 deletions
diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc
index 32f1fa8db..c6005f1c8 100644
--- a/apt-pkg/deb/debmetaindex.cc
+++ b/apt-pkg/deb/debmetaindex.cc
@@ -515,10 +515,9 @@ bool debReleaseIndex::Load(std::string const &Filename, std::string * const Erro
bool FoundHashSum = false;
bool FoundStrongHashSum = false;
- auto const SupportedHashes = HashString::SupportedHashes();
- for (int i=0; SupportedHashes[i] != NULL; i++)
+ for (auto const hashinfo : HashString::SupportedHashesInfo())
{
- if (!Section.Find(SupportedHashes[i], Start, End))
+ if (not Section.Find(hashinfo.namekey, Start, End))
continue;
std::string Name;
@@ -529,7 +528,7 @@ bool debReleaseIndex::Load(std::string const &Filename, std::string * const Erro
if (!parseSumData(Start, End, Name, Hash, Size))
return false;
- HashString const hs(SupportedHashes[i], Hash);
+ HashString const hs(hashinfo.name.to_string(), Hash);
if (Entries.find(Name) == Entries.end())
{
metaIndex::checkSum *Sum = new metaIndex::checkSum;
diff --git a/apt-pkg/deb/debsrcrecords.cc b/apt-pkg/deb/debsrcrecords.cc
index 1fd0fdc12..311bacfdd 100644
--- a/apt-pkg/deb/debsrcrecords.cc
+++ b/apt-pkg/deb/debsrcrecords.cc
@@ -172,26 +172,19 @@ bool debSrcRecordParser::Files(std::vector<pkgSrcRecords::File> &List)
std::vector<std::string> const compExts = APT::Configuration::getCompressorExtensions();
auto const &posix = std::locale::classic();
- for (char const * const * type = HashString::SupportedHashes(); *type != NULL; ++type)
+ for (auto const 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);
-
- string const Files = Sect.FindS(checksumField.c_str());
+ auto const Files = Sect.Find(hashinfo.chksumskey);
if (Files.empty() == true)
continue;
- std::istringstream ss(Files);
+ std::istringstream ss(Files.to_string());
ss.imbue(posix);
while (ss.good())
{
std::string hash, path;
unsigned long long size;
- if (iIndex == nullptr && checksumField == "Files")
+ if (iIndex == nullptr && hashinfo.chksumskey == pkgTagSection::Key::Files)
{
std::string ignore;
ss >> hash >> size >> ignore >> ignore >> path;
@@ -200,9 +193,9 @@ bool debSrcRecordParser::Files(std::vector<pkgSrcRecords::File> &List)
ss >> hash >> size >> path;
if (ss.fail() || hash.empty() || path.empty())
- return _error->Error("Error parsing file record in %s of source package %s", checksumField.c_str(), Package().c_str());
+ return _error->Error("Error parsing file record in %s of source package %s", hashinfo.chksumsname.to_string().c_str(), Package().c_str());
- HashString const hashString(*type, hash);
+ HashString const hashString(hashinfo.name.to_string(), hash);
if (Base.empty() == false)
path = Base + path;
@@ -217,7 +210,7 @@ bool debSrcRecordParser::Files(std::vector<pkgSrcRecords::File> &List)
{
// an error here indicates that we have two different hashes for the same file
if (file->Hashes.push_back(hashString) == false)
- return _error->Error("Error parsing checksum in %s of source package %s", checksumField.c_str(), Package().c_str());
+ return _error->Error("Error parsing checksum in %s of source package %s", hashinfo.chksumsname.to_string().c_str(), Package().c_str());
continue;
}