From 472376be6818b5ea43250abcbecfcab53b4a729a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 1 Apr 2022 13:45:09 +0200 Subject: Use pkgTagSection::Key in more places in src:apt The speed critical paths were converted earlier, but the remaining could benefit a tiny bit from this as well especially as we have the facility now available and can therefore brush up the code in various places in the process as well. Also takes the time to add the hidden Exists method advertised in the headers, but previously not implemented. --- apt-pkg/deb/deblistparser.cc | 21 +++++------ apt-pkg/deb/debrecords.cc | 29 +++++++------- apt-pkg/deb/debsrcrecords.h | 7 ++-- apt-pkg/depcache.cc | 9 +++-- apt-pkg/edsp/edsplistparser.cc | 5 ++- apt-pkg/indexcopy.cc | 15 +++----- apt-pkg/policy.cc | 12 +++--- apt-pkg/tagfile.cc | 5 +++ apt-private/private-show.cc | 11 ++++-- cmdline/apt-extracttemplates.cc | 9 +++-- cmdline/apt-sortpkgs.cc | 7 ++-- ftparchive/writer.cc | 84 +++++++++++++++++++---------------------- 12 files changed, 110 insertions(+), 104 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 debListParser::AvailableDescriptionLanguages() { - std::vector const understood = APT::Configuration::getLanguages(true); std::vector avail; static constexpr int prefixLen = 12; char buf[32] = "Description-"; - if (Section.Exists("Description") == true) - avail.push_back(""); - for (std::vector::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 #include #include +#include #include #include @@ -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 #include +#include #include #include @@ -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 &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 #include #include +#include #include #include #include @@ -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 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 #include #include +#include #include #include @@ -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 #include #include +#include #include #include @@ -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 #include #include +#include #include +#include #include #include #include @@ -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 @@ -625,6 +625,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 /*{{{*/ diff --git a/apt-private/private-show.cc b/apt-private/private-show.cc index b56b87d67..46c4c35e7 100644 --- a/apt-private/private-show.cc +++ b/apt-private/private-show.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -233,13 +234,15 @@ static bool DisplayRecordV2(pkgCacheFile &CacheFile, pkgRecords &Recs, /*{{{*/ // make size nice std::string installed_size; - if (Tags.FindULL("Installed-Size") > 0) - strprintf(installed_size, "%sB", SizeToStr(Tags.FindULL("Installed-Size") * 1024).c_str()); + auto const installed_size_field = Tags.FindULL(pkgTagSection::Key::Installed_Size); + if (installed_size_field > 0) + installed_size = SizeToStr(installed_size_field * 1024).append("B"); else installed_size = _("unknown"); std::string package_size; - if (Tags.FindULL("Size") > 0) - strprintf(package_size, "%sB", SizeToStr(Tags.FindULL("Size")).c_str()); + auto const package_size_field = Tags.FindULL(pkgTagSection::Key::Size); + if (package_size_field > 0) + package_size = SizeToStr(package_size_field).append("B"); else package_size = _("unknown"); diff --git a/cmdline/apt-extracttemplates.cc b/cmdline/apt-extracttemplates.cc index 01b5dbb11..88a204110 100644 --- a/cmdline/apt-extracttemplates.cc +++ b/cmdline/apt-extracttemplates.cc @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -170,11 +171,11 @@ bool DebFile::ParseInfo() if (Section.Scan(Control, ControlLen) == false) return false; - Package = Section.FindS("Package"); + Package = Section.Find(pkgTagSection::Key::Package).to_string(); Version = GetInstalledVer(Package); const char *Start, *Stop; - if (Section.Find("Depends", Start, Stop) == true) + if (Section.Find(pkgTagSection::Key::Depends, Start, Stop)) { while (1) { @@ -191,8 +192,8 @@ bool DebFile::ParseInfo() if (Start == Stop) break; } } - - if (Section.Find("Pre-Depends", Start, Stop) == true) + + if (Section.Find(pkgTagSection::Key::Pre_Depends, Start, Stop)) { while (1) { diff --git a/cmdline/apt-sortpkgs.cc b/cmdline/apt-sortpkgs.cc index da451708f..519825457 100644 --- a/cmdline/apt-sortpkgs.cc +++ b/cmdline/apt-sortpkgs.cc @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -85,9 +86,9 @@ static bool DoIt(string InFile) /* Fetch the name, auto-detecting if this is a source file or a package file */ - Tmp.Name = Section.FindS("Package"); - Tmp.Ver = Section.FindS("Version"); - Tmp.Arch = Section.FindS("Architecture"); + Tmp.Name = Section.Find(pkgTagSection::Key::Package).to_string(); + Tmp.Ver = Section.Find(pkgTagSection::Key::Version).to_string(); + Tmp.Arch = Section.Find(pkgTagSection::Key::Architecture).to_string(); if (Tmp.Name.empty() == true) return _error->Error(_("Unknown package record!")); diff --git a/ftparchive/writer.cc b/ftparchive/writer.cc index e5565fa47..c786be6ac 100644 --- a/ftparchive/writer.cc +++ b/ftparchive/writer.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -421,7 +422,7 @@ bool PackagesWriter::DoPackage(string FileName) // Lookup the override information pkgTagSection &Tags = Db.Control.Section; - string Package = Tags.FindS("Package"); + auto const Package = Tags.Find(pkgTagSection::Key::Package).to_string(); string Architecture; // if we generate a Packages file for a given arch, we use it to // look for overrides. if we run in "simple" mode without the @@ -430,9 +431,9 @@ bool PackagesWriter::DoPackage(string FileName) if(Arch != "") Architecture = Arch; else - Architecture = Tags.FindS("Architecture"); - unique_ptr OverItem(Over.GetItem(Package,Architecture)); - + Architecture = Tags.Find(pkgTagSection::Key::Architecture).to_string(); + unique_ptr OverItem(Over.GetItem(Package, Architecture)); + if (Package.empty() == true) return _error->Error(_("Archive had no package field")); @@ -444,10 +445,10 @@ bool PackagesWriter::DoPackage(string FileName) NewLine(1); ioprintf(c1out, _(" %s has no override entry\n"), Package.c_str()); } - + OverItem = unique_ptr(new Override::Item); - OverItem->FieldOverride["Section"] = Tags.FindS("Section"); - OverItem->Priority = Tags.FindS("Priority"); + OverItem->FieldOverride["Section"] = Tags.Find(pkgTagSection::Key::Section).to_string(); + OverItem->Priority = Tags.Find(pkgTagSection::Key::Priority).to_string(); } // Strip the DirStrip prefix from the FileName and add the PathPrefix @@ -466,7 +467,7 @@ bool PackagesWriter::DoPackage(string FileName) in the package file - instead we want to ship a separated file */ string desc; if (LongDescription == false) { - desc = Tags.FindS("Description").append("\n"); + desc = Tags.Find(pkgTagSection::Key::Description).to_string().append("\n"); OverItem->FieldOverride["Description"] = desc.substr(0, desc.find('\n')).c_str(); } @@ -499,14 +500,14 @@ bool PackagesWriter::DoPackage(string FileName) // Rewrite the maintainer field if necessary bool MaintFailed; - string NewMaint = OverItem->SwapMaint(Tags.FindS("Maintainer"),MaintFailed); + string NewMaint = OverItem->SwapMaint(Tags.Find(pkgTagSection::Key::Maintainer).to_string(), MaintFailed); if (MaintFailed == true) { if (NoOverride == false) { NewLine(1); ioprintf(c1out, _(" %s maintainer is %s not %s\n"), - Package.c_str(), Tags.FindS("Maintainer").c_str(), OverItem->OldMaint.c_str()); + Package.c_str(), Tags.Find(pkgTagSection::Key::Maintainer).to_string().c_str(), OverItem->OldMaint.c_str()); } } @@ -614,14 +615,14 @@ SourcesWriter::SourcesWriter(FileFd * const GivenOutput, string const &DB, strin /*}}}*/ // SourcesWriter::DoPackage - Process a single package /*{{{*/ static std::string getDscHash(unsigned int const DoHashes, - Hashes::SupportedHashes const DoIt, pkgTagSection &Tags, char const * const FieldName, + Hashes::SupportedHashes const DoIt, pkgTagSection &Tags, pkgTagSection::Key const FieldKey, HashString const * const Hash, unsigned long long Size, std::string const &FileName) { - if ((DoHashes & DoIt) != DoIt || Tags.Exists(FieldName) == false || Hash == NULL) + if ((DoHashes & DoIt) != DoIt || not Tags.Exists(FieldKey) || Hash == nullptr) return ""; std::ostringstream out; out << "\n " << Hash->HashValue() << " " << std::to_string(Size) << " " << FileName - << "\n " << Tags.FindS(FieldName); + << "\n " << Tags.Find(FieldKey).to_string(); return out.str(); } bool SourcesWriter::DoPackage(string FileName) @@ -646,19 +647,20 @@ bool SourcesWriter::DoPackage(string FileName) if (Tags.Scan(Db.Dsc.Data.c_str(), Db.Dsc.Data.length()) == false) return _error->Error("Could not find a record in the DSC '%s'",FileName.c_str()); - if (Tags.Exists("Source") == false) + if (not Tags.Exists(pkgTagSection::Key::Source)) return _error->Error("Could not find a Source entry in the DSC '%s'",FileName.c_str()); Tags.Trim(); // Lookup the override information, finding first the best priority. string BestPrio; - string Bins = Tags.FindS("Binary"); + auto const Bins = Tags.Find(pkgTagSection::Key::Binary); char Buffer[Bins.length() + 1]; unique_ptr OverItem(nullptr); if (Bins.empty() == false) { - strcpy(Buffer,Bins.c_str()); - + strncpy(Buffer, Bins.data(), Bins.length()); + Buffer[Bins.length()] = '\0'; + // Ignore too-long errors. char *BinList[400]; TokSplitString(',',Buffer,BinList,sizeof(BinList)/sizeof(BinList[0])); @@ -688,8 +690,8 @@ bool SourcesWriter::DoPackage(string FileName) { if (NoOverride == false) { - NewLine(1); - ioprintf(c1out, _(" %s has no override entry\n"), Tags.FindS("Source").c_str()); + NewLine(1); + ioprintf(c1out, _(" %s has no override entry\n"), Tags.Find(pkgTagSection::Key::Source).to_string().c_str()); } OverItem.reset(new Override::Item); @@ -699,15 +701,16 @@ bool SourcesWriter::DoPackage(string FileName) if (stat(FileName.c_str(), &St) != 0) return _error->Errno("fstat","Failed to stat %s",FileName.c_str()); - unique_ptr SOverItem(SOver.GetItem(Tags.FindS("Source"))); + auto const Package = Tags.Find(pkgTagSection::Key::Source).to_string(); + unique_ptr SOverItem(SOver.GetItem(Package)); // const unique_ptr autoSOverItem(SOverItem); if (SOverItem.get() == 0) { - ioprintf(c1out, _(" %s has no source override entry\n"), Tags.FindS("Source").c_str()); - SOverItem = unique_ptr(BOver.GetItem(Tags.FindS("Source"))); + ioprintf(c1out, _(" %s has no source override entry\n"), Package.c_str()); + SOverItem = unique_ptr(BOver.GetItem(Package)); if (SOverItem.get() == 0) { - ioprintf(c1out, _(" %s has no binary override entry either\n"), Tags.FindS("Source").c_str()); + ioprintf(c1out, _(" %s has no binary override entry either\n"), Package.c_str()); SOverItem = unique_ptr(new Override::Item); *SOverItem = *OverItem; } @@ -715,10 +718,10 @@ bool SourcesWriter::DoPackage(string FileName) // Add the dsc to the files hash list string const strippedName = flNotDir(FileName); - std::string const Files = getDscHash(DoHashes, Hashes::MD5SUM, Tags, "Files", Db.HashesList.find("MD5Sum"), St.st_size, strippedName); - std::string ChecksumsSha1 = getDscHash(DoHashes, Hashes::SHA1SUM, Tags, "Checksums-Sha1", Db.HashesList.find("SHA1"), St.st_size, strippedName); - std::string ChecksumsSha256 = getDscHash(DoHashes, Hashes::SHA256SUM, Tags, "Checksums-Sha256", Db.HashesList.find("SHA256"), St.st_size, strippedName); - std::string ChecksumsSha512 = getDscHash(DoHashes, Hashes::SHA512SUM, Tags, "Checksums-Sha512", Db.HashesList.find("SHA512"), St.st_size, strippedName); + std::string const Files = getDscHash(DoHashes, Hashes::MD5SUM, Tags, pkgTagSection::Key::Files, Db.HashesList.find("MD5Sum"), St.st_size, strippedName); + std::string ChecksumsSha1 = getDscHash(DoHashes, Hashes::SHA1SUM, Tags, pkgTagSection::Key::Checksums_Sha1, Db.HashesList.find("SHA1"), St.st_size, strippedName); + std::string ChecksumsSha256 = getDscHash(DoHashes, Hashes::SHA256SUM, Tags, pkgTagSection::Key::Checksums_Sha256, Db.HashesList.find("SHA256"), St.st_size, strippedName); + std::string ChecksumsSha512 = getDscHash(DoHashes, Hashes::SHA512SUM, Tags, pkgTagSection::Key::Checksums_Sha512, Db.HashesList.find("SHA512"), St.st_size, strippedName); // Strip the DirStrip prefix from the FileName and add the PathPrefix string NewFileName; @@ -732,7 +735,6 @@ bool SourcesWriter::DoPackage(string FileName) NewFileName = flCombine(PathPrefix,NewFileName); string Directory = flNotFile(OriginalPath); - string Package = Tags.FindS("Source"); // Perform operation over all of the files string ParseJnk; @@ -750,9 +752,9 @@ bool SourcesWriter::DoPackage(string FileName) string OriginalPath = Directory + ParseJnk; // Add missing hashes to source files - if (((DoHashes & Hashes::SHA1SUM) == Hashes::SHA1SUM && !Tags.Exists("Checksums-Sha1")) || - ((DoHashes & Hashes::SHA256SUM) == Hashes::SHA256SUM && !Tags.Exists("Checksums-Sha256")) || - ((DoHashes & Hashes::SHA512SUM) == Hashes::SHA512SUM && !Tags.Exists("Checksums-Sha512"))) + if (((DoHashes & Hashes::SHA1SUM) == Hashes::SHA1SUM && not Tags.Exists(pkgTagSection::Key::Checksums_Sha1)) || + ((DoHashes & Hashes::SHA256SUM) == Hashes::SHA256SUM && not Tags.Exists(pkgTagSection::Key::Checksums_Sha256)) || + ((DoHashes & Hashes::SHA512SUM) == Hashes::SHA512SUM && not Tags.Exists(pkgTagSection::Key::Checksums_Sha512))) { if (Db.GetFileInfo(OriginalPath, false, /* DoControl */ @@ -848,14 +850,14 @@ bool SourcesWriter::DoPackage(string FileName) // Rewrite the maintainer field if necessary bool MaintFailed; - string NewMaint = OverItem->SwapMaint(Tags.FindS("Maintainer"), MaintFailed); + string NewMaint = OverItem->SwapMaint(Tags.Find(pkgTagSection::Key::Maintainer).to_string(), MaintFailed); if (MaintFailed == true) { if (NoOverride == false) { NewLine(1); ioprintf(c1out, _(" %s maintainer is %s not %s\n"), Package.c_str(), - Tags.FindS("Maintainer").c_str(), OverItem->OldMaint.c_str()); + Tags.Find(pkgTagSection::Key::Maintainer).to_string().c_str(), OverItem->OldMaint.c_str()); } } if (NewMaint.empty() == false) @@ -907,7 +909,7 @@ bool ContentsWriter::DoPackage(string FileName, string Package) // Parse the package name if (Package.empty() == true) { - Package = Db.Control.Section.FindS("Package"); + Package = Db.Control.Section.Find(pkgTagSection::Key::Package).to_string(); } Db.Contents.Add(Gen,Package); @@ -937,17 +939,9 @@ bool ContentsWriter::ReadFromPkgs(string const &PkgFile,string const &PkgCompres pkgTagSection Section; while (Tags.Step(Section) == true) { - string File = flCombine(Prefix,Section.FindS("FileName")); - string Package = Section.FindS("Section"); - if (Package.empty() == false && Package.end()[-1] != '/') - { - Package += '/'; - Package += Section.FindS("Package"); - } - else - Package += Section.FindS("Package"); - - DoPackage(File,Package); + auto File = flCombine(Prefix, Section.Find(pkgTagSection::Key::Filename).to_string()); + auto Package = flCombine(Section.Find(pkgTagSection::Key::Section).to_string(), Section.Find(pkgTagSection::Key::Package).to_string()); + DoPackage(std::move(File), std::move(Package)); if (_error->empty() == false) { _error->Error("Errors apply to file '%s'",File.c_str()); -- cgit v1.2.3-70-g09d2