summaryrefslogtreecommitdiff
path: root/apt-pkg/deb
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2022-05-06 16:20:52 +0000
committerJulian Andres Klode <jak@debian.org>2022-05-06 16:20:52 +0000
commit97f16727b50dcaa4810e80d3c16639e0ce6a0958 (patch)
tree1228c44118015b13b2f94177571c6780eb861a7e /apt-pkg/deb
parent6778e2d672d84c962a578f6de415c666b9cf6ee1 (diff)
parent05fae6fae95d8ef6690f3d56863e3bb6a44d424c (diff)
Merge branch 'fix/tagfilekeys' into 'main'
Consistently dealing with fields via pkgTagSection::Key See merge request apt-team/apt!233
Diffstat (limited to 'apt-pkg/deb')
-rw-r--r--apt-pkg/deb/deblistparser.cc26
-rw-r--r--apt-pkg/deb/debmetaindex.cc7
-rw-r--r--apt-pkg/deb/debrecords.cc31
-rw-r--r--apt-pkg/deb/debsrcrecords.cc21
-rw-r--r--apt-pkg/deb/debsrcrecords.h7
5 files changed, 41 insertions, 51 deletions
diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc
index 2f0ebaa7b..6f47053a5 100644
--- a/apt-pkg/deb/deblistparser.cc
+++ b/apt-pkg/deb/deblistparser.cc
@@ -126,7 +126,7 @@ unsigned char debListParser::ParseMultiArch(bool const showErrors) /*{{{*/
{
if (showErrors == true)
_error->Warning("Architecture: all package '%s' can't be Multi-Arch: same",
- Section.FindS("Package").c_str());
+ Package().c_str());
MA = pkgCache::Version::No;
}
else
@@ -140,7 +140,7 @@ unsigned char debListParser::ParseMultiArch(bool const showErrors) /*{{{*/
{
if (showErrors == true)
_error->Warning("Unknown Multi-Arch type '%s' for package '%s'",
- MultiArch.to_string().c_str(), Section.FindS("Package").c_str());
+ MultiArch.to_string().c_str(), Package().c_str());
MA = pkgCache::Version::No;
}
@@ -241,10 +241,7 @@ bool debListParser::NewVersion(pkgCache::VerIterator &Ver)
return false;
if (ParseDepends(Ver,pkgTagSection::Key::Enhances,pkgCache::Dep::Enhances) == false)
return false;
- // Obsolete.
- if (ParseDepends(Ver,pkgTagSection::Key::Optional,pkgCache::Dep::Suggests) == false)
- return false;
-
+
if (ParseProvides(Ver) == false)
return false;
if (not APT::KernelAutoRemoveHelper::getUname(Ver.ParentPkg().Name()).empty())
@@ -259,21 +256,20 @@ bool debListParser::NewVersion(pkgCache::VerIterator &Ver)
// ListParser::AvailableDescriptionLanguages /*{{{*/
std::vector<std::string> debListParser::AvailableDescriptionLanguages()
{
- std::vector<std::string> const understood = APT::Configuration::getLanguages(true);
std::vector<std::string> avail;
static constexpr int prefixLen = 12;
char buf[32] = "Description-";
- if (Section.Exists("Description") == true)
- avail.push_back("");
- for (std::vector<std::string>::const_iterator lang = understood.begin(); lang != understood.end(); ++lang)
+ if (Section.Exists(pkgTagSection::Key::Description))
+ avail.emplace_back();
+ for (auto const &lang : APT::Configuration::getLanguages(true))
{
- if (unlikely(lang->size() > sizeof(buf) - prefixLen)) {
- _error->Warning("Ignoring translated description %s", lang->c_str());
+ if (unlikely(lang.size() > sizeof(buf) - prefixLen)) {
+ _error->Warning("Ignoring translated description %s", lang.c_str());
continue;
}
- memcpy(buf + prefixLen, lang->c_str(), lang->size());
- if (Section.Exists(StringView(buf, prefixLen + lang->size())) == true)
- avail.push_back(*lang);
+ memcpy(buf + prefixLen, lang.c_str(), lang.size());
+ if (Section.Exists(StringView(buf, prefixLen + lang.size())) == true)
+ avail.push_back(lang);
}
return avail;
}
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/debrecords.cc b/apt-pkg/deb/debrecords.cc
index 22ac219ba..e2ffaefff 100644
--- a/apt-pkg/deb/debrecords.cc
+++ b/apt-pkg/deb/debrecords.cc
@@ -16,6 +16,7 @@
#include <apt-pkg/fileutl.h>
#include <apt-pkg/pkgcache.h>
#include <apt-pkg/strutl.h>
+#include <apt-pkg/tagfile-keys.h>
#include <apt-pkg/tagfile.h>
#include <algorithm>
@@ -57,13 +58,13 @@ debRecordParserBase::debRecordParserBase() : Parser(), d(NULL) {}
// RecordParserBase::FileName - Return the archive filename on the site /*{{{*/
string debRecordParserBase::FileName()
{
- return Section.FindS("Filename");
+ return Section.Find(pkgTagSection::Key::Filename).to_string();
}
/*}}}*/
// RecordParserBase::Name - Return the package name /*{{{*/
string debRecordParserBase::Name()
{
- string Result = Section.FindS("Package");
+ auto Result = Section.Find(pkgTagSection::Key::Package).to_string();
// Normalize mixed case package names to lower case, like dpkg does
// See Bug#807012 for details
@@ -75,7 +76,7 @@ string debRecordParserBase::Name()
// RecordParserBase::Homepage - Return the package homepage /*{{{*/
string debRecordParserBase::Homepage()
{
- return Section.FindS("Homepage");
+ return Section.Find(pkgTagSection::Key::Homepage).to_string();
}
/*}}}*/
// RecordParserBase::Hashes - return the available archive hashes /*{{{*/
@@ -88,7 +89,7 @@ HashStringList debRecordParserBase::Hashes() const
if (hash.empty() == false)
hashes.push_back(HashString(*type, hash));
}
- auto const size = Section.FindULL("Size", 0);
+ auto const size = Section.FindULL(pkgTagSection::Key::Size, 0);
if (size != 0)
hashes.FileSize(size);
return hashes;
@@ -97,7 +98,7 @@ HashStringList debRecordParserBase::Hashes() const
// RecordParserBase::Maintainer - Return the maintainer email /*{{{*/
string debRecordParserBase::Maintainer()
{
- return Section.FindS("Maintainer");
+ return Section.Find(pkgTagSection::Key::Maintainer).to_string();
}
/*}}}*/
// RecordParserBase::RecordField - Return the value of an arbitrary field /*{{*/
@@ -129,25 +130,25 @@ string debRecordParserBase::LongDesc(std::string const &lang)
l != lang.end(); ++l)
{
std::string const tagname = "Description-" + *l;
- orig = Section.FindS(tagname.c_str());
+ orig = Section.FindS(tagname);
if (orig.empty() == false)
break;
else if (*l == "en")
{
- orig = Section.FindS("Description");
+ orig = Section.Find(pkgTagSection::Key::Description).to_string();
if (orig.empty() == false)
break;
}
}
if (orig.empty() == true)
- orig = Section.FindS("Description");
+ orig = Section.Find(pkgTagSection::Key::Description).to_string();
}
else
{
std::string const tagname = "Description-" + lang;
orig = Section.FindS(tagname.c_str());
if (orig.empty() == true && lang == "en")
- orig = Section.FindS("Description");
+ orig = Section.Find(pkgTagSection::Key::Description).to_string();
}
char const * const codeset = nl_langinfo(CODESET);
@@ -165,17 +166,17 @@ static const char * const SourceVerSeparators = " ()";
// RecordParserBase::SourcePkg - Return the source package name if any /*{{{*/
string debRecordParserBase::SourcePkg()
{
- string Res = Section.FindS("Source");
- string::size_type Pos = Res.find_first_of(SourceVerSeparators);
- if (Pos == string::npos)
- return Res;
- return string(Res,0,Pos);
+ auto Res = Section.Find(pkgTagSection::Key::Source).to_string();
+ auto const Pos = Res.find_first_of(SourceVerSeparators);
+ if (Pos != std::string::npos)
+ Res.erase(Pos);
+ return Res;
}
/*}}}*/
// RecordParserBase::SourceVer - Return the source version number if present /*{{{*/
string debRecordParserBase::SourceVer()
{
- string Pkg = Section.FindS("Source");
+ auto const Pkg = Section.Find(pkgTagSection::Key::Source).to_string();
string::size_type Pos = Pkg.find_first_of(SourceVerSeparators);
if (Pos == string::npos)
return "";
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;
}
diff --git a/apt-pkg/deb/debsrcrecords.h b/apt-pkg/deb/debsrcrecords.h
index b572d3427..1a0bbe0fd 100644
--- a/apt-pkg/deb/debsrcrecords.h
+++ b/apt-pkg/deb/debsrcrecords.h
@@ -12,6 +12,7 @@
#include <apt-pkg/fileutl.h>
#include <apt-pkg/srcrecords.h>
+#include <apt-pkg/tagfile-keys.h>
#include <apt-pkg/tagfile.h>
#include <string>
@@ -40,9 +41,9 @@ class APT_HIDDEN debSrcRecordParser : public pkgSrcRecords::Parser
virtual bool Jump(unsigned long const &Off) APT_OVERRIDE {iOffset = Off; return Tags.Jump(Sect,Off);};
virtual std::string Package() const APT_OVERRIDE;
- virtual std::string Version() const APT_OVERRIDE {return Sect.FindS("Version");};
- virtual std::string Maintainer() const APT_OVERRIDE {return Sect.FindS("Maintainer");};
- virtual std::string Section() const APT_OVERRIDE {return Sect.FindS("Section");};
+ virtual std::string Version() const APT_OVERRIDE {return Sect.Find(pkgTagSection::Key::Version).to_string();};
+ virtual std::string Maintainer() const APT_OVERRIDE {return Sect.Find(pkgTagSection::Key::Maintainer).to_string();};
+ virtual std::string Section() const APT_OVERRIDE {return Sect.Find(pkgTagSection::Key::Section).to_string();};
virtual const char **Binaries() APT_OVERRIDE;
virtual bool BuildDepends(std::vector<BuildDepRec> &BuildDeps, bool const &ArchOnly, bool const &StripMultiArch = true) APT_OVERRIDE;
virtual unsigned long Offset() APT_OVERRIDE {return iOffset;};