summaryrefslogtreecommitdiff
path: root/apt-pkg
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
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')
-rw-r--r--apt-pkg/CMakeLists.txt7
-rw-r--r--apt-pkg/acquire-item.cc18
-rw-r--r--apt-pkg/cachefilter-patterns.h5
-rw-r--r--apt-pkg/contrib/hashes.cc11
-rw-r--r--apt-pkg/contrib/hashes.h14
-rw-r--r--apt-pkg/contrib/header-is-private.h3
-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
-rw-r--r--apt-pkg/depcache.cc9
-rw-r--r--apt-pkg/edsp.cc2
-rw-r--r--apt-pkg/edsp/edsplistparser.cc9
-rw-r--r--apt-pkg/indexcopy.cc31
-rw-r--r--apt-pkg/policy.cc12
-rw-r--r--apt-pkg/tagfile-keys.list26
-rw-r--r--apt-pkg/tagfile-order.c35
-rw-r--r--apt-pkg/tagfile.cc9
-rw-r--r--apt-pkg/tagfile.h23
20 files changed, 161 insertions, 145 deletions
diff --git a/apt-pkg/CMakeLists.txt b/apt-pkg/CMakeLists.txt
index 5c97493af..a40b041b8 100644
--- a/apt-pkg/CMakeLists.txt
+++ b/apt-pkg/CMakeLists.txt
@@ -2,7 +2,8 @@
include_directories(${PROJECT_BINARY_DIR}/include/apt-pkg)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/include/apt-pkg/)
-execute_process(COMMAND ${TRIEHASH_EXECUTABLE}
+execute_process(COMMAND grep -v "^#" "${CMAKE_CURRENT_SOURCE_DIR}/tagfile-keys.list"
+ COMMAND ${TRIEHASH_EXECUTABLE}
--ignore-case
--header ${PROJECT_BINARY_DIR}/include/apt-pkg/tagfile-keys.h
--code ${CMAKE_CURRENT_BINARY_DIR}/tagfile-keys.cc
@@ -10,8 +11,10 @@ execute_process(COMMAND ${TRIEHASH_EXECUTABLE}
--enum-name pkgTagSection::Key
--function-name pkgTagHash
--include "<apt-pkg/tagfile.h>"
- ${CMAKE_CURRENT_SOURCE_DIR}/tagfile-keys.list)
+ --include "<apt-pkg/header-is-private.h>"
+ /dev/stdin )
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "tagfile-keys.list")
+set_source_files_properties("${CMAKE_CURRENT_BINARY_DIR}/tagfile-keys.cc" PROPERTIES COMPILE_DEFINITIONS APT_COMPILING_APT)
# Set the version of the library
diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc
index f9362b0d5..d9e1e516b 100644
--- a/apt-pkg/acquire-item.cc
+++ b/apt-pkg/acquire-item.cc
@@ -2371,13 +2371,13 @@ bool pkgAcqDiffIndex::ParseDiffIndex(string const &IndexDiffFile) /*{{{*/
{
std::string tagname = *type;
tagname.append("-Current");
- std::string const tmp = Tags.FindS(tagname.c_str());
+ auto const tmp = Tags.Find(tagname);
if (tmp.empty() == true)
continue;
string hash;
unsigned long long size;
- std::stringstream ss(tmp);
+ std::stringstream ss(tmp.to_string());
ss.imbue(posix);
ss >> hash >> size;
if (unlikely(hash.empty() == true))
@@ -2441,13 +2441,13 @@ bool pkgAcqDiffIndex::ParseDiffIndex(string const &IndexDiffFile) /*{{{*/
std::string tagname = *type;
tagname.append("-History");
- std::string const tmp = Tags.FindS(tagname.c_str());
+ auto const tmp = Tags.Find(tagname);
if (tmp.empty() == true)
continue;
string hash, filename;
unsigned long long size;
- std::stringstream ss(tmp);
+ std::stringstream ss(tmp.to_string());
ss.imbue(posix);
while (ss >> hash >> size >> filename)
@@ -2498,13 +2498,13 @@ bool pkgAcqDiffIndex::ParseDiffIndex(string const &IndexDiffFile) /*{{{*/
std::string tagname = *type;
tagname.append("-Patches");
- std::string const tmp = Tags.FindS(tagname.c_str());
+ auto const tmp = Tags.Find(tagname);
if (tmp.empty() == true)
continue;
string hash, filename;
unsigned long long size;
- std::stringstream ss(tmp);
+ std::stringstream ss(tmp.to_string());
ss.imbue(posix);
while (ss >> hash >> size >> filename)
@@ -2536,13 +2536,13 @@ bool pkgAcqDiffIndex::ParseDiffIndex(string const &IndexDiffFile) /*{{{*/
{
std::string tagname = *type;
tagname.append("-Download");
- std::string const tmp = Tags.FindS(tagname.c_str());
+ auto const tmp = Tags.Find(tagname);
if (tmp.empty() == true)
continue;
string hash, filename;
unsigned long long size;
- std::stringstream ss(tmp);
+ std::stringstream ss(tmp.to_string());
ss.imbue(posix);
// FIXME: all of pdiff supports only .gz compressed patches
@@ -2613,7 +2613,7 @@ bool pkgAcqDiffIndex::ParseDiffIndex(string const &IndexDiffFile) /*{{{*/
if (pdiff_merge == true)
{
// reprepro and dak add this flag if they merge patches on the server
- std::string const precedence = Tags.FindS("X-Patch-Precedence");
+ auto const precedence = Tags.Find("X-Patch-Precedence");
pdiff_merge = (precedence != "merged");
}
diff --git a/apt-pkg/cachefilter-patterns.h b/apt-pkg/cachefilter-patterns.h
index e6ea16c68..284fcc1cf 100644
--- a/apt-pkg/cachefilter-patterns.h
+++ b/apt-pkg/cachefilter-patterns.h
@@ -11,6 +11,7 @@
#include <apt-pkg/cachefile.h>
#include <apt-pkg/cachefilter.h>
#include <apt-pkg/error.h>
+#include <apt-pkg/header-is-private.h>
#include <apt-pkg/string_view.h>
#include <apt-pkg/strutl.h>
#include <iostream>
@@ -20,10 +21,6 @@
#include <vector>
#include <assert.h>
-#ifndef APT_COMPILING_APT
-#error Internal header
-#endif
-
namespace APT
{
diff --git a/apt-pkg/contrib/hashes.cc b/apt-pkg/contrib/hashes.cc
index 267e2679a..313b1d37d 100644
--- a/apt-pkg/contrib/hashes.cc
+++ b/apt-pkg/contrib/hashes.cc
@@ -17,6 +17,8 @@
#include <apt-pkg/hashes.h>
#include <apt-pkg/macros.h>
#include <apt-pkg/strutl.h>
+#include <apt-pkg/tagfile-keys.h>
+#include <apt-pkg/tagfile.h>
#include <algorithm>
#include <iostream>
@@ -45,6 +47,15 @@ const char * HashString::_SupportedHashes[] =
{
"SHA512", "SHA256", "SHA1", "MD5Sum", "Checksum-FileSize", NULL
};
+std::vector<HashString::HashSupportInfo> HashString::SupportedHashesInfo()
+{
+ return {{
+ { "SHA512", pkgTagSection::Key::SHA512,"Checksums-Sha512", pkgTagSection::Key::Checksums_Sha512},
+ { "SHA256", pkgTagSection::Key::SHA256, "Checksums-Sha256", pkgTagSection::Key::Checksums_Sha256},
+ { "SHA1", pkgTagSection::Key::SHA1, "Checksums-Sha1", pkgTagSection::Key::Checksums_Sha1 },
+ { "MD5Sum", pkgTagSection::Key::MD5sum, "Files", pkgTagSection::Key::Files },
+ }};
+}
HashString::HashString()
{
diff --git a/apt-pkg/contrib/hashes.h b/apt-pkg/contrib/hashes.h
index 422c1e023..e259b4e28 100644
--- a/apt-pkg/contrib/hashes.h
+++ b/apt-pkg/contrib/hashes.h
@@ -14,6 +14,11 @@
#include <apt-pkg/macros.h>
+#ifdef APT_COMPILING_APT
+#include <apt-pkg/string_view.h>
+#include <apt-pkg/tagfile-keys.h>
+#endif
+
#include <cstring>
#include <string>
#include <vector>
@@ -59,6 +64,15 @@ class APT_PUBLIC HashString
// return the list of hashes we support
static APT_PURE const char** SupportedHashes();
+#ifdef APT_COMPILING_APT
+ struct APT_HIDDEN HashSupportInfo {
+ APT::StringView name;
+ pkgTagSection::Key namekey;
+ APT::StringView chksumsname;
+ pkgTagSection::Key chksumskey;
+ };
+ APT_HIDDEN static std::vector<HashSupportInfo> SupportedHashesInfo();
+#endif
};
class APT_PUBLIC HashStringList
diff --git a/apt-pkg/contrib/header-is-private.h b/apt-pkg/contrib/header-is-private.h
new file mode 100644
index 000000000..201a40c62
--- /dev/null
+++ b/apt-pkg/contrib/header-is-private.h
@@ -0,0 +1,3 @@
+#ifndef APT_COMPILING_APT
+#error Internal header without ABI stability. Should only be used by apt itself!
+#endif
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;};
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.cc b/apt-pkg/edsp.cc
index b7c0d28d2..6493a4595 100644
--- a/apt-pkg/edsp.cc
+++ b/apt-pkg/edsp.cc
@@ -453,7 +453,7 @@ bool EDSP::ReadResponse(int const input, pkgDepCache &Cache, OpProgress *Progres
continue;
}
- decltype(VersionCount) const id = section.FindULL(type.c_str(), VersionCount);
+ decltype(VersionCount) const id = section.FindULL(type, VersionCount);
if (id == VersionCount) {
_error->Warning("Unable to parse %s request with id value '%s'!", type.c_str(), section.FindS(type.c_str()).c_str());
continue;
diff --git a/apt-pkg/edsp/edsplistparser.cc b/apt-pkg/edsp/edsplistparser.cc
index 34b9ec934..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>
@@ -61,9 +62,7 @@ APT::StringView edspLikeListParser::Description_md5()
// ListParser::VersionHash - Compute a unique hash for this version /*{{{*/
uint32_t edspLikeListParser::VersionHash()
{
- if (Section.Exists("APT-Hash") == true)
- return Section.FindI("APT-Hash");
- else if (Section.Exists("APT-ID") == true)
+ if (Section.Exists("APT-ID") == true)
return Section.FindI("APT-ID");
return 0;
}
@@ -143,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..0d569265d 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;
@@ -436,29 +437,16 @@ 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.c_str());
- 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;
- // 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 +460,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-keys.list b/apt-pkg/tagfile-keys.list
index 36da3435e..4b57e46c2 100644
--- a/apt-pkg/tagfile-keys.list
+++ b/apt-pkg/tagfile-keys.list
@@ -1,7 +1,16 @@
+# This file is input for triehash(1) (after stripping comments)
+#
+# The fields listed here are accessible via pkgTagSection::Key::FIELD
+# Do *NOT* edit, remove or insert new fields in the sorted section here
+# as the file forms part of the ABI of the libapt library and is used
+# by our apt tools. External clients are forbidden though, so if really needed
+# we can use libapt Breaks: apt, but always prefer appending only.
+#
+# For Fields used in Packages, Sources and status files, see also tagfile-order.c
Architecture
+Auto-Built-Package
Binary
Breaks
-Bugs
Build-Conflicts
Build-Conflicts-Arch
Build-Conflicts-Indep
@@ -15,7 +24,6 @@ Checksums-Md5
Checksums-Sha1
Checksums-Sha256
Checksums-Sha512
-Class
Conffiles
Config-Version
Conflicts
@@ -23,7 +31,6 @@ Depends
Description
Description-md5
Directory
-Dm-Upload-Allowed
Enhances
Essential
Filename
@@ -32,29 +39,21 @@ Format
Homepage
Important
Installed-Size
-Installer-Menu-Item
-Kernel-Version
Maintainer
MD5sum
-MSDOS-Filename
Multi-Arch
-Optional
Origin
Original-Maintainer
Package
Package-List
-Package_Revision
-Package-Revision
Package-Type
Phased-Update-Percentage
Pre-Depends
Priority
Protected
Provides
-Recommended
Recommends
Replaces
-Revision
Section
SHA1
SHA256
@@ -64,17 +63,13 @@ Source
Standards-Version
Static-Built-Using
Status
-Subarchitecture
Suggests
Tag
Task
Testsuite
Testsuite-Triggers
-Triggers-Awaited
-Triggers-Pending
Uploaders
Vcs-Arch
-Vcs-Browse
Vcs-Browser
Vcs-Bzr
Vcs-Cvs
@@ -84,3 +79,4 @@ Vcs-Hg
Vcs-Mtn
Vcs-Svn
Version
+### APPEND BELOW, sort in with next ABI break ###
diff --git a/apt-pkg/tagfile-order.c b/apt-pkg/tagfile-order.c
index 79d6992b4..7cf188c51 100644
--- a/apt-pkg/tagfile-order.c
+++ b/apt-pkg/tagfile-order.c
@@ -9,12 +9,12 @@ static const char *iTFRewritePackageOrder[] = {
"Package",
"Package-Type",
"Architecture",
- "Subarchitecture", // Used only by d-i
+ "Subarchitecture", // NO_KEY: Used only by d-i
"Version",
- "Revision", // Obsolete (warning in dpkg)
- "Package-Revision", // Obsolete (warning in dpkg)
- "Package_Revision", // Obsolete (warning in dpkg)
- "Kernel-Version", // Used only by d-i
+// "Revision", // Obsolete (warning in dpkg)
+// "Package-Revision", // Obsolete (warning in dpkg)
+// "Package_Revision", // Obsolete (warning in dpkg)
+ "Kernel-Version", // NO_KEY: Used only by d-i
"Built-Using",
"Static-Built-Using",
"Built-For-Profiles",
@@ -22,35 +22,37 @@ static const char *iTFRewritePackageOrder[] = {
"Multi-Arch",
"Status",
"Priority",
- "Class", // dpkg nickname for Priority
+// "Class", // Obsolete alias for Priority, warning by dpkg
"Build-Essential",
"Protected",
+ "Important", // old name of Protected
"Essential",
- "Installer-Menu-Item", // Used only by d-i
+ "Installer-Menu-Item", // NO_KEY: Used only by d-i
"Section",
"Source",
"Origin",
+ "Phased-Update-Percentage",
"Maintainer",
"Original-Maintainer", // unknown in dpkg order
- "Bugs",
+ "Bugs", // NO_KEY: very uncommon encounter
"Config-Version", // Internal of dpkg
"Conffiles",
- "Triggers-Awaited",
- "Triggers-Pending",
+ "Triggers-Awaited", // NO_KEY: Internal of dpkg
+ "Triggers-Pending", // NO_KEY: Internal of dpkg
"Installed-Size",
"Provides",
"Pre-Depends",
"Depends",
"Recommends",
- "Recommended", // dpkg nickname for Recommends
+// "Recommended", // Obsolete alias for Recommends, warning by dpkg
"Suggests",
- "Optional", // dpkg nickname for Suggests
+// "Optional", // Obsolete alias for Suggests, warning by dpkg
"Conflicts",
"Breaks",
"Replaces",
"Enhances",
"Filename",
- "MSDOS-Filename", // Obsolete (used by dselect)
+ "MSDOS-Filename", // NO_KEY: Obsolete (used by dselect)
"Size",
"MD5sum",
"SHA1",
@@ -58,6 +60,7 @@ static const char *iTFRewritePackageOrder[] = {
"SHA512",
"Homepage",
"Description",
+ "Description-md5",
"Tag",
"Task",
0,
@@ -70,13 +73,13 @@ static const char *iTFRewriteSourceOrder[] = {
"Architecture",
"Version",
"Priority",
- "Class", // dpkg nickname for Priority
+// "Class", // Obsolete alias for Priority, warning by dpkg
"Section",
"Origin",
"Maintainer",
"Original-Maintainer", // unknown in dpkg order
"Uploaders",
- "Dm-Upload-Allowed", // Obsolete (ignored by dak)
+ "Dm-Upload-Allowed", // NO_KEY: Obsolete (ignored by dak)
"Standards-Version",
"Build-Depends",
"Build-Depends-Arch",
@@ -89,7 +92,7 @@ static const char *iTFRewriteSourceOrder[] = {
"Homepage",
"Description",
"Vcs-Browser",
- "Vcs-Browse", // dak only (nickname?)
+ "Vcs-Browse", // NO_KEY: dak only (nickname?)
"Vcs-Arch",
"Vcs-Bzr",
"Vcs-Cvs",
diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc
index 52000c6b9..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 /*{{{*/
// ---------------------------------------------------------------------
@@ -1051,8 +1056,8 @@ bool pkgTagSection::Write(FileFd &File, char const * const * const Order, std::v
{
if (R->Action == Tag::REMOVE)
continue;
- std::string const name = ((R->Action == Tag::RENAME) ? R->Data : R->Name);
- if (Exists(name.c_str()))
+ auto const name = ((R->Action == Tag::RENAME) ? R->Data : R->Name);
+ if (Exists(name))
continue;
if (Order != NULL)
{
diff --git a/apt-pkg/tagfile.h b/apt-pkg/tagfile.h
index f6bdd12c9..54562d07c 100644
--- a/apt-pkg/tagfile.h
+++ b/apt-pkg/tagfile.h
@@ -70,18 +70,21 @@ class APT_PUBLIC pkgTagSection
std::string FindS(APT::StringView sv) const { return Find(sv).to_string(); }
std::string FindRawS(APT::StringView sv) const { return FindRaw(sv).to_string(); };
+#ifdef APT_COMPILING_APT
// Functions for lookup with a perfect hash function
enum class Key;
- APT_HIDDEN bool Find(Key key,const char *&Start, const char *&End) const;
- APT_HIDDEN bool Find(Key key,unsigned int &Pos) const;
- APT_HIDDEN signed int FindI(Key key,signed long Default = 0) const;
- APT_HIDDEN bool FindB(Key key, bool Default = false) const;
- APT_HIDDEN unsigned long long FindULL(Key key, unsigned long long const &Default = 0) const;
- APT_HIDDEN bool FindFlag(Key key,uint8_t &Flags, uint8_t const Flag) const;
- APT_HIDDEN bool FindFlag(Key key,unsigned long &Flags, unsigned long Flag) const;
- APT_HIDDEN bool Exists(Key key) const;
- APT_HIDDEN APT::StringView Find(Key key) const;
- APT_HIDDEN APT::StringView FindRaw(Key key) const;
+ bool Find(Key key,const char *&Start, const char *&End) const;
+ bool Find(Key key,unsigned int &Pos) const;
+ signed int FindI(Key key,signed long Default = 0) const;
+ bool FindB(Key key, bool Default = false) const;
+ unsigned long long FindULL(Key key, unsigned long long const &Default = 0) const;
+ bool FindFlag(Key key,uint8_t &Flags, uint8_t const Flag) const;
+ bool FindFlag(Key key,unsigned long &Flags, unsigned long Flag) const;
+ bool Exists(Key key) const;
+ APT::StringView Find(Key key) const;
+ APT::StringView FindRaw(Key key) const;
+#endif
+
bool Find(APT::StringView Tag,const char *&Start, const char *&End) const;
bool Find(APT::StringView Tag,unsigned int &Pos) const;
APT::StringView Find(APT::StringView Tag) const;