diff options
| author | наб <nabijaczleweli@nabijaczleweli.xyz> | 2025-01-23 20:50:39 +0100 |
|---|---|---|
| committer | Julian Andres Klode <julian.klode@canonical.com> | 2025-02-14 19:45:12 +0100 |
| commit | 729a5c8f4fb8c841497d26170e1a47c41617ecd9 (patch) | |
| tree | 3d9e97b68a2a9706ce7295e0b056a053449b39cc /apt-pkg | |
| parent | 384cfa1fe9dfd30b35d6f8b0ae87be643ab75d06 (diff) | |
string{=> _view} flNotDir(string{=> _view}). Configuration::{Cnd,}Set(Value: string{=> _view})
Diffstat (limited to 'apt-pkg')
| -rw-r--r-- | apt-pkg/acquire-item.cc | 14 | ||||
| -rw-r--r-- | apt-pkg/cachefile.cc | 12 | ||||
| -rw-r--r-- | apt-pkg/contrib/configuration.cc | 4 | ||||
| -rw-r--r-- | apt-pkg/contrib/configuration.h | 10 | ||||
| -rw-r--r-- | apt-pkg/contrib/fileutl.cc | 8 | ||||
| -rw-r--r-- | apt-pkg/contrib/fileutl.h | 2 | ||||
| -rw-r--r-- | apt-pkg/deb/debindexfile.cc | 4 | ||||
| -rw-r--r-- | apt-pkg/deb/dpkgpm.cc | 2 | ||||
| -rw-r--r-- | apt-pkg/sourcelist.cc | 7 |
9 files changed, 33 insertions, 30 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<std::string> caches = GetListOfFilesInDir(cachedir, false); for (std::vector<std::string>::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<std::string> caches = GetListOfFilesInDir(cachedir, false); for (std::vector<std::string>::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 <sys/stat.h> #include <unistd.h> + +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::vector<std::st else { auto const filename = flNotDir(File); - auto const Target = IndexTarget(File, filename, File, "file:" + File, false, true, { + auto const Target = IndexTarget(File, std::string{filename}, File, "file:" + File, false, true, { { "FILENAME", File }, - { "REPO_URI", "file:" + flAbsPath(flNotFile(File)) + '/' }, + { "REPO_URI", ("file:"s += flAbsPath(flNotFile(File))) += '/' }, { "COMPONENT", "volatile-packages-file" }, }); if (fileNameMatches(filename, "Packages")) |
