From 729a5c8f4fb8c841497d26170e1a47c41617ecd9 Mon Sep 17 00:00:00 2001 From: наб Date: Thu, 23 Jan 2025 20:50:39 +0100 Subject: string{=> _view} flNotDir(string{=> _view}). Configuration::{Cnd,}Set(Value: string{=> _view}) --- apt-pkg/acquire-item.cc | 14 +++++++------- apt-pkg/cachefile.cc | 12 ++++++------ apt-pkg/contrib/configuration.cc | 4 ++-- apt-pkg/contrib/configuration.h | 10 +++++----- apt-pkg/contrib/fileutl.cc | 8 ++++---- apt-pkg/contrib/fileutl.h | 2 +- apt-pkg/deb/debindexfile.cc | 4 +++- apt-pkg/deb/dpkgpm.cc | 2 +- apt-pkg/sourcelist.cc | 7 ++++--- apt-private/private-cmndline.cc | 4 ++-- apt-private/private-download.cc | 3 ++- apt-private/private-source.cc | 2 +- apt-private/private-sources.cc | 6 +++--- apt-private/private-update.cc | 2 +- ftparchive/writer.cc | 6 +++--- methods/http.cc | 2 +- methods/mirror.cc | 4 ++-- methods/store.cc | 4 ++-- test/interactive-helper/aptwebserver.cc | 2 +- 19 files changed, 51 insertions(+), 47 deletions(-) diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index 7e0dc25d2..87e5ddefb 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -482,7 +482,7 @@ bool pkgAcqTransactionItem::QueueURI(pkgAcquire::ItemDesc &Item) return false; auto altPath = uri.Path.substr(0, trailing_slash) + "/by-hash/" + TargetHash->HashType() + "/" + TargetHash->HashValue(); std::swap(uri.Path, altPath); - PushAlternativeURI(uri, {{"Alternate-Paths", "../../" + flNotDir(altPath)}}, false); + PushAlternativeURI(uri, {{"Alternate-Paths", "../../"s += flNotDir(altPath)}}, false); return true; }; PushByHashURI(Item.URI); @@ -546,7 +546,7 @@ std::string pkgAcqMetaBase::GetFinalFilename() const } std::string pkgAcqArchive::GetFinalFilename() const { - return _config->FindDir("Dir::Cache::Archives") + flNotDir(StoreFilename); + return _config->FindDir("Dir::Cache::Archives") += flNotDir(StoreFilename); } /*}}}*/ // pkgAcqTransactionItem::GetMetaKey and specialisations for child classes /*{{{*/ @@ -3310,7 +3310,7 @@ void pkgAcqIndex::StageDownloadDone(string const &Message) if (StringToBool(LookupTag(Message, "IMS-Hit"), false)) { Filename = GetExistingFilename(GetFinalFileNameFromURI(Target.URI)); - EraseFileName = DestFile = flCombine(flNotFile(DestFile), flNotDir(Filename)); + EraseFileName = DestFile = flCombine(flNotFile(DestFile), std::string{flNotDir(Filename)}); if (symlink(Filename.c_str(), DestFile.c_str()) != 0) _error->WarningE("pkgAcqIndex::StageDownloadDone", "Symlinking file %s to %s failed", Filename.c_str(), DestFile.c_str()); Stage = STAGE_DECOMPRESS_AND_VERIFY; @@ -3527,7 +3527,7 @@ pkgAcqArchive::pkgAcqArchive(pkgAcquire *const Owner, pkgSourceList *const Sourc // Check if we already downloaded the file struct stat Buf; - auto FinalFile = _config->FindDir("Dir::Cache::Archives") + flNotDir(StoreFilename); + auto FinalFile = _config->FindDir("Dir::Cache::Archives") += flNotDir(StoreFilename); if (stat(FinalFile.c_str(), &Buf) == 0) { // Make sure the size matches @@ -3546,7 +3546,7 @@ pkgAcqArchive::pkgAcqArchive(pkgAcquire *const Owner, pkgSourceList *const Sourc } // Check the destination file - DestFile = _config->FindDir("Dir::Cache::Archives") + "partial/" + flNotDir(StoreFilename); + DestFile = (_config->FindDir("Dir::Cache::Archives") += "partial/") += flNotDir(StoreFilename); if (stat(DestFile.c_str(), &Buf) == 0) { // Hmm, the partial file is too big, erase it @@ -3953,9 +3953,9 @@ pkgAcqFile::pkgAcqFile(pkgAcquire *const Owner, string const &URI, HashStringLis if(!DestFilename.empty()) DestFile = DestFilename; else if(!DestDir.empty()) - DestFile = DestDir + "/" + DeQuoteString(flNotDir(url.Path)); + DestFile = DestDir + "/" + DeQuoteString(std::string{flNotDir(url.Path)}); else - DestFile = DeQuoteString(flNotDir(url.Path)); + DestFile = DeQuoteString(std::string{flNotDir(url.Path)}); // Create the item Desc.URI = std::string(url); diff --git a/apt-pkg/cachefile.cc b/apt-pkg/cachefile.cc index e27688b4e..8034ffea8 100644 --- a/apt-pkg/cachefile.cc +++ b/apt-pkg/cachefile.cc @@ -318,15 +318,15 @@ void pkgCacheFile::RemoveCaches() if (pkgcache.empty() == false) { std::string cachedir = flNotFile(pkgcache); - std::string cachefile = flNotDir(pkgcache); + std::string cachefile{flNotDir(pkgcache)}; if (cachedir.empty() != true && cachefile.empty() != true && DirectoryExists(cachedir) == true) { cachefile.append("."); std::vector caches = GetListOfFilesInDir(cachedir, false); for (std::vector::const_iterator file = caches.begin(); file != caches.end(); ++file) { - std::string nuke = flNotDir(*file); - if (strncmp(cachefile.c_str(), nuke.c_str(), cachefile.length()) != 0) + auto nuke = flNotDir(*file); + if (cachefile != nuke.substr(0, cachefile.length())) continue; RemoveFile("RemoveCaches", *file); } @@ -337,15 +337,15 @@ void pkgCacheFile::RemoveCaches() return; std::string cachedir = flNotFile(srcpkgcache); - std::string cachefile = flNotDir(srcpkgcache); + std::string cachefile{flNotDir(srcpkgcache)}; if (cachedir.empty() == true || cachefile.empty() == true || DirectoryExists(cachedir) == false) return; cachefile.append("."); std::vector caches = GetListOfFilesInDir(cachedir, false); for (std::vector::const_iterator file = caches.begin(); file != caches.end(); ++file) { - std::string nuke = flNotDir(*file); - if (strncmp(cachefile.c_str(), nuke.c_str(), cachefile.length()) != 0) + auto nuke = flNotDir(*file); + if (cachefile != nuke.substr(0, cachefile.length())) continue; RemoveFile("RemoveCaches", *file); } diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc index fff10fb17..28cf3e480 100644 --- a/apt-pkg/contrib/configuration.cc +++ b/apt-pkg/contrib/configuration.cc @@ -540,7 +540,7 @@ string Configuration::FindAny(const char *Name,const char *Default) const // Configuration::CndSet - Conditional Set a value /*{{{*/ // --------------------------------------------------------------------- /* This will not overwrite */ -void Configuration::CndSet(const char *Name,const string &Value) +void Configuration::CndSet(const char *Name,const string_view &Value) { Item *Itm = Lookup(Name,true); if (Itm == 0) @@ -565,7 +565,7 @@ void Configuration::CndSet(const char *Name,int const Value) // Configuration::Set - Set a value /*{{{*/ // --------------------------------------------------------------------- /* */ -void Configuration::Set(const char *Name,const string &Value) +void Configuration::Set(const char *Name,const string_view &Value) { Item *Itm = Lookup(Name,true); if (Itm == 0) diff --git a/apt-pkg/contrib/configuration.h b/apt-pkg/contrib/configuration.h index 6ebf28d03..1c09137f6 100644 --- a/apt-pkg/contrib/configuration.h +++ b/apt-pkg/contrib/configuration.h @@ -88,13 +88,13 @@ class APT_PUBLIC Configuration bool FindB(const char *Name,bool const &Default = false) const; bool FindB(std::string const &Name,bool const &Default = false) const {return FindB(Name.c_str(),Default);}; std::string FindAny(const char *Name,const char *Default = 0) const; - - inline void Set(const std::string &Name,const std::string &Value) {Set(Name.c_str(),Value);}; - void CndSet(const char *Name,const std::string &Value); + + inline void Set(const std::string &Name,const std::string_view &Value) {Set(Name.c_str(),Value);}; + void CndSet(const char *Name,const std::string_view &Value); void CndSet(const char *Name,const int Value); - void Set(const char *Name,const std::string &Value); + void Set(const char *Name,const std::string_view &Value); void Set(const char *Name,const int &Value); - + inline bool Exists(const std::string &Name) const {return Exists(Name.c_str());}; bool Exists(const char *Name) const; bool ExistsAny(const char *Name) const; diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 1a417f7e2..ee0b7a04a 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -670,13 +670,13 @@ time_t GetModificationTime(string const &Path) // flNotDir - Strip the directory from the filename /*{{{*/ // --------------------------------------------------------------------- /* */ -string flNotDir(string File) +string_view flNotDir(string_view File) { - string::size_type Res = File.rfind('/'); - if (Res == string::npos) + string_view::size_type Res = File.rfind('/'); + if (Res == string_view::npos) return File; Res++; - return string(File,Res,Res - File.length()); + return File.substr(Res,Res - File.length()); } /*}}}*/ // flNotFile - Strip the file from the directory name /*{{{*/ diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index 52f9bc657..5d1e4ab69 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -252,7 +252,7 @@ APT_PUBLIC bool ChangeOwnerAndPermissionOfFile(char const * const requester, cha APT_PUBLIC bool DropPrivileges(); // File string manipulators -APT_PUBLIC std::string flNotDir(std::string File); +APT_PUBLIC std::string_view flNotDir(std::string_view File); APT_PUBLIC std::string flNotFile(std::string File); APT_PUBLIC std::string flNoLink(std::string File); APT_PUBLIC std::string_view flExtension(std::string_view File); diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index 306018858..fefbf45eb 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -33,6 +33,8 @@ #include #include + +using namespace std::literals; /*}}}*/ // Sources Index /*{{{*/ @@ -198,7 +200,7 @@ bool debDebPkgFileIndex::GetContent(std::ostream &content, std::string const &de bool debDebPkgFileIndex::OpenListFile(FileFd &Pkg, std::string const &FileName) { // write the control data to a tempfile - if (GetTempFile("deb-file-" + flNotDir(FileName), true, &Pkg) == NULL) + if (GetTempFile("deb-file-"s += flNotDir(FileName), true, &Pkg) == NULL) return false; std::ostringstream content; if (GetContent(content, FileName) == false) diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index cc695ceb9..09f3e4783 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -1876,7 +1876,7 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress) { if (I->File[0] != '/') return _error->Error("Internal Error, Pathname to install is not absolute '%s'",I->File.c_str()); - auto file = flNotDir(I->File); + std::string file{flNotDir(I->File)}; if (flExtension(file) != "deb") file.append(".deb"); std::string linkpath; diff --git a/apt-pkg/sourcelist.cc b/apt-pkg/sourcelist.cc index 94fe02531..b744da23a 100644 --- a/apt-pkg/sourcelist.cc +++ b/apt-pkg/sourcelist.cc @@ -36,6 +36,7 @@ /*}}}*/ using namespace std; +using namespace std::literals; // Global list of Items supported static pkgSourceList::Type *ItmList[10]; @@ -541,7 +542,7 @@ void pkgSourceList::AddVolatileFile(pkgIndexFile * const File) /*{{{*/ VolatileFiles.push_back(File); } /*}}}*/ -static bool fileNameMatches(std::string const &filename, std::string const &idxtype)/*{{{*/ +static bool fileNameMatches(std::string_view const &filename, std::string const &idxtype)/*{{{*/ { for (auto && type: APT::Configuration::getCompressionTypes()) { @@ -590,9 +591,9 @@ bool pkgSourceList::AddVolatileFile(std::string const &File, std::vectorCndSet("Binary::apt-cdrom::APT::Internal::OpProgress::EraseLines", false); @@ -522,7 +522,7 @@ static void BinarySpecificConfiguration(char const * const Binary) /*{{{*/ /*}}}*/ static void BinaryCommandSpecificConfiguration(char const * const Binary, char const * const Cmd)/*{{{*/ { - std::string const binary = flNotDir(Binary); + auto const binary = flNotDir(Binary); if ((binary == "apt" || binary == "apt-get") && CmdMatches("upgrade", "dist-upgrade", "full-upgrade")) { //FIXME: the option is documented to apply only for install/remove, so diff --git a/apt-private/private-download.cc b/apt-private/private-download.cc index 338ffae9b..e3d425283 100644 --- a/apt-private/private-download.cc +++ b/apt-private/private-download.cc @@ -197,7 +197,8 @@ bool DoDownload(CommandLine &CmdL) pkgAcquire::Item *I = new pkgAcqArchive(&Fetcher, SrcList, &Recs, *Ver, storefile[i]); if (storefile[i].empty()) continue; - std::string const filename = cwd + flNotDir(storefile[i]); + auto filename = cwd; + filename += flNotDir(storefile[i]); storefile[i].assign(filename); I->DestFile.assign(filename); } diff --git a/apt-private/private-source.cc b/apt-private/private-source.cc index 6280b9fff..ac52de9e9 100644 --- a/apt-private/private-source.cc +++ b/apt-private/private-source.cc @@ -423,7 +423,7 @@ bool DoSource(CommandLine &CmdL) queued.insert(Last->Index().ArchiveURI(I->Path)); // check if we have a file with that md5 sum already localy - std::string localFile = flNotDir(I->Path); + std::string localFile{flNotDir(I->Path)}; if (FileExists(localFile) == true) if(I->Hashes.VerifyFile(localFile) == true) { diff --git a/apt-private/private-sources.cc b/apt-private/private-sources.cc index b887efca5..9e6deb1ce 100644 --- a/apt-private/private-sources.cc +++ b/apt-private/private-sources.cc @@ -24,7 +24,7 @@ #include -using std::operator""sv; +using namespace std::literals; /* Interface discussion with donkult (for the future): apt [add-{archive,release,component}|edit|change-release|disable]-sources @@ -192,9 +192,9 @@ static bool Modernize(std::string const &filename) /*{{{*/ if (FileExists(dir + keyring)) e.signedBy = dir + keyring; } - if (auto k = _config->FindDir("Dir::Etc::trustedparts") + flNotDir(std::regex_replace(filename, std::regex("\\.list$"), ".gpg")); FileExists(k)) + if (auto k = _config->FindDir("Dir::Etc::trustedparts") += flNotDir(std::regex_replace(filename, std::regex("\\.list$"), ".gpg")); FileExists(k)) e.signedBy = k; - if (auto k = _config->FindDir("Dir::Etc::trustedparts") + flNotDir(std::regex_replace(filename, std::regex("\\.list$"), ".asc")); FileExists(k)) + if (auto k = _config->FindDir("Dir::Etc::trustedparts") += flNotDir(std::regex_replace(filename, std::regex("\\.list$"), ".asc")); FileExists(k)) e.signedBy = k; if (isMain && not meta->GetOrigin().empty()) diff --git a/apt-private/private-update.cc b/apt-private/private-update.cc index bd8823568..98961966e 100644 --- a/apt-private/private-update.cc +++ b/apt-private/private-update.cc @@ -58,7 +58,7 @@ bool DoUpdate() pkgAcquire::UriIterator I = Fetcher.UriBegin(); for (; I != Fetcher.UriEnd(); ++I) { - std::string FileName = flNotDir(I->Owner->DestFile); + auto FileName = flNotDir(I->Owner->DestFile); if(compExt.empty() == false && APT::String::Endswith(FileName, compExt)) FileName = FileName.substr(0, FileName.size() - compExt.size() - 1); diff --git a/ftparchive/writer.cc b/ftparchive/writer.cc index 3c5237915..78852e772 100644 --- a/ftparchive/writer.cc +++ b/ftparchive/writer.cc @@ -611,12 +611,12 @@ 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, pkgTagSection::Key const FieldKey, - HashString const * const Hash, unsigned long long Size, std::string const &FileName) + HashString const * const Hash, unsigned long long Size, std::string_view const &FileName) { if ((DoHashes & DoIt) != DoIt || not Tags.Exists(FieldKey) || Hash == nullptr) return ""; std::ostringstream out; - out << "\n " << Hash->HashValue() << " " << std::to_string(Size) << " " << FileName + out << "\n " << Hash->HashValue() << " " << Size << " " << FileName << "\n " << Tags.Find(FieldKey); return out.str(); } @@ -713,7 +713,7 @@ bool SourcesWriter::DoPackage(string FileName) } // Add the dsc to the files hash list - string const strippedName = flNotDir(FileName); + auto const strippedName = flNotDir(FileName); 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); diff --git a/methods/http.cc b/methods/http.cc index f2514eb9d..a6d7511fd 100644 --- a/methods/http.cc +++ b/methods/http.cc @@ -1045,7 +1045,7 @@ int main(int, const char *argv[]) // ignore SIGPIPE, this can happen on write() if the socket // closes the connection (this is dealt with via ServerDie()) signal(SIGPIPE, SIG_IGN); - std::string Binary = flNotDir(argv[0]); + std::string Binary{flNotDir(argv[0])}; if (Binary.find('+') == std::string::npos && Binary != "https" && Binary != "http") Binary.append("+http"); return HttpMethod(std::move(Binary)).Loop(); diff --git a/methods/mirror.cc b/methods/mirror.cc index dfdd550b7..6da0b4258 100644 --- a/methods/mirror.cc +++ b/methods/mirror.cc @@ -97,7 +97,7 @@ class MirrorMethod : public aptMethod /*{{{*/ void DealWithPendingItems(std::vector const &baseuris, MirrorListInfo const &info, FetchItem *Itm, std::function handler); public: - explicit MirrorMethod(std::string &&pProg) : aptMethod(std::move(pProg), "2.0", SingleInstance | Pipeline | SendConfig | AuxRequests | SendURIEncoded), genrng(clock()) + explicit MirrorMethod(std::string pProg) : aptMethod(std::move(pProg), "2.0", SingleInstance | Pipeline | SendConfig | AuxRequests | SendURIEncoded), genrng(clock()) { SeccompFlags = aptMethod::BASE | aptMethod::DIRECTORY; } @@ -417,5 +417,5 @@ bool MirrorMethod::URIAcquire(std::string const &Message, FetchItem *Itm) /*{{{* int main(int, const char *argv[]) { - return MirrorMethod(flNotDir(argv[0])).Run(); + return MirrorMethod(std::string{flNotDir(argv[0])}).Run(); } diff --git a/methods/store.cc b/methods/store.cc index bfd748e23..14fadabac 100644 --- a/methods/store.cc +++ b/methods/store.cc @@ -37,7 +37,7 @@ class StoreMethod final : public aptMethod public: - explicit StoreMethod(std::string &&pProg) : aptMethod(std::move(pProg),"1.2",SingleInstance | SendConfig | SendURIEncoded) + explicit StoreMethod(std::string pProg) : aptMethod(std::move(pProg),"1.2",SingleInstance | SendConfig | SendURIEncoded) { SeccompFlags = aptMethod::BASE; if (Binary != "store") @@ -144,5 +144,5 @@ bool StoreMethod::Fetch(FetchItem *Itm) /*{{{*/ int main(int, char *argv[]) { - return StoreMethod(flNotDir(argv[0])).Run(); + return StoreMethod(std::string{flNotDir(argv[0])}).Run(); } diff --git a/test/interactive-helper/aptwebserver.cc b/test/interactive-helper/aptwebserver.cc index a2637c668..e9882abd0 100644 --- a/test/interactive-helper/aptwebserver.cc +++ b/test/interactive-helper/aptwebserver.cc @@ -755,7 +755,7 @@ static void * handleClient(int const client, size_t const id) /*{{{*/ } if (regexec(pattern, filename.c_str(), 0, 0, 0) == 0) { - filename = _config->Find("aptwebserver::overwrite::" + I->Tag + "::filename", flNotDir(filename)); + filename = _config->Find("aptwebserver::overwrite::" + I->Tag + "::filename", std::string{flNotDir(filename)}); if (filename.find("/") == std::string::npos) { auto directory = _config->Find("aptwebserver::overwrite::" + I->Tag + "::directory", flNotFile(filename)); -- cgit v1.2.3-70-g09d2