summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/deb/deblistparser.cc21
-rw-r--r--apt-pkg/deb/debrecords.cc29
-rw-r--r--apt-pkg/deb/debsrcrecords.h7
-rw-r--r--apt-pkg/depcache.cc9
-rw-r--r--apt-pkg/edsp/edsplistparser.cc5
-rw-r--r--apt-pkg/indexcopy.cc15
-rw-r--r--apt-pkg/policy.cc12
-rw-r--r--apt-pkg/tagfile.cc5
8 files changed, 55 insertions, 48 deletions
diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc
index a1247dd98..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;
}
@@ -256,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/debrecords.cc b/apt-pkg/deb/debrecords.cc
index 8fb17ae0b..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 /*{{*/
@@ -134,20 +135,20 @@ string debRecordParserBase::LongDesc(std::string const &lang)
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.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;};
diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc
index f7d9832a0..a5b586f5b 100644
--- a/apt-pkg/depcache.cc
+++ b/apt-pkg/depcache.cc
@@ -23,6 +23,7 @@
#include <apt-pkg/prettyprinters.h>
#include <apt-pkg/progress.h>
#include <apt-pkg/strutl.h>
+#include <apt-pkg/tagfile-keys.h>
#include <apt-pkg/tagfile.h>
#include <apt-pkg/version.h>
#include <apt-pkg/versionmatch.h>
@@ -310,8 +311,8 @@ bool pkgDepCache::readStateFile(OpProgress * const Prog) /*{{{*/
off_t amt = 0;
bool const debug_autoremove = _config->FindB("Debug::pkgAutoRemove",false);
while(tagfile.Step(section)) {
- string const pkgname = section.FindS("Package");
- string pkgarch = section.FindS("Architecture");
+ auto const pkgname = section.Find(pkgTagSection::Key::Package);
+ auto pkgarch = section.Find(pkgTagSection::Key::Architecture);
if (pkgarch.empty() == true)
pkgarch = "any";
pkgCache::PkgIterator pkg = Cache->FindPkg(pkgname, pkgarch);
@@ -379,8 +380,8 @@ bool pkgDepCache::writeStateFile(OpProgress * const /*prog*/, bool const Install
pkgTagSection section;
std::set<string> pkgs_seen;
while(tagfile.Step(section)) {
- string const pkgname = section.FindS("Package");
- string pkgarch = section.FindS("Architecture");
+ auto const pkgname = section.Find(pkgTagSection::Key::Package);
+ auto pkgarch = section.Find(pkgTagSection::Key::Architecture);
if (pkgarch.empty() == true)
pkgarch = "native";
// Silently ignore unknown packages and packages with no actual
diff --git a/apt-pkg/edsp/edsplistparser.cc b/apt-pkg/edsp/edsplistparser.cc
index 0be543e3c..5419069f2 100644
--- a/apt-pkg/edsp/edsplistparser.cc
+++ b/apt-pkg/edsp/edsplistparser.cc
@@ -19,6 +19,7 @@
#include <apt-pkg/pkgsystem.h>
#include <apt-pkg/string_view.h>
#include <apt-pkg/strutl.h>
+#include <apt-pkg/tagfile-keys.h>
#include <apt-pkg/tagfile.h>
#include <array>
@@ -141,8 +142,8 @@ bool eippListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
{"triggers-pending",pkgCache::State::TriggersPending},
{"installed",pkgCache::State::Installed},
}};
- auto const status = Section.Find("Status");
- if (status.empty() == false)
+ auto const status = Section.Find(pkgTagSection::Key::Status);
+ if (not status.empty())
{
for (auto && sv: statusvalues)
{
diff --git a/apt-pkg/indexcopy.cc b/apt-pkg/indexcopy.cc
index 88c2150ff..82baba337 100644
--- a/apt-pkg/indexcopy.cc
+++ b/apt-pkg/indexcopy.cc
@@ -22,6 +22,7 @@
#include <apt-pkg/metaindex.h>
#include <apt-pkg/progress.h>
#include <apt-pkg/strutl.h>
+#include <apt-pkg/tagfile-keys.h>
#include <apt-pkg/tagfile.h>
#include <iostream>
@@ -413,8 +414,8 @@ bool IndexCopy::GrabFirst(string Path,string &To,unsigned int Depth)
/* */
bool PackageCopy::GetFile(string &File,unsigned long long &Size)
{
- File = Section->FindS("Filename");
- Size = Section->FindULL("Size");
+ File = Section->Find(pkgTagSection::Key::Filename).to_string();
+ Size = Section->FindULL(pkgTagSection::Key::Size);
if (File.empty() || Size == 0)
return _error->Error("Cannot find filename or size tag");
return true;
@@ -447,18 +448,13 @@ bool SourceCopy::GetFile(string &File,unsigned long long &Size)
else
checksumField.append(*type);
- Files = Section->FindS(checksumField.c_str());
+ Files = Section->FindS(checksumField);
if (Files.empty() == false)
break;
}
if (Files.empty() == true)
return false;
- // Stash the / terminated directory prefix
- string Base = Section->FindS("Directory");
- if (Base.empty() == false && Base[Base.length()-1] != '/')
- Base += '/';
-
// Read the first file triplet
const char *C = Files.c_str();
string sSize;
@@ -472,7 +468,8 @@ bool SourceCopy::GetFile(string &File,unsigned long long &Size)
// Parse the size and append the directory
Size = strtoull(sSize.c_str(), NULL, 10);
- File = Base + File;
+ auto const Base = Section->Find(pkgTagSection::Key::Directory);
+ File = flCombine(Base.to_string(), File);
return true;
}
/*}}}*/
diff --git a/apt-pkg/policy.cc b/apt-pkg/policy.cc
index c5328c517..b30eddb37 100644
--- a/apt-pkg/policy.cc
+++ b/apt-pkg/policy.cc
@@ -21,7 +21,9 @@
#include <apt-pkg/fileutl.h>
#include <apt-pkg/pkgcache.h>
#include <apt-pkg/policy.h>
+#include <apt-pkg/string_view.h>
#include <apt-pkg/strutl.h>
+#include <apt-pkg/tagfile-keys.h>
#include <apt-pkg/tagfile.h>
#include <apt-pkg/version.h>
#include <apt-pkg/versionmatch.h>
@@ -425,12 +427,12 @@ bool ReadPinFile(pkgPolicy &Plcy,string File)
if (Tags.Count() == 0)
continue;
- string Name = Tags.FindS("Package");
- if (Name.empty() == true)
+ auto Name = Tags.Find(pkgTagSection::Key::Package);
+ if (Name.empty())
return _error->Error(_("Invalid record in the preferences file %s, no Package header"), File.c_str());
if (Name == "*")
- Name = string();
-
+ Name = APT::StringView{};
+
const char *Start;
const char *End;
if (Tags.Find("Pin",Start,End) == false)
@@ -479,7 +481,7 @@ bool ReadPinFile(pkgPolicy &Plcy,string File)
return _error->Error(_("No priority (or zero) specified for pin"));
}
- istringstream s(Name);
+ std::istringstream s(Name.to_string());
string pkg;
while(!s.eof())
{
diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc
index ebad1a4c5..047f88986 100644
--- a/apt-pkg/tagfile.cc
+++ b/apt-pkg/tagfile.cc
@@ -626,6 +626,11 @@ bool pkgTagSection::Exists(StringView Tag) const
unsigned int tmp;
return Find(Tag, tmp);
}
+bool pkgTagSection::Exists(Key key) const
+{
+ unsigned int tmp;
+ return Find(key, tmp);
+}
/*}}}*/
// TagSection::Find - Locate a tag /*{{{*/
// ---------------------------------------------------------------------