From b0f4b486e6850c5f98520ccf19da71d0ed748ae4 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Sun, 21 Sep 2014 10:18:03 +0200 Subject: generalize Acquire::GzipIndex --- apt-pkg/acquire-item.cc | 44 +++++++++++++++++++++------------ apt-pkg/deb/debindexfile.cc | 60 ++++++++++++++++++++++++++++----------------- 2 files changed, 67 insertions(+), 37 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index 5df43726b..da57f8d3b 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -969,8 +969,10 @@ void pkgAcqIndex::Init(string const &URI, string const &URIDesc, string const &S std::string const comprExt = CompressionExtension.substr(0, CompressionExtension.find(' ')); if (comprExt == "uncompressed") Desc.URI = URI; - else + else { Desc.URI = URI + '.' + comprExt; + DestFile = DestFile + '.' + comprExt; + } Desc.Description = URIDesc; Desc.Owner = this; @@ -984,10 +986,11 @@ void pkgAcqIndex::Init(string const &URI, string const &URIDesc, string const &S /* The only header we use is the last-modified header. */ string pkgAcqIndex::Custom600Headers() { + std::string const compExt = CompressionExtension.substr(0, CompressionExtension.find(' ')); string Final = _config->FindDir("Dir::State::lists"); Final += URItoFileName(RealURI); if (_config->FindB("Acquire::GzipIndexes",false)) - Final += ".gz"; + Final += compExt; string msg = "\nIndex-File: true"; // FIXME: this really should use "IndexTarget::IsOptional()" but that @@ -1027,8 +1030,8 @@ std::string pkgAcqIndex::GetFinalFilename(std::string const &URI, { std::string FinalFile = _config->FindDir("Dir::State::lists"); FinalFile += URItoFileName(URI); - if (_config->FindB("Acquire::GzipIndexes",false) && compExt == "gz") - FinalFile += ".gz"; + if (_config->FindB("Acquire::GzipIndexes",false) == true) + FinalFile += '.' + compExt; return FinalFile; } /*}}}*/ @@ -1036,8 +1039,8 @@ std::string pkgAcqIndex::GetFinalFilename(std::string const &URI, void pkgAcqIndex::ReverifyAfterIMS(std::string const &FileName) { std::string const compExt = CompressionExtension.substr(0, CompressionExtension.find(' ')); - if (_config->FindB("Acquire::GzipIndexes",false) && compExt == "gz") - DestFile += ".gz"; + if (_config->FindB("Acquire::GzipIndexes",false) == true) + DestFile += compExt; string FinalFile = GetFinalFilename(RealURI, compExt); Rename(FinalFile, FileName); @@ -1080,7 +1083,7 @@ void pkgAcqIndex::Done(string Message,unsigned long long Size,string Hash, /* Always verify the index file for correctness (all indexes must * have a Package field) (LP: #346386) (Closes: #627642) */ - FileFd fd(DestFile, FileFd::ReadOnlyGzip); + FileFd fd(DestFile, FileFd::ReadOnly, FileFd::Extension); // Only test for correctness if the file is not empty (empty is ok) if (fd.Size() > 0) { @@ -1104,8 +1107,8 @@ void pkgAcqIndex::Done(string Message,unsigned long long Size,string Hash, will work OK */ DestFile = _config->FindDir("Dir::State::lists") + "partial/"; DestFile += URItoFileName(RealURI); - if (_config->FindB("Acquire::GzipIndexes",false) && compExt == "gz") - DestFile += ".gz"; + if (_config->FindB("Acquire::GzipIndexes",false)) + DestFile += '.' + compExt; // Remove the compressed version. if (Erase == true) @@ -1146,16 +1149,23 @@ void pkgAcqIndex::Done(string Message,unsigned long long Size,string Hash, // matching the Release file if (!Local && StringToBool(LookupTag(Message,"IMS-Hit"),false) == true) { + // set destfile to the final destfile + if(_config->FindB("Acquire::GzipIndexes",false) == false) + { + DestFile = _config->FindDir("Dir::State::lists") + "partial/"; + DestFile += URItoFileName(RealURI); + } + ReverifyAfterIMS(FileName); return; } string decompProg; // If we enable compressed indexes, queue for hash verification - if (_config->FindB("Acquire::GzipIndexes",false) && compExt == "gz" && !Local) + if (_config->FindB("Acquire::GzipIndexes",false)) { DestFile = _config->FindDir("Dir::State::lists"); - DestFile += URItoFileName(RealURI) + ".gz"; + DestFile += URItoFileName(RealURI) + '.' + compExt; Decompression = true; Desc.URI = "copy:" + FileName; @@ -1201,11 +1211,11 @@ pkgAcqIndexTrans::pkgAcqIndexTrans(pkgAcquire *Owner, IndexTarget const *Target, // --------------------------------------------------------------------- string pkgAcqIndexTrans::Custom600Headers() { + std::string const compExt = CompressionExtension.substr(0, CompressionExtension.find(' ')); string Final = _config->FindDir("Dir::State::lists"); Final += URItoFileName(RealURI); - if (_config->FindB("Acquire::GzipIndexes",false)) - Final += ".gz"; + Final += compExt; struct stat Buf; if (stat(Final.c_str(),&Buf) != 0) @@ -1552,8 +1562,12 @@ void pkgAcqMetaIndex::AuthDone(string Message) /*{{{*/ URItoFileName((*Target)->URI); unlink(index.c_str()); // and also old gzipindexes - index += ".gz"; - unlink(index.c_str()); + std::vector types = APT::Configuration::getCompressionTypes(); + for (std::vector::const_iterator t = types.begin(); t != types.end(); ++t) + { + index += '.' + (*t); + unlink(index.c_str()); + } } } diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index a0dd15cd8..5b4289e92 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -80,14 +80,18 @@ pkgSrcRecords::Parser *debSourcesIndex::CreateSrcParser() const { string SourcesURI = _config->FindDir("Dir::State::lists") + URItoFileName(IndexURI("Sources")); - string SourcesURIgzip = SourcesURI + ".gz"; - if (!FileExists(SourcesURI) && !FileExists(SourcesURIgzip)) - return NULL; - else if (!FileExists(SourcesURI) && FileExists(SourcesURIgzip)) - SourcesURI = SourcesURIgzip; - - return new debSrcRecordParser(SourcesURI,this); + std::vector types = APT::Configuration::getCompressionTypes(); + for (std::vector::const_iterator t = types.begin(); t != types.end(); ++t) + { + string p; + p = SourcesURI + '.' + *t; + if (FileExists(p)) + return new debSrcRecordParser(p, this); + } + if (FileExists(SourcesURI)) + return new debSrcRecordParser(SourcesURI, this); + return NULL; } /*}}}*/ // SourcesIndex::Describe - Give a descriptive path to the index /*{{{*/ @@ -129,11 +133,15 @@ string debSourcesIndex::Info(const char *Type) const inline string debSourcesIndex::IndexFile(const char *Type) const { string s = URItoFileName(IndexURI(Type)); - string sgzip = s + ".gz"; - if (!FileExists(s) && FileExists(sgzip)) - return sgzip; - else - return s; + + std::vector types = APT::Configuration::getCompressionTypes(); + for (std::vector::const_iterator t = types.begin(); t != types.end(); ++t) + { + string p = s + '.' + *t; + if (FileExists(p)) + return p; + } + return s; } string debSourcesIndex::IndexURI(const char *Type) const @@ -259,11 +267,15 @@ string debPackagesIndex::Info(const char *Type) const inline string debPackagesIndex::IndexFile(const char *Type) const { string s =_config->FindDir("Dir::State::lists") + URItoFileName(IndexURI(Type)); - string sgzip = s + ".gz"; - if (!FileExists(s) && FileExists(sgzip)) - return sgzip; - else - return s; + + std::vector types = APT::Configuration::getCompressionTypes(); + for (std::vector::const_iterator t = types.begin(); t != types.end(); ++t) + { + string p = s + '.' + *t; + if (FileExists(p)) + return p; + } + return s; } string debPackagesIndex::IndexURI(const char *Type) const { @@ -411,11 +423,15 @@ debTranslationsIndex::debTranslationsIndex(string URI,string Dist,string Section inline string debTranslationsIndex::IndexFile(const char *Type) const { string s =_config->FindDir("Dir::State::lists") + URItoFileName(IndexURI(Type)); - string sgzip = s + ".gz"; - if (!FileExists(s) && FileExists(sgzip)) - return sgzip; - else - return s; + + std::vector types = APT::Configuration::getCompressionTypes(); + for (std::vector::const_iterator t = types.begin(); t != types.end(); ++t) + { + string p = s + '.' + *t; + if (FileExists(p)) + return p; + } + return s; } string debTranslationsIndex::IndexURI(const char *Type) const { -- cgit v1.2.3 From ca15786a9ae637048e329c159831dd486c54dea7 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 25 Sep 2014 11:49:16 +0200 Subject: Revert making pkgAcquire::Item::DescURI() "const" Revert because its a API change and the gain does not justify the extra work to make the required changes in the consumers of this interface at this point. --- apt-pkg/acquire-item.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-item.h b/apt-pkg/acquire-item.h index c027a2764..d0a61f5ec 100644 --- a/apt-pkg/acquire-item.h +++ b/apt-pkg/acquire-item.h @@ -245,12 +245,12 @@ class pkgAcquire::Item : public WeakPointable * * \return a URI that should be used to describe what is being fetched. */ - virtual std::string DescURI() const = 0; + virtual std::string DescURI() = 0; /** \brief Short item description. * * \return a brief description of the object being fetched. */ - virtual std::string ShortDesc() const {return DescURI();} + virtual std::string ShortDesc() {return DescURI();} /** \brief Invoked by the worker when the download is completely done. */ virtual void Finished() {}; @@ -347,7 +347,7 @@ class pkgAcqSubIndex : public pkgAcquire::Item virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf); virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes, pkgAcquire::MethodConfig *Cnf); - virtual std::string DescURI() const {return Desc.URI;}; + virtual std::string DescURI() {return Desc.URI;}; virtual std::string Custom600Headers() const; virtual bool ParseIndex(std::string const &IndexFile); @@ -423,7 +423,7 @@ class pkgAcqDiffIndex : public pkgAcqBaseIndex virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf); virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes, pkgAcquire::MethodConfig *Cnf); - virtual std::string DescURI() const {return RealURI + "Index";}; + virtual std::string DescURI() {return RealURI + "Index";}; virtual std::string Custom600Headers() const; /** \brief Parse the Index file for a set of Packages diffs. @@ -516,7 +516,7 @@ class pkgAcqIndexMergeDiffs : public pkgAcqBaseIndex virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf); virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes, pkgAcquire::MethodConfig *Cnf); - virtual std::string DescURI() const {return RealURI + "Index";}; + virtual std::string DescURI() {return RealURI + "Index";}; /** \brief Create an index merge-diff item. * @@ -641,7 +641,7 @@ class pkgAcqIndexDiffs : public pkgAcqBaseIndex virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes, pkgAcquire::MethodConfig *Cnf); - virtual std::string DescURI() const {return RealURI + "Index";}; + virtual std::string DescURI() {return RealURI + "Index";}; /** \brief Create an index diff item. * @@ -726,7 +726,7 @@ class pkgAcqIndex : public pkgAcqBaseIndex virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes, pkgAcquire::MethodConfig *Cnf); virtual std::string Custom600Headers() const; - virtual std::string DescURI() const {return Desc.URI;}; + virtual std::string DescURI() {return Desc.URI;}; /** \brief Create a pkgAcqIndex. * @@ -890,7 +890,7 @@ class pkgAcqMetaSig : public pkgAcquire::Item virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes, pkgAcquire::MethodConfig *Cnf); virtual std::string Custom600Headers() const; - virtual std::string DescURI() const {return RealURI; }; + virtual std::string DescURI() {return RealURI; }; /** \brief Create a new pkgAcqMetaSig. */ pkgAcqMetaSig(pkgAcquire *Owner,std::string URI,std::string URIDesc, std::string ShortDesc, @@ -983,7 +983,7 @@ class pkgAcqMetaIndex : public pkgAcquire::Item virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes, pkgAcquire::MethodConfig *Cnf); virtual std::string Custom600Headers() const; - virtual std::string DescURI() const {return RealURI; }; + virtual std::string DescURI() {return RealURI; }; /** \brief Create a new pkgAcqMetaIndex. */ pkgAcqMetaIndex(pkgAcquire *Owner, @@ -1077,8 +1077,8 @@ class pkgAcqArchive : public pkgAcquire::Item virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf); virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes, pkgAcquire::MethodConfig *Cnf); - virtual std::string DescURI() const {return Desc.URI;}; - virtual std::string ShortDesc() const {return Desc.ShortDesc;}; + virtual std::string DescURI() {return Desc.URI;}; + virtual std::string ShortDesc() {return Desc.ShortDesc;}; virtual void Finished(); virtual bool IsTrusted() const; @@ -1127,7 +1127,7 @@ class pkgAcqFile : public pkgAcquire::Item virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf); virtual void Done(std::string Message,unsigned long long Size, HashStringList const &CalcHashes, pkgAcquire::MethodConfig *Cnf); - virtual std::string DescURI() const {return Desc.URI;}; + virtual std::string DescURI() {return Desc.URI;}; virtual std::string Custom600Headers() const; /** \brief Create a new pkgAcqFile object. -- cgit v1.2.3 From 13a72218012a5f862f691f1016c9c147972ee8ec Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 25 Sep 2014 12:26:22 +0200 Subject: Remove check for "Translation-" from pkgAcqIndex::Custom600Headers() This unneeded because pkgAcqIndexTrans has its own Custom600Headers() method. --- apt-pkg/acquire-item.cc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index 7ad6a794e..a3e02cb53 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -1063,10 +1063,7 @@ string pkgAcqIndex::Custom600Headers() const Final += ".gz"; string msg = "\nIndex-File: true"; - // FIXME: this really should use "IndexTarget::IsOptional()" but that - // seems to be difficult without breaking ABI - if (ShortDesc().find("Translation") != 0) - msg += "\nFail-Ignore: true"; + struct stat Buf; if (stat(Final.c_str(),&Buf) == 0) msg += "\nLast-Modified: " + TimeRFC1123(Buf.st_mtime); -- cgit v1.2.3 From fe86debbae914b51d2799e7b24abfd1f944f8caf Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 19 Jun 2014 11:00:02 +0200 Subject: deprecate Pkg->Name in favor of Grp->Name They both store the same information, so this field just takes up space in the Package struct for no good reason. We mark it "just" as deprecated instead of instantly removing it though as it isn't misleading like Section was and is potentially used in the wild more often. --- apt-pkg/cacheiterators.h | 4 ++-- apt-pkg/pkgcache.cc | 9 +++------ apt-pkg/pkgcache.h | 7 +++++-- apt-pkg/pkgcachegen.cc | 9 ++++++++- 4 files changed, 18 insertions(+), 11 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h index f2aae7272..12a03eb07 100644 --- a/apt-pkg/cacheiterators.h +++ b/apt-pkg/cacheiterators.h @@ -159,7 +159,7 @@ class pkgCache::PkgIterator: public Iterator { enum OkState {NeedsNothing,NeedsUnpack,NeedsConfigure}; // Accessors - inline const char *Name() const {return S->Name == 0?0:Owner->StrP + S->Name;} + inline const char *Name() const { return Group().Name(); } // Versions have sections - and packages can have different versions with different sections // so this interface is broken by design. It used to return the section of the "first parsed // package stanza", but as this can potentially be anything it now returns the section of the @@ -336,7 +336,7 @@ class pkgCache::PrvIterator : public Iterator { inline void operator ++() {operator ++(0);} // Accessors - inline const char *Name() const {return Owner->StrP + Owner->PkgP[S->ParentPkg].Name;} + inline const char *Name() const {return ParentPkg().Name();} inline const char *ProvideVersion() const {return S->ProvideVersion == 0?0:Owner->StrP + S->ProvideVersion;} inline PkgIterator ParentPkg() const {return PkgIterator(*Owner,Owner->PkgP + S->ParentPkg);} inline VerIterator OwnerVer() const {return VerIterator(*Owner,Owner->VerP + S->Version);} diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index b1ed0129d..7a913d2bb 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -215,10 +215,7 @@ pkgCache::PkgIterator pkgCache::SingleArchFindPkg(const string &Name) Package *Pkg = PkgP + HeaderP->PkgHashTable()[Hash(Name)]; for (; Pkg != PkgP; Pkg = PkgP + Pkg->Next) { - if (unlikely(Pkg->Name == 0)) - continue; - - int const cmp = strcasecmp(Name.c_str(), StrP + Pkg->Name); + int const cmp = strcasecmp(Name.c_str(), StrP + (GrpP + Pkg->Group)->Name); if (cmp == 0) return PkgIterator(*this, Pkg); else if (cmp < 0) @@ -370,7 +367,7 @@ pkgCache::PkgIterator pkgCache::GrpIterator::FindPkg(string Arch) const { so we need to check the name also */ for (pkgCache::Package *Pkg = PackageList(); Pkg != Owner->PkgP; Pkg = Owner->PkgP + Pkg->Next) { - if (S->Name == Pkg->Name && + if (S->Name == (Owner->GrpP + Pkg->Group)->Name && stringcasecmp(Arch, Owner->StrP + Pkg->Arch) == 0) return PkgIterator(*Owner, Pkg); if ((Owner->PkgP + S->LastPackage) == Pkg) @@ -1037,7 +1034,7 @@ bool pkgCache::PrvIterator::IsMultiArchImplicit() const { pkgCache::PkgIterator const Owner = OwnerPkg(); pkgCache::PkgIterator const Parent = ParentPkg(); - if (strcmp(Owner.Arch(), Parent.Arch()) != 0 || Owner->Name == Parent->Name) + if (strcmp(Owner.Arch(), Parent.Arch()) != 0 || Owner.Group()->Name == Parent.Group()->Name) return true; return false; } diff --git a/apt-pkg/pkgcache.h b/apt-pkg/pkgcache.h index 0ce2a2878..8179e05aa 100644 --- a/apt-pkg/pkgcache.h +++ b/apt-pkg/pkgcache.h @@ -376,8 +376,11 @@ struct pkgCache::Group */ struct pkgCache::Package { - /** \brief Name of the package */ - map_stringitem_t Name; + /** \brief Name of the package + * Note that the access method Name() will remain. It is just this data member + * deprecated as this information is already stored and available via the + * associated Group – so it is wasting precious binary cache space */ + APT_DEPRECATED map_stringitem_t Name; /** \brief Architecture of the package */ map_stringitem_t Arch; /** \brief Base of a singly linked list of versions diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index a4d5d8783..359dffc9d 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -660,7 +660,7 @@ bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,const string &Name // Insert it into the hash table map_id_t const Hash = Cache.Hash(Name); map_pointer_t *insertAt = &Cache.HeaderP->PkgHashTable()[Hash]; - while (*insertAt != 0 && strcasecmp(Name.c_str(), Cache.StrP + (Cache.PkgP + *insertAt)->Name) > 0) + while (*insertAt != 0 && strcasecmp(Name.c_str(), Cache.StrP + (Cache.GrpP + (Cache.PkgP + *insertAt)->Group)->Name) > 0) insertAt = &(Cache.PkgP + *insertAt)->Next; Pkg->Next = *insertAt; *insertAt = Package; @@ -675,7 +675,14 @@ bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,const string &Name Grp->LastPackage = Package; // Set the name, arch and the ID +#if __GNUC__ >= 4 + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif Pkg->Name = Grp->Name; +#if __GNUC__ >= 4 + #pragma GCC diagnostic pop +#endif Pkg->Group = Grp.Index(); // all is mapped to the native architecture map_stringitem_t const idxArch = (Arch == "all") ? Cache.HeaderP->Architecture : WriteUniqString(Arch.c_str()); -- cgit v1.2.3 From b59325e85b77f8d1b12a558915a8fd646f193e74 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 19 Jun 2014 11:59:41 +0200 Subject: search for pkg names in the cache case-sensitive MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Package names have to be lowercase (debian-policy §5.6.1) and in as lowlevel as these method are it would be quiet strange to treat an invalid package "suddently" as a valid one which other tools might or might not accept. If case-insensitivity is really needed the frontend should ensure this rather than these methods waste cpu cycles by default. Git-Dch: Ignore --- apt-pkg/pkgcache.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index 7a913d2bb..467d15eae 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -215,7 +215,7 @@ pkgCache::PkgIterator pkgCache::SingleArchFindPkg(const string &Name) Package *Pkg = PkgP + HeaderP->PkgHashTable()[Hash(Name)]; for (; Pkg != PkgP; Pkg = PkgP + Pkg->Next) { - int const cmp = strcasecmp(Name.c_str(), StrP + (GrpP + Pkg->Group)->Name); + int const cmp = strcmp(Name.c_str(), StrP + (GrpP + Pkg->Group)->Name); if (cmp == 0) return PkgIterator(*this, Pkg); else if (cmp < 0) @@ -279,7 +279,7 @@ pkgCache::GrpIterator pkgCache::FindGrp(const string &Name) { if (unlikely(Grp->Name == 0)) continue; - int const cmp = strcasecmp(Name.c_str(), StrP + Grp->Name); + int const cmp = strcmp(Name.c_str(), StrP + Grp->Name); if (cmp == 0) return GrpIterator(*this, Grp); else if (cmp < 0) @@ -356,7 +356,7 @@ pkgCache::PkgIterator pkgCache::GrpIterator::FindPkg(string Arch) const { last one we check, so we do it now. */ if (Arch == "native" || Arch == myArch || Arch == "all") { pkgCache::Package *Pkg = Owner->PkgP + S->LastPackage; - if (strcasecmp(myArch, Owner->StrP + Pkg->Arch) == 0) + if (strcmp(myArch, Owner->StrP + Pkg->Arch) == 0) return PkgIterator(*Owner, Pkg); Arch = myArch; } @@ -368,7 +368,7 @@ pkgCache::PkgIterator pkgCache::GrpIterator::FindPkg(string Arch) const { for (pkgCache::Package *Pkg = PackageList(); Pkg != Owner->PkgP; Pkg = Owner->PkgP + Pkg->Next) { if (S->Name == (Owner->GrpP + Pkg->Group)->Name && - stringcasecmp(Arch, Owner->StrP + Pkg->Arch) == 0) + stringcmp(Arch, Owner->StrP + Pkg->Arch) == 0) return PkgIterator(*Owner, Pkg); if ((Owner->PkgP + S->LastPackage) == Pkg) break; -- cgit v1.2.3 From 5d1e330d8b3f7ef2daf54d7701a83919b9582f38 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 19 Jun 2014 12:23:10 +0200 Subject: packages in the cache are sorted by name so noise-free Commit aa0fe657e46b87cc692895a36df12e8b74bb27bb sorts the package names in the hashtable. We make use of this already in these functions, but as a minor sideeffect it also means that we don't have 'noise' anymore between packages belonging to the same group. We therefore don't need to check for a matching name in Grp.FindPkg anymore. Git-Dch: Ignore --- apt-pkg/pkgcache.cc | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index 467d15eae..4b4631a65 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -276,9 +276,6 @@ pkgCache::GrpIterator pkgCache::FindGrp(const string &Name) { // Look at the hash bucket for the group Group *Grp = GrpP + HeaderP->GrpHashTable()[sHash(Name)]; for (; Grp != GrpP; Grp = GrpP + Grp->Next) { - if (unlikely(Grp->Name == 0)) - continue; - int const cmp = strcmp(Name.c_str(), StrP + Grp->Name); if (cmp == 0) return GrpIterator(*this, Grp); @@ -361,14 +358,10 @@ pkgCache::PkgIterator pkgCache::GrpIterator::FindPkg(string Arch) const { Arch = myArch; } - /* Iterate over the list to find the matching arch - unfortunately this list includes "package noise" - (= different packages with same calculated hash), - so we need to check the name also */ + // Iterate over the list to find the matching arch for (pkgCache::Package *Pkg = PackageList(); Pkg != Owner->PkgP; Pkg = Owner->PkgP + Pkg->Next) { - if (S->Name == (Owner->GrpP + Pkg->Group)->Name && - stringcmp(Arch, Owner->StrP + Pkg->Arch) == 0) + if (stringcmp(Arch, Owner->StrP + Pkg->Arch) == 0) return PkgIterator(*Owner, Pkg); if ((Owner->PkgP + S->LastPackage) == Pkg) break; -- cgit v1.2.3 From 78a5476f3177a2a74ae51a1878c26ca322a25003 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 20 Jun 2014 21:33:56 +0200 Subject: drop stored StringItems in favor of in-memory mappings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Strings like Section names or architectures are needed vary often. Instead of writing them each time we need them, we deploy sharing for these special strings. Until now, this was done with a linked list of strings in which we would search, which was stored in the cache. It turns out we can do this just as well in memory as well with a bunch of std::map's. In memory means here that it isn't available anymore if we have a partly invalid cache, but that isn't much of a problem in practice as the status file is compared to the other files we parse very small and includes mostly duplicates, so the space we would gain by storing is more or less equal to the size of the stored linked list… --- apt-pkg/deb/debindexfile.cc | 2 +- apt-pkg/deb/deblistparser.cc | 45 ++++++++++-------------- apt-pkg/deb/deblistparser.h | 1 - apt-pkg/edsp/edspindexfile.cc | 2 +- apt-pkg/pkgcache.cc | 2 -- apt-pkg/pkgcache.h | 30 ++-------------- apt-pkg/pkgcachegen.cc | 81 ++++++++++++------------------------------- apt-pkg/pkgcachegen.h | 18 ++++++---- 8 files changed, 57 insertions(+), 124 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index feda8d0d8..c35a89ade 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -619,7 +619,7 @@ bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const pkgCache::PkgFileIterator CFile = Gen.GetCurFile(); CFile->Size = Pkg.FileSize(); CFile->mtime = Pkg.ModificationTime(); - map_stringitem_t const storage = Gen.WriteUniqString("now"); + map_stringitem_t const storage = Gen.StoreString(pkgCacheGenerator::MIXED, "now"); CFile->Archive = storage; if (Gen.MergeList(Parser) == false) diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index 3e0d3a791..9919d2036 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -58,18 +58,6 @@ debListParser::debListParser(FileFd *File, string const &Arch) : Tags(File), MultiArchEnabled = Architectures.size() > 1; } /*}}}*/ -// ListParser::UniqFindTagWrite - Find the tag and write a unq string /*{{{*/ -// --------------------------------------------------------------------- -/* */ -map_stringitem_t debListParser::UniqFindTagWrite(const char *Tag) -{ - const char *Start; - const char *Stop; - if (Section.Find(Tag,Start,Stop) == false) - return 0; - return WriteUniqString(Start,Stop - Start); -} - /*}}}*/ // ListParser::Package - Return the package name /*{{{*/ // --------------------------------------------------------------------- /* This is to return the name of the package this section describes */ @@ -144,9 +132,16 @@ unsigned char debListParser::ParseMultiArch(bool const showErrors) /*{{{*/ /* */ bool debListParser::NewVersion(pkgCache::VerIterator &Ver) { + const char *Start; + const char *Stop; + // Parse the section - unsigned long const idxSection = UniqFindTagWrite("Section"); - Ver->Section = idxSection; + if (Section.Find("Section",Start,Stop) == true) + { + map_stringitem_t const idx = StoreString(pkgCacheGenerator::SECTION, Start, Stop - Start); + Ver->Section = idx; + } + Ver->MultiArch = ParseMultiArch(true); // Archive Size Ver->Size = Section.FindULL("Size"); @@ -155,10 +150,8 @@ bool debListParser::NewVersion(pkgCache::VerIterator &Ver) Ver->InstalledSize *= 1024; // Priority - const char *Start; - const char *Stop; if (Section.Find("Priority",Start,Stop) == true) - { + { if (GrabWord(string(Start,Stop-Start),PrioList,Ver->Priority) == false) Ver->Priority = pkgCache::State::Extra; } @@ -891,7 +884,7 @@ bool debListParser::LoadReleaseInfo(pkgCache::PkgFileIterator &FileI, { // apt-secure does no longer download individual (per-section) Release // file. to provide Component pinning we use the section name now - map_stringitem_t const storage = WriteUniqString(component); + map_stringitem_t const storage = StoreString(pkgCacheGenerator::MIXED, component); FileI->Component = storage; pkgTagFile TagFile(&File, File.Size()); @@ -900,19 +893,19 @@ bool debListParser::LoadReleaseInfo(pkgCache::PkgFileIterator &FileI, return false; std::string data; - #define APT_INRELEASE(TAG, STORE) \ + #define APT_INRELEASE(TYPE, TAG, STORE) \ data = Section.FindS(TAG); \ if (data.empty() == false) \ { \ - map_stringitem_t const storage = WriteUniqString(data); \ + map_stringitem_t const storage = StoreString(pkgCacheGenerator::TYPE, data); \ STORE = storage; \ } - APT_INRELEASE("Suite", FileI->Archive) - APT_INRELEASE("Component", FileI->Component) - APT_INRELEASE("Version", FileI->Version) - APT_INRELEASE("Origin", FileI->Origin) - APT_INRELEASE("Codename", FileI->Codename) - APT_INRELEASE("Label", FileI->Label) + APT_INRELEASE(MIXED, "Suite", FileI->Archive) + APT_INRELEASE(MIXED, "Component", FileI->Component) + APT_INRELEASE(VERSION, "Version", FileI->Version) + APT_INRELEASE(MIXED, "Origin", FileI->Origin) + APT_INRELEASE(MIXED, "Codename", FileI->Codename) + APT_INRELEASE(MIXED, "Label", FileI->Label) #undef APT_INRELEASE Section.FindFlag("NotAutomatic", FileI->Flags, pkgCache::Flag::NotAutomatic); Section.FindFlag("ButAutomaticUpgrades", FileI->Flags, pkgCache::Flag::ButAutomaticUpgrades); diff --git a/apt-pkg/deb/deblistparser.h b/apt-pkg/deb/deblistparser.h index f5ac47e1e..b55e57d41 100644 --- a/apt-pkg/deb/deblistparser.h +++ b/apt-pkg/deb/deblistparser.h @@ -49,7 +49,6 @@ class debListParser : public pkgCacheGenerator::ListParser std::vector Architectures; bool MultiArchEnabled; - map_stringitem_t UniqFindTagWrite(const char *Tag); virtual bool ParseStatus(pkgCache::PkgIterator &Pkg,pkgCache::VerIterator &Ver); bool ParseDepends(pkgCache::VerIterator &Ver,const char *Tag, unsigned int Type); diff --git a/apt-pkg/edsp/edspindexfile.cc b/apt-pkg/edsp/edspindexfile.cc index e013dd44c..c38f24567 100644 --- a/apt-pkg/edsp/edspindexfile.cc +++ b/apt-pkg/edsp/edspindexfile.cc @@ -56,7 +56,7 @@ bool edspIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const pkgCache::PkgFileIterator CFile = Gen.GetCurFile(); CFile->Size = Pkg.FileSize(); CFile->mtime = Pkg.ModificationTime(); - map_stringitem_t const storage = Gen.WriteUniqString("edsp::scenario"); + map_stringitem_t const storage = Gen.StoreString(pkgCacheGenerator::MIXED, "edsp::scenario"); CFile->Archive = storage; if (Gen.MergeList(Parser) == false) diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index 4b4631a65..4ab9e2a4b 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -82,7 +82,6 @@ pkgCache::Header::Header() MaxDescFileSize = 0; FileList = 0; - StringList = 0; VerSysName = 0; Architecture = 0; HashTableSize = _config->FindI("APT::Cache-HashTableSize", 10 * 1048); @@ -140,7 +139,6 @@ bool pkgCache::ReMap(bool const &Errorchecks) DescP = (Description *)Map.Data(); ProvideP = (Provides *)Map.Data(); DepP = (Dependency *)Map.Data(); - StringItemP = (StringItem *)Map.Data(); StrP = (char *)Map.Data(); if (Errorchecks == false) diff --git a/apt-pkg/pkgcache.h b/apt-pkg/pkgcache.h index 8179e05aa..4284a318c 100644 --- a/apt-pkg/pkgcache.h +++ b/apt-pkg/pkgcache.h @@ -109,7 +109,6 @@ class pkgCache /*{{{*/ struct Description; struct Provides; struct Dependency; - struct StringItem; struct VerFile; struct DescFile; @@ -186,7 +185,6 @@ class pkgCache /*{{{*/ Description *DescP; Provides *ProvideP; Dependency *DepP; - StringItem *StringItemP; char *StrP; virtual bool ReMap(bool const &Errorchecks = true); @@ -290,12 +288,6 @@ struct pkgCache::Header The PackageFile structures are singly linked lists that represent all package files that have been merged into the cache. */ map_pointer_t FileList; - /** \brief index of the first StringItem structure - - The cache contains a list of all the unique strings (StringItems). - The parser reads this list into memory so it can match strings - against it.*/ - map_pointer_t StringList; /** \brief String representing the version system used */ map_pointer_t VerSysName; /** \brief native architecture the cache was built against */ @@ -438,7 +430,7 @@ struct pkgCache::Package struct pkgCache::PackageFile { /** \brief physical disk file that this PackageFile represents */ - map_pointer_t FileName; // StringItem + map_stringitem_t FileName; /** \brief the release information Please see the files document for a description of what the @@ -606,7 +598,7 @@ struct pkgCache::Description struct pkgCache::Dependency { /** \brief string of the version the dependency is applied against */ - map_stringitem_t Version; // StringItem + map_stringitem_t Version; /** \brief index of the package this depends applies to The generator will - if the package does not already exist - @@ -656,24 +648,6 @@ struct pkgCache::Provides map_pointer_t NextPkgProv; // Provides }; /*}}}*/ -// StringItem structure /*{{{*/ -/** \brief used for generating single instances of strings - - Some things like Section Name are are useful to have as unique tags. - It is part of a linked list based at pkgCache::Header::StringList - - All strings are simply inlined any place in the file that is natural - for the writer. The client should make no assumptions about the positioning - of strings. All StringItems should be null-terminated. */ -struct pkgCache::StringItem -{ - /** \brief string this refers to */ - map_stringitem_t String; - /** \brief Next link in the chain */ - map_stringitem_t NextItem; -}; - /*}}}*/ - inline char const * pkgCache::NativeArch() { return StrP + HeaderP->Architecture; } diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index 359dffc9d..f7480bc77 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -57,8 +57,7 @@ pkgCacheGenerator::pkgCacheGenerator(DynamicMMap *pMap,OpProgress *Prog) : FoundFileDeps(0) { CurrentFile = 0; - memset(UniqHash,0,sizeof(UniqHash)); - + if (_error->PendingError() == true) return; @@ -82,9 +81,7 @@ pkgCacheGenerator::pkgCacheGenerator(DynamicMMap *pMap,OpProgress *Prog) : if (unlikely(idxVerSysName == 0)) return; Cache.HeaderP->VerSysName = idxVerSysName; - // this pointer is set in ReMap, but we need it now for WriteUniqString - Cache.StringItemP = (pkgCache::StringItem *)Map.Data(); - map_stringitem_t const idxArchitecture = WriteUniqString(_config->Find("APT::Architecture")); + map_stringitem_t const idxArchitecture = StoreString(MIXED, _config->Find("APT::Architecture")); if (unlikely(idxArchitecture == 0)) return; Cache.HeaderP->Architecture = idxArchitecture; @@ -149,10 +146,6 @@ void pkgCacheGenerator::ReMap(void const * const oldMap, void const * const newM CurrentFile += (pkgCache::PackageFile const * const) newMap - (pkgCache::PackageFile const * const) oldMap; - for (size_t i = 0; i < _count(UniqHash); ++i) - if (UniqHash[i] != 0) - UniqHash[i] += (pkgCache::StringItem const * const) newMap - (pkgCache::StringItem const * const) oldMap; - for (std::vector::const_iterator i = Dynamic::toReMap.begin(); i != Dynamic::toReMap.end(); ++i) (*i)->ReMap(oldMap, newMap); @@ -685,7 +678,7 @@ bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,const string &Name #endif Pkg->Group = Grp.Index(); // all is mapped to the native architecture - map_stringitem_t const idxArch = (Arch == "all") ? Cache.HeaderP->Architecture : WriteUniqString(Arch.c_str()); + map_stringitem_t const idxArch = (Arch == "all") ? Cache.HeaderP->Architecture : StoreString(MIXED, Arch); if (unlikely(idxArch == 0)) return false; Pkg->Arch = idxArch; @@ -900,7 +893,7 @@ map_pointer_t pkgCacheGenerator::NewDescription(pkgCache::DescIterator &Desc, // Fill it in Desc = pkgCache::DescIterator(Cache,Cache.DescP + Description); Desc->ID = Cache.HeaderP->DescriptionCount++; - map_stringitem_t const idxlanguage_code = WriteUniqString(Lang); + map_stringitem_t const idxlanguage_code = StoreString(MIXED, Lang); if (unlikely(idxlanguage_code == 0)) return 0; Desc->language_code = idxlanguage_code; @@ -1102,7 +1095,7 @@ bool pkgCacheGenerator::SelectFile(const string &File,const string &Site, // Fill it in map_stringitem_t const idxFileName = WriteStringInMap(File); - map_stringitem_t const idxSite = WriteUniqString(Site); + map_stringitem_t const idxSite = StoreString(MIXED, Site); if (unlikely(idxFileName == 0 || idxSite == 0)) return false; CurrentFile->FileName = idxFileName; @@ -1110,7 +1103,7 @@ bool pkgCacheGenerator::SelectFile(const string &File,const string &Site, CurrentFile->NextFile = Cache.HeaderP->FileList; CurrentFile->Flags = Flags; CurrentFile->ID = Cache.HeaderP->PackageFileCount; - map_stringitem_t const idxIndexType = WriteUniqString(Index.GetType()->Label); + map_stringitem_t const idxIndexType = StoreString(MIXED, Index.GetType()->Label); if (unlikely(idxIndexType == 0)) return false; CurrentFile->IndexType = idxIndexType; @@ -1127,57 +1120,27 @@ bool pkgCacheGenerator::SelectFile(const string &File,const string &Site, // --------------------------------------------------------------------- /* This is used to create handles to strings. Given the same text it always returns the same number */ -map_stringitem_t pkgCacheGenerator::WriteUniqString(const char *S, +map_stringitem_t pkgCacheGenerator::StoreString(enum StringType const type, const char *S, unsigned int Size) { - /* We use a very small transient hash table here, this speeds up generation - by a fair amount on slower machines */ - pkgCache::StringItem *&Bucket = UniqHash[(S[0]*5 + S[1]) % _count(UniqHash)]; - if (Bucket != 0 && - stringcmp(S,S+Size,Cache.StrP + Bucket->String) == 0) - return Bucket->String; - - // Search for an insertion point - pkgCache::StringItem *I = Cache.StringItemP + Cache.HeaderP->StringList; - int Res = 1; - map_stringitem_t *Last = &Cache.HeaderP->StringList; - for (; I != Cache.StringItemP; Last = &I->NextItem, - I = Cache.StringItemP + I->NextItem) - { - Res = stringcmp(S,S+Size,Cache.StrP + I->String); - if (Res >= 0) - break; + std::string const key(S, Size); + + std::map * strings; + switch(type) { + case MIXED: strings = &strMixed; break; + case PKGNAME: strings = &strPkgNames; break; + case VERSION: strings = &strVersions; break; + case SECTION: strings = &strSections; break; + default: _error->Fatal("Unknown enum type used for string storage of '%s'", key.c_str()); return 0; } - - // Match - if (Res == 0) - { - Bucket = I; - return I->String; - } - - // Get a structure - void const * const oldMap = Map.Data(); - map_pointer_t const Item = AllocateInMap(sizeof(pkgCache::StringItem)); - if (Item == 0) - return 0; - - map_stringitem_t const idxString = WriteStringInMap(S,Size); - if (unlikely(idxString == 0)) - return 0; - if (oldMap != Map.Data()) { - Last += (map_pointer_t const * const) Map.Data() - (map_pointer_t const * const) oldMap; - I += (pkgCache::StringItem const * const) Map.Data() - (pkgCache::StringItem const * const) oldMap; - } - *Last = Item; - // Fill in the structure - pkgCache::StringItem *ItemP = Cache.StringItemP + Item; - ItemP->NextItem = I - Cache.StringItemP; - ItemP->String = idxString; + std::map::const_iterator const item = strings->find(key); + if (item != strings->end()) + return item->second; - Bucket = ItemP; - return ItemP->String; + map_stringitem_t const idxString = WriteStringInMap(S,Size); + strings->insert(std::make_pair(key, idxString)); + return idxString; } /*}}}*/ // CheckValidity - Check that a cache is up-to-date /*{{{*/ diff --git a/apt-pkg/pkgcachegen.h b/apt-pkg/pkgcachegen.h index 42da7b12d..84777b912 100644 --- a/apt-pkg/pkgcachegen.h +++ b/apt-pkg/pkgcachegen.h @@ -27,6 +27,7 @@ #include #include +#include class FileFd; class pkgSourceList; @@ -36,13 +37,16 @@ class pkgIndexFile; class pkgCacheGenerator /*{{{*/ { private: - - pkgCache::StringItem *UniqHash[26]; APT_HIDDEN map_stringitem_t WriteStringInMap(std::string const &String) { return WriteStringInMap(String.c_str()); }; APT_HIDDEN map_stringitem_t WriteStringInMap(const char *String); APT_HIDDEN map_stringitem_t WriteStringInMap(const char *String, const unsigned long &Len); APT_HIDDEN map_pointer_t AllocateInMap(const unsigned long &size); + std::map strMixed; + std::map strSections; + std::map strPkgNames; + std::map strVersions; + public: class ListParser; @@ -91,8 +95,9 @@ class pkgCacheGenerator /*{{{*/ public: - map_stringitem_t WriteUniqString(const char *S,unsigned int const Size); - inline map_stringitem_t WriteUniqString(const std::string &S) {return WriteUniqString(S.c_str(),S.length());}; + enum StringType { MIXED, PKGNAME, VERSION, SECTION }; + map_stringitem_t StoreString(enum StringType const type, const char * S, unsigned int const Size); + inline map_stringitem_t StoreString(enum StringType const type, const std::string &S) {return StoreString(type, S.c_str(),S.length());}; void DropProgress() {Progress = 0;}; bool SelectFile(const std::string &File,const std::string &Site,pkgIndexFile const &Index, @@ -145,8 +150,9 @@ class pkgCacheGenerator::ListParser protected: - inline map_stringitem_t WriteUniqString(std::string S) {return Owner->WriteUniqString(S);}; - inline map_stringitem_t WriteUniqString(const char *S,unsigned int Size) {return Owner->WriteUniqString(S,Size);}; + inline map_stringitem_t StoreString(pkgCacheGenerator::StringType const type, std::string const &S) {return Owner->StoreString(type, S);}; + inline map_stringitem_t StoreString(pkgCacheGenerator::StringType const type, const char *S,unsigned int Size) {return Owner->StoreString(type, S, Size);}; + inline map_stringitem_t WriteString(const std::string &S) {return Owner->WriteStringInMap(S);}; inline map_stringitem_t WriteString(const char *S,unsigned int Size) {return Owner->WriteStringInMap(S,Size);}; bool NewDepends(pkgCache::VerIterator &Ver,const std::string &Package, const std::string &Arch, -- cgit v1.2.3 From b13ce62c7e7db6a0e80a0f4729ee00105466c3ac Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 23 Jul 2014 14:52:11 +0200 Subject: de-duplicate version strings in the cache Turns out that version numbers aren't as random as you might guess. In my cache for example, I have: Total package names: 69513 (1390 k) Total package structures: 188259 (9036 k) Total distinct versions: 186345 (13.4 M) Total dependencies: 2052242 (57.5 M) which amounts to 1035873 (10,1 M) strings. Reusing version strings reduces this to 161465 (3.479 k). This comes at a cost of course: Generation is slightly slower, but we are still faster than what we started with and it makes room (also cache size wise) for further changes. --- apt-pkg/pkgcachegen.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index f7480bc77..6df3d5ebd 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -609,7 +609,7 @@ bool pkgCacheGenerator::NewGroup(pkgCache::GrpIterator &Grp, const string &Name) return false; Grp = pkgCache::GrpIterator(Cache, Cache.GrpP + Group); - map_pointer_t const idxName = WriteStringInMap(Name); + map_stringitem_t const idxName = StoreString(PKGNAME, Name); if (unlikely(idxName == 0)) return false; Grp->Name = idxName; @@ -836,7 +836,7 @@ map_pointer_t pkgCacheGenerator::NewVersion(pkgCache::VerIterator &Ver, } } // haven't found the version string, so create - map_stringitem_t const idxVerStr = WriteStringInMap(VerStr); + map_stringitem_t const idxVerStr = StoreString(VERSION, VerStr); if (unlikely(idxVerStr == 0)) return 0; Ver->VerStr = idxVerStr; @@ -933,7 +933,7 @@ bool pkgCacheGenerator::NewDepends(pkgCache::PkgIterator &Pkg, if (index == 0) { void const * const oldMap = Map.Data(); - index = WriteStringInMap(Version); + index = StoreString(VERSION, Version); if (unlikely(index == 0)) return false; if (OldDepLast != 0 && oldMap != Map.Data()) -- cgit v1.2.3 From 2a884c612b10b27f4be2cc6dd689bfe448d9361a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 17 Aug 2014 12:30:21 +0200 Subject: fix progress output for (dist-)upgrade calculation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, we had a start and a done of the calculation printed by higher-level code, but this got intermixed by progress reporting from an external solver or the output of autoremove code… The higherlevel code is now only responsible for instantiating a progress object of its choosing (if it wants progress after all) and the rest will be handled by the upgrade code. Either it is used to show the progress of the external solver or the internal solver will give some hints about its overall progress. The later isn't really a proper progress as it will jump forward after each substep, but that is at least a bit better than before without any progress indication. Fixes also the 'strange' non-display of this progress line in -q=1, while all others are shown, which is reflected by all testcase changes. --- apt-pkg/algorithms.cc | 16 +++----- apt-pkg/algorithms.h | 10 ++--- apt-pkg/upgrade.cc | 104 +++++++++++++++++++++++++++++++++----------------- apt-pkg/upgrade.h | 12 +++--- 4 files changed, 87 insertions(+), 55 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index 608ec7fce..71b5ac2c1 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -640,13 +640,11 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg) // ProblemResolver::Resolve - calls a resolver to fix the situation /*{{{*/ // --------------------------------------------------------------------- /* */ -bool pkgProblemResolver::Resolve(bool BrokenFix) +bool pkgProblemResolver::Resolve(bool BrokenFix, OpProgress * const Progress) { std::string const solver = _config->Find("APT::Solver", "internal"); - if (solver != "internal") { - OpTextProgress Prog(*_config); - return EDSP::ResolveExternal(solver.c_str(), Cache, false, false, false, &Prog); - } + if (solver != "internal") + return EDSP::ResolveExternal(solver.c_str(), Cache, false, false, false, Progress); return ResolveInternal(BrokenFix); } /*}}}*/ @@ -1140,13 +1138,11 @@ bool pkgProblemResolver::InstOrNewPolicyBroken(pkgCache::PkgIterator I) /* This is the work horse of the soft upgrade routine. It is very gental in that it does not install or remove any packages. It is assumed that the system was non-broken previously. */ -bool pkgProblemResolver::ResolveByKeep() +bool pkgProblemResolver::ResolveByKeep(OpProgress * const Progress) { std::string const solver = _config->Find("APT::Solver", "internal"); - if (solver != "internal") { - OpTextProgress Prog(*_config); - return EDSP::ResolveExternal(solver.c_str(), Cache, true, false, false, &Prog); - } + if (solver != "internal") + return EDSP::ResolveExternal(solver.c_str(), Cache, true, false, false, Progress); return ResolveByKeepInternal(); } /*}}}*/ diff --git a/apt-pkg/algorithms.h b/apt-pkg/algorithms.h index f35bd9a13..4d3bfa81f 100644 --- a/apt-pkg/algorithms.h +++ b/apt-pkg/algorithms.h @@ -136,12 +136,12 @@ class pkgProblemResolver /*{{{*/ inline void Protect(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= Protected; Cache.MarkProtected(Pkg);}; inline void Remove(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= ToRemove;}; inline void Clear(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] &= ~(Protected | ToRemove);}; - - // Try to intelligently resolve problems by installing and removing packages - bool Resolve(bool BrokenFix = false); - + + // Try to intelligently resolve problems by installing and removing packages + bool Resolve(bool BrokenFix = false, OpProgress * const Progress = NULL); + // Try to resolve problems only by using keep - bool ResolveByKeep(); + bool ResolveByKeep(OpProgress * const Progress = NULL); APT_DEPRECATED void InstallProtect(); diff --git a/apt-pkg/upgrade.cc b/apt-pkg/upgrade.cc index 29b11937b..20a38ecee 100644 --- a/apt-pkg/upgrade.cc +++ b/apt-pkg/upgrade.cc @@ -24,13 +24,14 @@ The problem resolver is used to resolve the problems. */ -bool pkgDistUpgrade(pkgDepCache &Cache) +bool pkgDistUpgrade(pkgDepCache &Cache, OpProgress * const Progress) { std::string const solver = _config->Find("APT::Solver", "internal"); - if (solver != "internal") { - OpTextProgress Prog(*_config); - return EDSP::ResolveExternal(solver.c_str(), Cache, false, true, false, &Prog); - } + if (solver != "internal") + return EDSP::ResolveExternal(solver.c_str(), Cache, false, true, false, Progress); + + if (Progress != NULL) + Progress->OverallProgress(0, 100, 1, _("Calculating upgrade")); pkgDepCache::ActionGroup group(Cache); @@ -41,12 +42,18 @@ bool pkgDistUpgrade(pkgDepCache &Cache) if (I->CurrentVer != 0) Cache.MarkInstall(I, false, 0, false); + if (Progress != NULL) + Progress->Progress(10); + /* Auto upgrade all installed packages, this provides the basis for the installation */ for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) if (I->CurrentVer != 0) Cache.MarkInstall(I, true, 0, false); + if (Progress != NULL) + Progress->Progress(50); + /* Now, install each essential package which is not installed (and not provided by another package in the same name group) */ std::string essential = _config->Find("pkgCacheGen::Essential", "all"); @@ -77,15 +84,24 @@ bool pkgDistUpgrade(pkgDepCache &Cache) for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) if ((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential) Cache.MarkInstall(I, true, 0, false); - + + if (Progress != NULL) + Progress->Progress(55); + /* We do it again over all previously installed packages to force conflict resolution on them all. */ for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) if (I->CurrentVer != 0) Cache.MarkInstall(I, false, 0, false); + if (Progress != NULL) + Progress->Progress(65); + pkgProblemResolver Fix(&Cache); + if (Progress != NULL) + Progress->Progress(95); + // Hold back held packages. if (_config->FindB("APT::Ignore-Hold",false) == false) { @@ -98,18 +114,22 @@ bool pkgDistUpgrade(pkgDepCache &Cache) } } } - - return Fix.Resolve(); + + bool const success = Fix.Resolve(false, Progress); + if (Progress != NULL) + Progress->Done(); + return success; } /*}}}*/ // AllUpgradeNoNewPackages - Upgrade but no removals or new pkgs /*{{{*/ -static bool pkgAllUpgradeNoNewPackages(pkgDepCache &Cache) +static bool pkgAllUpgradeNoNewPackages(pkgDepCache &Cache, OpProgress * const Progress) { std::string const solver = _config->Find("APT::Solver", "internal"); - if (solver != "internal") { - OpTextProgress Prog(*_config); - return EDSP::ResolveExternal(solver.c_str(), Cache, true, false, false, &Prog); - } + if (solver != "internal") + return EDSP::ResolveExternal(solver.c_str(), Cache, true, false, false, Progress); + + if (Progress != NULL) + Progress->OverallProgress(0, 100, 1, _("Calculating upgrade")); pkgDepCache::ActionGroup group(Cache); @@ -131,8 +151,15 @@ static bool pkgAllUpgradeNoNewPackages(pkgDepCache &Cache) if (I->CurrentVer != 0 && Cache[I].InstallVer != 0) Cache.MarkInstall(I, false, 0, false); } - - return Fix.ResolveByKeep(); + + if (Progress != NULL) + Progress->Progress(50); + + // resolve remaining issues via keep + bool const success = Fix.ResolveByKeep(Progress); + if (Progress != NULL) + Progress->Done(); + return success; } /*}}}*/ // AllUpgradeWithNewInstalls - Upgrade + install new packages as needed /*{{{*/ @@ -141,13 +168,14 @@ static bool pkgAllUpgradeNoNewPackages(pkgDepCache &Cache) * Upgrade as much as possible without deleting anything (useful for * stable systems) */ -static bool pkgAllUpgradeWithNewPackages(pkgDepCache &Cache) +static bool pkgAllUpgradeWithNewPackages(pkgDepCache &Cache, OpProgress * const Progress) { std::string const solver = _config->Find("APT::Solver", "internal"); - if (solver != "internal") { - OpTextProgress Prog(*_config); - return EDSP::ResolveExternal(solver.c_str(), Cache, true, false, false, &Prog); - } + if (solver != "internal") + return EDSP::ResolveExternal(solver.c_str(), Cache, true, false, false, Progress); + + if (Progress != NULL) + Progress->OverallProgress(0, 100, 1, _("Calculating upgrade")); pkgDepCache::ActionGroup group(Cache); @@ -170,18 +198,30 @@ static bool pkgAllUpgradeWithNewPackages(pkgDepCache &Cache) } } + if (Progress != NULL) + Progress->Progress(10); + // then let auto-install loose for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) if (Cache[I].Install()) Cache.MarkInstall(I, true, 0, false); + if (Progress != NULL) + Progress->Progress(50); + // ... but it may remove stuff, we we need to clean up afterwards again for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) if (Cache[I].Delete() == true) Cache.MarkKeep(I, false, false); + if (Progress != NULL) + Progress->Progress(60); + // resolve remaining issues via keep - return Fix.ResolveByKeep(); + bool const success = Fix.ResolveByKeep(Progress); + if (Progress != NULL) + Progress->Done(); + return success; } /*}}}*/ // AllUpgrade - Upgrade as many packages as possible /*{{{*/ @@ -189,9 +229,9 @@ static bool pkgAllUpgradeWithNewPackages(pkgDepCache &Cache) /* Right now the system must be consistent before this can be called. It also will not change packages marked for install, it only tries to install packages not marked for install */ -bool pkgAllUpgrade(pkgDepCache &Cache) +bool pkgAllUpgrade(pkgDepCache &Cache, OpProgress * const Progress) { - return pkgAllUpgradeNoNewPackages(Cache); + return pkgAllUpgradeNoNewPackages(Cache, Progress); } /*}}}*/ // MinimizeUpgrade - Minimizes the set of packages to be upgraded /*{{{*/ @@ -239,21 +279,15 @@ bool pkgMinimizeUpgrade(pkgDepCache &Cache) return true; } /*}}}*/ -// APT::Upgrade::Upgrade - Upgrade using a specific strategy /*{{{*/ -bool APT::Upgrade::Upgrade(pkgDepCache &Cache, int mode) +// APT::Upgrade::Upgrade - Upgrade using a specific strategy /*{{{*/ +bool APT::Upgrade::Upgrade(pkgDepCache &Cache, int mode, OpProgress * const Progress) { - if (mode == 0) - { - return pkgDistUpgrade(Cache); - } + if (mode == 0) + return pkgDistUpgrade(Cache, Progress); else if ((mode & ~FORBID_REMOVE_PACKAGES) == 0) - { - return pkgAllUpgradeWithNewPackages(Cache); - } + return pkgAllUpgradeWithNewPackages(Cache, Progress); else if ((mode & ~(FORBID_REMOVE_PACKAGES|FORBID_INSTALL_NEW_PACKAGES)) == 0) - { - return pkgAllUpgradeNoNewPackages(Cache); - } + return pkgAllUpgradeNoNewPackages(Cache, Progress); else _error->Error("pkgAllUpgrade called with unsupported mode %i", mode); diff --git a/apt-pkg/upgrade.h b/apt-pkg/upgrade.h index aa883df10..894f0625e 100644 --- a/apt-pkg/upgrade.h +++ b/apt-pkg/upgrade.h @@ -10,7 +10,10 @@ #ifndef PKGLIB_UPGRADE_H #define PKGLIB_UPGRADE_H +#include + class pkgDepCache; +class OpProgress; namespace APT { namespace Upgrade { @@ -19,14 +22,13 @@ namespace APT { FORBID_REMOVE_PACKAGES = 1, FORBID_INSTALL_NEW_PACKAGES = 2 }; - bool Upgrade(pkgDepCache &Cache, int UpgradeMode); + bool Upgrade(pkgDepCache &Cache, int UpgradeMode, OpProgress * const Progress = NULL); } } // please use APT::Upgrade::Upgrade() instead -bool pkgDistUpgrade(pkgDepCache &Cache); -bool pkgAllUpgrade(pkgDepCache &Cache); -bool pkgMinimizeUpgrade(pkgDepCache &Cache); - +bool pkgDistUpgrade(pkgDepCache &Cache, OpProgress * const Progress = NULL); +bool pkgAllUpgrade(pkgDepCache &Cache, OpProgress * const Progress = NULL); +bool pkgMinimizeUpgrade(pkgDepCache &Cache); #endif -- cgit v1.2.3 From 67caa2e6538f13ff7a0d77e98ad6c58af998376d Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 17 Aug 2014 13:27:59 +0200 Subject: mark pkg(All|Dist)Upgrade as deprecated The comment above their definition marks them already as such, so this is only a formalisation of the deprecation and fixes the occurances we have in our own code together with removing a magic number. Git-Dch: Ignore --- apt-pkg/upgrade.cc | 11 +++++++++-- apt-pkg/upgrade.h | 6 ++++-- 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/upgrade.cc b/apt-pkg/upgrade.cc index 20a38ecee..ca670bdf5 100644 --- a/apt-pkg/upgrade.cc +++ b/apt-pkg/upgrade.cc @@ -282,7 +282,12 @@ bool pkgMinimizeUpgrade(pkgDepCache &Cache) // APT::Upgrade::Upgrade - Upgrade using a specific strategy /*{{{*/ bool APT::Upgrade::Upgrade(pkgDepCache &Cache, int mode, OpProgress * const Progress) { - if (mode == 0) +#if __GNUC__ >= 4 + // the deprecated methods will become our privates, so that is fine + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + if (mode == ALLOW_EVERYTHING) return pkgDistUpgrade(Cache, Progress); else if ((mode & ~FORBID_REMOVE_PACKAGES) == 0) return pkgAllUpgradeWithNewPackages(Cache, Progress); @@ -290,7 +295,9 @@ bool APT::Upgrade::Upgrade(pkgDepCache &Cache, int mode, OpProgress * const Prog return pkgAllUpgradeNoNewPackages(Cache, Progress); else _error->Error("pkgAllUpgrade called with unsupported mode %i", mode); - +#if __GNUC__ >= 4 + #pragma GCC diagnostic pop +#endif return false; } /*}}}*/ diff --git a/apt-pkg/upgrade.h b/apt-pkg/upgrade.h index 894f0625e..a3f693d86 100644 --- a/apt-pkg/upgrade.h +++ b/apt-pkg/upgrade.h @@ -11,6 +11,7 @@ #define PKGLIB_UPGRADE_H #include +#include class pkgDepCache; class OpProgress; @@ -19,6 +20,7 @@ namespace APT { namespace Upgrade { // FIXME: make this "enum class UpgradeMode {" once we enable c++11 enum UpgradeMode { + ALLOW_EVERYTHING = 0, FORBID_REMOVE_PACKAGES = 1, FORBID_INSTALL_NEW_PACKAGES = 2 }; @@ -27,8 +29,8 @@ namespace APT { } // please use APT::Upgrade::Upgrade() instead -bool pkgDistUpgrade(pkgDepCache &Cache, OpProgress * const Progress = NULL); -bool pkgAllUpgrade(pkgDepCache &Cache, OpProgress * const Progress = NULL); +APT_DEPRECATED bool pkgDistUpgrade(pkgDepCache &Cache, OpProgress * const Progress = NULL); +APT_DEPRECATED bool pkgAllUpgrade(pkgDepCache &Cache, OpProgress * const Progress = NULL); bool pkgMinimizeUpgrade(pkgDepCache &Cache); #endif -- cgit v1.2.3 From 5c8c7321559d9136ba90d0ec647ef0234e8d6c23 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 3 Sep 2014 00:26:13 +0200 Subject: add specialisations for std::vector Git-Dch: Ignore --- apt-pkg/cacheset.h | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 2 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/cacheset.h b/apt-pkg/cacheset.h index 36f41c34d..736dda3cf 100644 --- a/apt-pkg/cacheset.h +++ b/apt-pkg/cacheset.h @@ -13,8 +13,10 @@ #include #include #include +#include #include #include +#include #include @@ -99,6 +101,7 @@ protected: bool ShowError; GlobalError::MsgType ErrorType; }; /*}}}*/ + class PackageContainerInterface { /*{{{*/ /** \class PackageContainerInterface @@ -243,6 +246,18 @@ public: /*{{{*/ PackageContainer() : ConstructedBy(UNKNOWN) {} PackageContainer(Constructor const &by) : ConstructedBy(by) {} + /** \brief sort all included versions with given comparer + + Some containers are sorted by default, some are not and can't be, + but a few like std::vector can be sorted if need be, so this can be + specialized in later on. The default is that this will fail though. + Specifically, already sorted containers like std::set will return + false as well as there is no easy way to check that the given comparer + would sort in the same way the set is currently sorted + + \return \b true if the set was sorted, \b false if not. */ + template bool sort(Compare /*Comp*/) { return false; } + /** \brief returns all packages in the cache who belong to the given task A simple helper responsible for search for all members of a task @@ -375,11 +390,15 @@ private: /*{{{*/ Constructor ConstructedBy; /*}}}*/ }; /*}}}*/ - +// specialisations for push_back containers: std::list & std::vector /*{{{*/ template<> template void PackageContainer >::insert(PackageContainer const &pkgcont) { for (typename PackageContainer::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p) _cont.push_back(*p); } +template<> template void PackageContainer >::insert(PackageContainer const &pkgcont) { + for (typename PackageContainer::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p) + _cont.push_back(*p); +} // these two are 'inline' as otherwise the linker has problems with seeing these untemplated // specializations again and again - but we need to see them, so that library users can use them template<> inline bool PackageContainer >::insert(pkgCache::PkgIterator const &P) { @@ -388,12 +407,30 @@ template<> inline bool PackageContainer >::inse _cont.push_back(P); return true; } +template<> inline bool PackageContainer >::insert(pkgCache::PkgIterator const &P) { + if (P.end() == true) + return false; + _cont.push_back(P); + return true; +} template<> inline void PackageContainer >::insert(const_iterator begin, const_iterator end) { for (const_iterator p = begin; p != end; ++p) _cont.push_back(*p); } +template<> inline void PackageContainer >::insert(const_iterator begin, const_iterator end) { + for (const_iterator p = begin; p != end; ++p) + _cont.push_back(*p); +} + /*}}}*/ + +template<> template inline bool PackageContainer >::sort(Compare Comp) { + std::sort(_cont.begin(), _cont.end(), Comp); + return true; +} + typedef PackageContainer > PackageSet; typedef PackageContainer > PackageList; +typedef PackageContainer > PackageVector; class VersionContainerInterface { /*{{{*/ /** \class APT::VersionContainerInterface @@ -568,6 +605,18 @@ public: /*{{{*/ iterator end() { return iterator(_cont.end()); } const_iterator find(pkgCache::VerIterator const &V) const { return const_iterator(_cont.find(V)); } + /** \brief sort all included versions with given comparer + + Some containers are sorted by default, some are not and can't be, + but a few like std::vector can be sorted if need be, so this can be + specialized in later on. The default is that this will fail though. + Specifically, already sorted containers like std::set will return + false as well as there is no easy way to check that the given comparer + would sort in the same way the set is currently sorted + + \return \b true if the set was sorted, \b false if not. */ + template bool sort(Compare /*Comp*/) { return false; } + /** \brief returns all versions specified on the commandline Get all versions from the commandline, uses given default version if @@ -669,11 +718,15 @@ public: /*{{{*/ } /*}}}*/ }; /*}}}*/ - +// specialisations for push_back containers: std::list & std::vector /*{{{*/ template<> template void VersionContainer >::insert(VersionContainer const &vercont) { for (typename VersionContainer::const_iterator v = vercont.begin(); v != vercont.end(); ++v) _cont.push_back(*v); } +template<> template void VersionContainer >::insert(VersionContainer const &vercont) { + for (typename VersionContainer::const_iterator v = vercont.begin(); v != vercont.end(); ++v) + _cont.push_back(*v); +} // these two are 'inline' as otherwise the linker has problems with seeing these untemplated // specializations again and again - but we need to see them, so that library users can use them template<> inline bool VersionContainer >::insert(pkgCache::VerIterator const &V) { @@ -682,11 +735,29 @@ template<> inline bool VersionContainer >::inse _cont.push_back(V); return true; } +template<> inline bool VersionContainer >::insert(pkgCache::VerIterator const &V) { + if (V.end() == true) + return false; + _cont.push_back(V); + return true; +} template<> inline void VersionContainer >::insert(const_iterator begin, const_iterator end) { for (const_iterator v = begin; v != end; ++v) _cont.push_back(*v); } +template<> inline void VersionContainer >::insert(const_iterator begin, const_iterator end) { + for (const_iterator v = begin; v != end; ++v) + _cont.push_back(*v); +} + /*}}}*/ + +template<> template inline bool VersionContainer >::sort(Compare Comp) { + std::sort(_cont.begin(), _cont.end(), Comp); + return true; +} + typedef VersionContainer > VersionSet; typedef VersionContainer > VersionList; +typedef VersionContainer > VersionVector; } #endif -- cgit v1.2.3 From 840ca9714364d5ef5aa8eee0c9b045277b6ab945 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 3 Sep 2014 11:11:10 +0200 Subject: add APT::PackageUniverse as a pkgCache wrapper Git-Dch: Ignore --- apt-pkg/cacheset.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'apt-pkg') diff --git a/apt-pkg/cacheset.h b/apt-pkg/cacheset.h index 736dda3cf..2656727d4 100644 --- a/apt-pkg/cacheset.h +++ b/apt-pkg/cacheset.h @@ -428,6 +428,44 @@ template<> template inline bool PackageContainerHead().PackageCount; } + + const_iterator begin() const { return _cont->PkgBegin(); } + const_iterator end() const { return _cont->PkgEnd(); } + iterator begin() { return _cont->PkgBegin(); } + iterator end() { return _cont->PkgEnd(); } + + PackageUniverse(pkgCache * const Owner) : _cont(Owner) { } + +private: + bool insert(pkgCache::PkgIterator const &) { return true; } + template void insert(PackageContainer const &) { } + void insert(const_iterator, const_iterator) { } + + void clear() { } + iterator& erase(iterator &iter) { return iter; } + size_t erase(const pkgCache::PkgIterator) { return 0; } + void erase(iterator, iterator) { } + + void setConstructor(Constructor const &) { } + Constructor getConstructor() const { return UNKNOWN; } +}; + /*}}}*/ typedef PackageContainer > PackageSet; typedef PackageContainer > PackageList; typedef PackageContainer > PackageVector; -- cgit v1.2.3 From fdba4d53d6b9b594531c34792798f4044a25157e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 3 Sep 2014 18:16:16 +0200 Subject: rework cachesets API to allow future extension MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The introduction of Fnmatch showed that each new selector would require multiple new virtual methods in the CacheSetHelper to work correctly, which isn't that great. We now flip to a single virtual method which handles all cases separated by an enum – as new enum values can be added without an ABI break. Great care was taken to make old code work with the new way of organisation, which means in return that you might be bombarded with deprecation warnings now if you don't adapt, but code should still compile and work as before as can be seen in apt itself with this commit. Git-Dch: Ignore --- apt-pkg/cacheset.cc | 264 +++++++++++++++++++++++++++---------- apt-pkg/cacheset.h | 364 +++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 484 insertions(+), 144 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/cacheset.cc b/apt-pkg/cacheset.cc index d95a32aff..3c38895e9 100644 --- a/apt-pkg/cacheset.cc +++ b/apt-pkg/cacheset.cc @@ -55,7 +55,7 @@ bool PackageContainerInterface::FromTask(PackageContainerInterface * const pci, bool const wasEmpty = pci->empty(); if (wasEmpty == true) - pci->setConstructor(TASK); + pci->setConstructor(CacheSetHelper::TASK); // get the records pkgRecords Recs(Cache); @@ -91,19 +91,19 @@ bool PackageContainerInterface::FromTask(PackageContainerInterface * const pci, continue; pci->insert(Pkg); - helper.showTaskSelection(Pkg, pattern); + helper.showPackageSelection(Pkg, CacheSetHelper::TASK, pattern); found = true; } regfree(&Pattern); if (found == false) { - helper.canNotFindTask(pci, Cache, pattern); - pci->setConstructor(UNKNOWN); + helper.canNotFindPackage(CacheSetHelper::TASK, pci, Cache, pattern); + pci->setConstructor(CacheSetHelper::UNKNOWN); return false; } - if (wasEmpty == false && pci->getConstructor() != UNKNOWN) - pci->setConstructor(UNKNOWN); + if (wasEmpty == false && pci->getConstructor() != CacheSetHelper::UNKNOWN) + pci->setConstructor(CacheSetHelper::UNKNOWN); return true; } @@ -116,7 +116,7 @@ bool PackageContainerInterface::FromRegEx(PackageContainerInterface * const pci, bool const wasEmpty = pci->empty(); if (wasEmpty == true) - pci->setConstructor(REGEX); + pci->setConstructor(CacheSetHelper::REGEX); size_t archfound = pattern.find_last_of(':'); std::string arch = "native"; @@ -150,18 +150,18 @@ bool PackageContainerInterface::FromRegEx(PackageContainerInterface * const pci, } pci->insert(Pkg); - helper.showRegExSelection(Pkg, pattern); + helper.showPackageSelection(Pkg, CacheSetHelper::REGEX, pattern); found = true; } if (found == false) { - helper.canNotFindRegEx(pci, Cache, pattern); - pci->setConstructor(UNKNOWN); + helper.canNotFindPackage(CacheSetHelper::REGEX, pci, Cache, pattern); + pci->setConstructor(CacheSetHelper::UNKNOWN); return false; } - if (wasEmpty == false && pci->getConstructor() != UNKNOWN) - pci->setConstructor(UNKNOWN); + if (wasEmpty == false && pci->getConstructor() != CacheSetHelper::UNKNOWN) + pci->setConstructor(CacheSetHelper::UNKNOWN); return true; } @@ -179,7 +179,7 @@ PackageContainerInterface::FromFnmatch(PackageContainerInterface * const pci, bool const wasEmpty = pci->empty(); if (wasEmpty == true) - pci->setConstructor(FNMATCH); + pci->setConstructor(CacheSetHelper::FNMATCH); size_t archfound = pattern.find_last_of(':'); std::string arch = "native"; @@ -213,26 +213,18 @@ PackageContainerInterface::FromFnmatch(PackageContainerInterface * const pci, } pci->insert(Pkg); -#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13) - helper.showFnmatchSelection(Pkg, pattern); -#else - helper.showRegExSelection(Pkg, pattern); -#endif + helper.showPackageSelection(Pkg, CacheSetHelper::FNMATCH, pattern); found = true; } if (found == false) { -#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13) - helper.canNotFindFnmatch(pci, Cache, pattern); -#else - helper.canNotFindRegEx(pci, Cache, pattern); -#endif - pci->setConstructor(UNKNOWN); + helper.canNotFindPackage(CacheSetHelper::FNMATCH, pci, Cache, pattern); + pci->setConstructor(CacheSetHelper::UNKNOWN); return false; } - if (wasEmpty == false && pci->getConstructor() != UNKNOWN) - pci->setConstructor(UNKNOWN); + if (wasEmpty == false && pci->getConstructor() != CacheSetHelper::UNKNOWN) + pci->setConstructor(CacheSetHelper::UNKNOWN); return true; } @@ -321,13 +313,11 @@ bool PackageContainerInterface::FromString(PackageContainerInterface * const pci if (FromGroup(pci, Cache, str, helper) == false && FromTask(pci, Cache, str, helper) == false && -#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13) - // FIXME: hm, hm, regexp/fnmatch incompatible? + // FIXME: hm, hm, regexp/fnmatch incompatible? FromFnmatch(pci, Cache, str, helper) == false && -#endif FromRegEx(pci, Cache, str, helper) == false) { - helper.canNotFindPackage(pci, Cache, str); + helper.canNotFindPackage(CacheSetHelper::PACKAGENAME, pci, Cache, str); found = false; } @@ -391,7 +381,7 @@ bool VersionContainerInterface::FromModifierCommandLine(unsigned short &modID, pkgCacheFile &Cache, const char * cmdline, std::list const &mods, CacheSetHelper &helper) { - Version select = NEWEST; + CacheSetHelper::VerSelector select = CacheSetHelper::NEWEST; std::string str = cmdline; if (unlikely(str.empty() == true)) return false; @@ -434,7 +424,8 @@ bool VersionContainerInterface::FromModifierCommandLine(unsigned short &modID, // FromCommandLine - Return all versions specified on commandline /*{{{*/ bool VersionContainerInterface::FromCommandLine(VersionContainerInterface * const vci, pkgCacheFile &Cache, const char **cmdline, - Version const &fallback, CacheSetHelper &helper) { + CacheSetHelper::VerSelector const fallback, + CacheSetHelper &helper) { bool found = false; for (const char **I = cmdline; *I != 0; ++I) found |= VersionContainerInterface::FromString(vci, Cache, *I, fallback, helper); @@ -444,7 +435,8 @@ bool VersionContainerInterface::FromCommandLine(VersionContainerInterface * cons // FromString - Returns all versions spedcified by a string /*{{{*/ bool VersionContainerInterface::FromString(VersionContainerInterface * const vci, pkgCacheFile &Cache, std::string pkg, - Version const &fallback, CacheSetHelper &helper, + CacheSetHelper::VerSelector const fallback, + CacheSetHelper &helper, bool const onlyFromName) { PackageSet pkgset; if(FileExists(pkg)) @@ -470,7 +462,7 @@ bool VersionContainerInterface::FromString(VersionContainerInterface * const vci } bool errors = true; - if (pkgset.getConstructor() != PackageSet::UNKNOWN) + if (pkgset.getConstructor() != CacheSetHelper::UNKNOWN) errors = helper.showErrors(false); bool found = false; @@ -489,7 +481,7 @@ bool VersionContainerInterface::FromString(VersionContainerInterface * const vci if (P->VersionList != 0) V = P.VersionList(); else - V = helper.canNotFindNewestVer(Cache, P); + V = helper.canNotGetVersion(CacheSetHelper::NEWEST, Cache, P); } else { pkgVersionMatch Match(ver, (verIsRel == true ? pkgVersionMatch::Release : pkgVersionMatch::Version)); @@ -506,11 +498,14 @@ bool VersionContainerInterface::FromString(VersionContainerInterface * const vci } if (V.end() == true) continue; - helper.showSelectedVersion(P, V, ver, verIsRel); + if (verIsRel == true) + helper.showVersionSelection(P, V, CacheSetHelper::RELEASE, ver); + else + helper.showVersionSelection(P, V, CacheSetHelper::VERSIONNUMBER, ver); vci->insert(V); found = true; } - if (pkgset.getConstructor() != PackageSet::UNKNOWN) + if (pkgset.getConstructor() != CacheSetHelper::UNKNOWN) helper.showErrors(errors); return found; } @@ -519,30 +514,30 @@ bool VersionContainerInterface::FromString(VersionContainerInterface * const vci bool VersionContainerInterface::FromPackage(VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &P, - Version const &fallback, + CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper) { pkgCache::VerIterator V; bool showErrors; bool found = false; switch(fallback) { - case ALL: + case CacheSetHelper::ALL: if (P->VersionList != 0) for (V = P.VersionList(); V.end() != true; ++V) found |= vci->insert(V); else - helper.canNotFindAllVer(vci, Cache, P); + helper.canNotFindVersion(CacheSetHelper::ALL, vci, Cache, P); break; - case CANDANDINST: + case CacheSetHelper::CANDANDINST: found |= vci->insert(getInstalledVer(Cache, P, helper)); found |= vci->insert(getCandidateVer(Cache, P, helper)); break; - case CANDIDATE: + case CacheSetHelper::CANDIDATE: found |= vci->insert(getCandidateVer(Cache, P, helper)); break; - case INSTALLED: + case CacheSetHelper::INSTALLED: found |= vci->insert(getInstalledVer(Cache, P, helper)); break; - case CANDINST: + case CacheSetHelper::CANDINST: showErrors = helper.showErrors(false); V = getCandidateVer(Cache, P, helper); if (V.end() == true) @@ -551,9 +546,9 @@ bool VersionContainerInterface::FromPackage(VersionContainerInterface * const vc if (V.end() == false) found |= vci->insert(V); else - helper.canNotFindInstCandVer(vci, Cache, P); + helper.canNotFindVersion(CacheSetHelper::CANDINST, vci, Cache, P); break; - case INSTCAND: + case CacheSetHelper::INSTCAND: showErrors = helper.showErrors(false); V = getInstalledVer(Cache, P, helper); if (V.end() == true) @@ -562,14 +557,18 @@ bool VersionContainerInterface::FromPackage(VersionContainerInterface * const vc if (V.end() == false) found |= vci->insert(V); else - helper.canNotFindInstCandVer(vci, Cache, P); + helper.canNotFindVersion(CacheSetHelper::INSTCAND, vci, Cache, P); break; - case NEWEST: + case CacheSetHelper::NEWEST: if (P->VersionList != 0) found |= vci->insert(P.VersionList()); else - helper.canNotFindNewestVer(Cache, P); + helper.canNotFindVersion(CacheSetHelper::NEWEST, vci, Cache, P); break; + case CacheSetHelper::RELEASE: + case CacheSetHelper::VERSIONNUMBER: + // both make no sense here, so always false + return false; } return found; } @@ -586,7 +585,7 @@ pkgCache::VerIterator VersionContainerInterface::getCandidateVer(pkgCacheFile &C Cand = Cache[Pkg].CandidateVerIter(Cache); } if (Cand.end() == true) - return helper.canNotFindCandidateVer(Cache, Pkg); + return helper.canNotGetVersion(CacheSetHelper::CANDIDATE, Cache, Pkg); return Cand; } /*}}}*/ @@ -594,19 +593,30 @@ pkgCache::VerIterator VersionContainerInterface::getCandidateVer(pkgCacheFile &C pkgCache::VerIterator VersionContainerInterface::getInstalledVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper) { if (Pkg->CurrentVer == 0) - return helper.canNotFindInstalledVer(Cache, Pkg); + return helper.canNotGetVersion(CacheSetHelper::INSTALLED, Cache, Pkg); return Pkg.CurrentVer(); } /*}}}*/ -// canNotFindPkgName - handle the case no package has this name /*{{{*/ -pkgCache::PkgIterator CacheSetHelper::canNotFindPkgName(pkgCacheFile &Cache, - std::string const &str) { - if (ShowError == true) - _error->Insert(ErrorType, _("Unable to locate package %s"), str.c_str()); - return pkgCache::PkgIterator(Cache, 0); +// canNotFindPackage - with the given selector and pattern /*{{{*/ +void CacheSetHelper::canNotFindPackage(enum PkgSelector const select, + PackageContainerInterface * const pci, pkgCacheFile &Cache, + std::string const &pattern) { + switch (select) { +#if __GNUC__ >= 4 + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + case REGEX: canNotFindRegEx(pci, Cache, pattern); break; + case TASK: canNotFindTask(pci, Cache, pattern); break; + case FNMATCH: canNotFindFnmatch(pci, Cache, pattern); break; + case PACKAGENAME: canNotFindPackage(pci, Cache, pattern); break; + case UNKNOWN: break; +#if __GNUC__ >= 4 + #pragma GCC diagnostic pop +#endif + } } - /*}}}*/ // canNotFindTask - handle the case no package is found for a task /*{{{*/ void CacheSetHelper::canNotFindTask(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string pattern) { if (ShowError == true) @@ -618,17 +628,50 @@ void CacheSetHelper::canNotFindRegEx(PackageContainerInterface * const /*pci*/, if (ShowError == true) _error->Insert(ErrorType, _("Couldn't find any package by regex '%s'"), pattern.c_str()); } -#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13) + /*}}}*/ // canNotFindFnmatch - handle the case no package is found by a fnmatch /*{{{*/ void CacheSetHelper::canNotFindFnmatch(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string pattern) { if (ShowError == true) _error->Insert(ErrorType, _("Couldn't find any package by glob '%s'"), pattern.c_str()); } -#endif /*}}}*/ + /*}}}*/ // canNotFindPackage - handle the case no package is found from a string/*{{{*/ APT_CONST void CacheSetHelper::canNotFindPackage(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string const &/*str*/) { } /*}}}*/ + /*}}}*/ +// canNotFindPkgName - handle the case no package has this name /*{{{*/ +pkgCache::PkgIterator CacheSetHelper::canNotFindPkgName(pkgCacheFile &Cache, + std::string const &str) { + if (ShowError == true) + _error->Insert(ErrorType, _("Unable to locate package %s"), str.c_str()); + return pkgCache::PkgIterator(Cache, 0); +} + /*}}}*/ +// canNotFindVersion - for package by selector /*{{{*/ +void CacheSetHelper::canNotFindVersion(enum VerSelector const select, VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) +{ + switch (select) { +#if __GNUC__ >= 4 + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + case ALL: canNotFindAllVer(vci, Cache, Pkg); break; + case INSTCAND: canNotFindInstCandVer(vci, Cache, Pkg); break; + case CANDINST: canNotFindCandInstVer(vci, Cache, Pkg); break; + case NEWEST: canNotFindNewestVer(Cache, Pkg); break; + case CANDIDATE: canNotFindCandidateVer(Cache, Pkg); break; + case INSTALLED: canNotFindInstalledVer(Cache, Pkg); break; +#if __GNUC__ >= 4 + #pragma GCC diagnostic pop +#endif + case CANDANDINST: canNotGetCandInstVer(Cache, Pkg); break; + case RELEASE: + case VERSIONNUMBER: + // invalid in this branch + break; + } +} // canNotFindAllVer /*{{{*/ void CacheSetHelper::canNotFindAllVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &/*Cache*/, pkgCache::PkgIterator const &Pkg) { @@ -637,19 +680,42 @@ void CacheSetHelper::canNotFindAllVer(VersionContainerInterface * const /*vci*/, } /*}}}*/ // canNotFindInstCandVer /*{{{*/ -void CacheSetHelper::canNotFindInstCandVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &/*Cache*/, +void CacheSetHelper::canNotFindInstCandVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { - if (ShowError == true) - _error->Insert(ErrorType, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str()); + canNotGetInstCandVer(Cache, Pkg); } /*}}}*/ // canNotFindInstCandVer /*{{{*/ -void CacheSetHelper::canNotFindCandInstVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &/*Cache*/, +void CacheSetHelper::canNotFindCandInstVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { - if (ShowError == true) - _error->Insert(ErrorType, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str()); + canNotGetCandInstVer(Cache, Pkg); } /*}}}*/ + /*}}}*/ +// canNotGetVersion - for package by selector /*{{{*/ +pkgCache::VerIterator CacheSetHelper::canNotGetVersion(enum VerSelector const select, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { + switch (select) { +#if __GNUC__ >= 4 + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + case NEWEST: return canNotFindNewestVer(Cache, Pkg); + case CANDIDATE: return canNotFindCandidateVer(Cache, Pkg); + case INSTALLED: return canNotFindInstalledVer(Cache, Pkg); +#if __GNUC__ >= 4 + #pragma GCC diagnostic pop +#endif + case CANDINST: return canNotGetCandInstVer(Cache, Pkg); + case INSTCAND: return canNotGetInstCandVer(Cache, Pkg); + case ALL: + case CANDANDINST: + case RELEASE: + case VERSIONNUMBER: + // invalid in this branch + return pkgCache::VerIterator(Cache, 0); + } + return pkgCache::VerIterator(Cache, 0); +} // canNotFindNewestVer /*{{{*/ pkgCache::VerIterator CacheSetHelper::canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { @@ -674,6 +740,41 @@ pkgCache::VerIterator CacheSetHelper::canNotFindInstalledVer(pkgCacheFile &Cache return pkgCache::VerIterator(Cache, 0); } /*}}}*/ +// canNotFindInstCandVer /*{{{*/ +pkgCache::VerIterator CacheSetHelper::canNotGetInstCandVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg) { + if (ShowError == true) + _error->Insert(ErrorType, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str()); + return pkgCache::VerIterator(Cache, 0); +} + /*}}}*/ +// canNotFindInstCandVer /*{{{*/ +pkgCache::VerIterator CacheSetHelper::canNotGetCandInstVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg) { + if (ShowError == true) + _error->Insert(ErrorType, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str()); + return pkgCache::VerIterator(Cache, 0); +} + /*}}}*/ + /*}}}*/ +// showPackageSelection - by selector and given pattern /*{{{*/ +APT_CONST void CacheSetHelper::showPackageSelection(pkgCache::PkgIterator const &pkg, enum PkgSelector const select, + std::string const &pattern) { + switch (select) { +#if __GNUC__ >= 4 + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + case REGEX: showRegExSelection(pkg, pattern); break; + case TASK: showTaskSelection(pkg, pattern); break; + case FNMATCH: showFnmatchSelection(pkg, pattern); break; +#if __GNUC__ >= 4 + #pragma GCC diagnostic pop +#endif + case PACKAGENAME: /* no suprises here */ break; + case UNKNOWN: break; + } +} // showTaskSelection /*{{{*/ APT_CONST void CacheSetHelper::showTaskSelection(pkgCache::PkgIterator const &/*pkg*/, std::string const &/*pattern*/) { @@ -684,14 +785,41 @@ APT_CONST void CacheSetHelper::showRegExSelection(pkgCache::PkgIterator const &/ std::string const &/*pattern*/) { } /*}}}*/ -#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13) // showFnmatchSelection /*{{{*/ APT_CONST void CacheSetHelper::showFnmatchSelection(pkgCache::PkgIterator const &/*pkg*/, std::string const &/*pattern*/) { } /*}}}*/ + /*}}}*/ +// showVersionSelection /*{{{*/ +APT_CONST void CacheSetHelper::showVersionSelection(pkgCache::PkgIterator const &Pkg, + pkgCache::VerIterator const &Ver, enum VerSelector const select, std::string const &pattern) { + switch (select) { +#if __GNUC__ >= 4 + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + case RELEASE: + showSelectedVersion(Pkg, Ver, pattern, true); + break; + case VERSIONNUMBER: + showSelectedVersion(Pkg, Ver, pattern, false); + break; +#if __GNUC__ >= 4 + #pragma GCC diagnostic pop + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif -// showSelectedVersion /*{{{*/ + case NEWEST: + case CANDIDATE: + case INSTALLED: + case CANDINST: + case INSTCAND: + case ALL: + case CANDANDINST: + // not really suprises, but in fact: just not implemented + break; + } +} APT_CONST void CacheSetHelper::showSelectedVersion(pkgCache::PkgIterator const &/*Pkg*/, pkgCache::VerIterator const /*Ver*/, std::string const &/*ver*/, diff --git a/apt-pkg/cacheset.h b/apt-pkg/cacheset.h index 2656727d4..57a956808 100644 --- a/apt-pkg/cacheset.h +++ b/apt-pkg/cacheset.h @@ -53,36 +53,109 @@ public: /*{{{*/ ShowError(ShowError), ErrorType(ErrorType) {} virtual ~CacheSetHelper() {} - virtual void showTaskSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern); - virtual void showRegExSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern); -#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13) - virtual void showFnmatchSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern); -#endif - virtual void showSelectedVersion(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const Ver, - std::string const &ver, bool const verIsRel); + enum PkgSelector { UNKNOWN, PACKAGENAME, REGEX, TASK, FNMATCH }; + + /** \brief be notified about the package being selected via pattern + * + * Main use is probably to show a message to the user what happened + * + * \param pkg is the package which was selected + * \param select is the selection method which choose the package + * \param pattern is the string used by the selection method to pick the package + */ + virtual void showPackageSelection(pkgCache::PkgIterator const &pkg, PkgSelector const select, std::string const &pattern); + // use the method above instead, react only on the type you need and let the base handle the rest if need be + // this allows use to add new selection methods without breaking the ABI constantly with new virtual methods + APT_DEPRECATED virtual void showTaskSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern); + APT_DEPRECATED virtual void showRegExSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern); + APT_DEPRECATED virtual void showFnmatchSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern); + + /** \brief be notified if a package can't be found via pattern + * + * Can be used to show a message as well as to try something else to make it match + * + * \param select is the method tried for selection + * \param pci is the container the package should be inserted in + * \param Cache is the package universe available + * \param pattern is the string not matching anything + */ + virtual void canNotFindPackage(enum PkgSelector const select, PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern); + // same as above for showPackageSelection + APT_DEPRECATED virtual void canNotFindTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern); + APT_DEPRECATED virtual void canNotFindRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern); + APT_DEPRECATED virtual void canNotFindFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern); + APT_DEPRECATED virtual void canNotFindPackage(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str); + + /** \brief specifies which version(s) we want to refer to */ + enum VerSelector { + /** by release string */ + RELEASE, + /** by version number string */ + VERSIONNUMBER, + /** All versions */ + ALL, + /** Candidate and installed version */ + CANDANDINST, + /** Candidate version */ + CANDIDATE, + /** Installed version */ + INSTALLED, + /** Candidate or if non installed version */ + CANDINST, + /** Installed or if non candidate version */ + INSTCAND, + /** Newest version */ + NEWEST + }; - virtual void canNotFindTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern); - virtual void canNotFindRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern); -#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13) - virtual void canNotFindFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern); -#endif - virtual void canNotFindPackage(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str); + /** \brief be notified about the version being selected via pattern + * + * Main use is probably to show a message to the user what happened + * Note that at the moment this method is only called for RELEASE + * and VERSION selections, not for the others. + * + * \param Pkg is the package which was selected for + * \param Ver is the version selected + * \param select is the selection method which choose the version + * \param pattern is the string used by the selection method to pick the version + */ + virtual void showVersionSelection(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const &Ver, + enum VerSelector const select, std::string const &pattern); + // renamed to have a similar interface to showPackageSelection + APT_DEPRECATED virtual void showSelectedVersion(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const Ver, + std::string const &ver, bool const verIsRel); - virtual void canNotFindAllVer(VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); - virtual void canNotFindInstCandVer(VersionContainerInterface * const vci, pkgCacheFile &Cache, + /** \brief be notified if a version can't be found for a package + * + * Main use is probably to show a message to the user what happened + * + * \param select is the method tried for selection + * \param vci is the container the version should be inserted in + * \param Cache is the package universe available + * \param Pkg is the package we wanted a version from + */ + virtual void canNotFindVersion(enum VerSelector const select, VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); + // same as above for showPackageSelection + APT_DEPRECATED virtual void canNotFindAllVer(VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); + APT_DEPRECATED virtual void canNotFindInstCandVer(VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); - virtual void canNotFindCandInstVer(VersionContainerInterface * const vci, + APT_DEPRECATED virtual void canNotFindCandInstVer(VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); - virtual pkgCache::PkgIterator canNotFindPkgName(pkgCacheFile &Cache, std::string const &str); - virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, + // the difference between canNotFind and canNotGet is that the later is more low-level + // and called from other places: In this case looking into the code is the only real answer… + virtual pkgCache::VerIterator canNotGetVersion(enum VerSelector const select, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); + // same as above for showPackageSelection + APT_DEPRECATED virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); - virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, + APT_DEPRECATED virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); - virtual pkgCache::VerIterator canNotFindInstalledVer(pkgCacheFile &Cache, + APT_DEPRECATED virtual pkgCache::VerIterator canNotFindInstalledVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); + virtual pkgCache::PkgIterator canNotFindPkgName(pkgCacheFile &Cache, std::string const &str); + bool showErrors() const { return ShowError; } bool showErrors(bool const newValue) { if (ShowError == newValue) return ShowError; else return ((ShowError = newValue) == false); } GlobalError::MsgType errorType() const { return ErrorType; } @@ -100,6 +173,11 @@ public: /*{{{*/ protected: bool ShowError; GlobalError::MsgType ErrorType; + + pkgCache::VerIterator canNotGetInstCandVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg); + pkgCache::VerIterator canNotGetCandInstVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg); }; /*}}}*/ class PackageContainerInterface { /*{{{*/ @@ -154,9 +232,24 @@ public: virtual bool empty() const = 0; virtual void clear() = 0; - enum Constructor { UNKNOWN, REGEX, TASK, FNMATCH }; - virtual void setConstructor(Constructor const &con) = 0; - virtual Constructor getConstructor() const = 0; + // FIXME: This is a bloody hack removed soon. Use CacheSetHelper::PkgSelector ! + enum APT_DEPRECATED Constructor { UNKNOWN = CacheSetHelper::UNKNOWN, + REGEX = CacheSetHelper::REGEX, + TASK = CacheSetHelper::TASK, + FNMATCH = CacheSetHelper::FNMATCH }; +#if __GNUC__ >= 4 + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + void setConstructor(Constructor const by) { ConstructedBy = (CacheSetHelper::PkgSelector)by; } +#if __GNUC__ >= 4 + #pragma GCC diagnostic pop +#endif + + void setConstructor(CacheSetHelper::PkgSelector const by) { ConstructedBy = by; } + CacheSetHelper::PkgSelector getConstructor() const { return ConstructedBy; } + PackageContainerInterface() : ConstructedBy(CacheSetHelper::UNKNOWN) {} + PackageContainerInterface(CacheSetHelper::PkgSelector const by) : ConstructedBy(by) {} static bool FromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); static bool FromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); @@ -177,6 +270,9 @@ public: static bool FromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci, pkgCacheFile &Cache, const char * cmdline, std::list const &mods, CacheSetHelper &helper); + +private: + CacheSetHelper::PkgSelector ConstructedBy; }; /*}}}*/ template class PackageContainer : public PackageContainerInterface {/*{{{*/ @@ -240,11 +336,16 @@ public: /*{{{*/ iterator end() { return iterator(_cont.end()); } const_iterator find(pkgCache::PkgIterator const &P) const { return const_iterator(_cont.find(P)); } - void setConstructor(Constructor const &by) { ConstructedBy = by; } - Constructor getConstructor() const { return ConstructedBy; } - - PackageContainer() : ConstructedBy(UNKNOWN) {} - PackageContainer(Constructor const &by) : ConstructedBy(by) {} + PackageContainer() : PackageContainerInterface() {} + PackageContainer(CacheSetHelper::PkgSelector const &by) : PackageContainerInterface(by) {} +#if __GNUC__ >= 4 + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + APT_DEPRECATED PackageContainer(Constructor const &by) : PackageContainerInterface((CacheSetHelper::PkgSelector)by) {} +#if __GNUC__ >= 4 + #pragma GCC diagnostic pop +#endif /** \brief sort all included versions with given comparer @@ -267,7 +368,7 @@ public: /*{{{*/ \param pattern name of the task \param helper responsible for error and message handling */ static PackageContainer FromTask(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { - PackageContainer cont(TASK); + PackageContainer cont(CacheSetHelper::TASK); PackageContainerInterface::FromTask(&cont, Cache, pattern, helper); return cont; } @@ -284,8 +385,8 @@ public: /*{{{*/ \param Cache the packages are in \param pattern regular expression for package names \param helper responsible for error and message handling */ - static PackageContainer FromRegEx(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { - PackageContainer cont(REGEX); + static PackageContainer FromRegEx(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { + PackageContainer cont(CacheSetHelper::REGEX); PackageContainerInterface::FromRegEx(&cont, Cache, pattern, helper); return cont; } @@ -295,8 +396,8 @@ public: /*{{{*/ return FromRegEx(Cache, pattern, helper); } - static PackageContainer FromFnmatch(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { - PackageContainer cont(FNMATCH); + static PackageContainer FromFnmatch(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { + PackageContainer cont(CacheSetHelper::FNMATCH); PackageContainerInterface::FromFnmatch(&cont, Cache, pattern, helper); return cont; } @@ -386,9 +487,6 @@ public: /*{{{*/ mods, fallback, helper); } /*}}}*/ -private: /*{{{*/ - Constructor ConstructedBy; - /*}}}*/ }; /*}}}*/ // specialisations for push_back containers: std::list & std::vector /*{{{*/ template<> template void PackageContainer >::insert(PackageContainer const &pkgcont) { @@ -461,9 +559,6 @@ private: iterator& erase(iterator &iter) { return iter; } size_t erase(const pkgCache::PkgIterator) { return 0; } void erase(iterator, iterator) { } - - void setConstructor(Constructor const &) { } - Constructor getConstructor() const { return UNKNOWN; } }; /*}}}*/ typedef PackageContainer > PackageSet; @@ -510,45 +605,83 @@ public: virtual void clear() = 0; /** \brief specifies which version(s) will be returned if non is given */ - enum Version { - /** All versions */ - ALL, - /** Candidate and installed version */ - CANDANDINST, - /** Candidate version */ - CANDIDATE, - /** Installed version */ - INSTALLED, - /** Candidate or if non installed version */ - CANDINST, - /** Installed or if non candidate version */ - INSTCAND, - /** Newest version */ - NEWEST + enum APT_DEPRECATED Version { + ALL = CacheSetHelper::ALL, + CANDANDINST = CacheSetHelper::CANDANDINST, + CANDIDATE = CacheSetHelper::CANDIDATE, + INSTALLED = CacheSetHelper::INSTALLED, + CANDINST = CacheSetHelper::CANDINST, + INSTCAND = CacheSetHelper::INSTCAND, + NEWEST = CacheSetHelper::NEWEST }; struct Modifier { - enum Position { NONE, PREFIX, POSTFIX }; - unsigned short ID; + unsigned short const ID; const char * const Alias; - Position Pos; - Version SelectVersion; + enum Position { NONE, PREFIX, POSTFIX } const Pos; + enum CacheSetHelper::VerSelector const SelectVersion; Modifier (unsigned short const &id, const char * const alias, Position const &pos, - Version const &select) : ID(id), Alias(alias), Pos(pos), + enum CacheSetHelper::VerSelector const select) : ID(id), Alias(alias), Pos(pos), SelectVersion(select) {} +#if __GNUC__ >= 4 + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + APT_DEPRECATED Modifier(unsigned short const &id, const char * const alias, Position const &pos, + Version const &select) : ID(id), Alias(alias), Pos(pos), + SelectVersion((CacheSetHelper::VerSelector)select) {} +#if __GNUC__ >= 4 + #pragma GCC diagnostic pop +#endif }; static bool FromCommandLine(VersionContainerInterface * const vci, pkgCacheFile &Cache, - const char **cmdline, Version const &fallback, + const char **cmdline, CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper); +#if __GNUC__ >= 4 + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + APT_DEPRECATED static bool FromCommandLine(VersionContainerInterface * const vci, pkgCacheFile &Cache, + const char **cmdline, Version const &fallback, + CacheSetHelper &helper) { + return FromCommandLine(vci, Cache, cmdline, (CacheSetHelper::VerSelector)fallback, helper); + } +#if __GNUC__ >= 4 + #pragma GCC diagnostic pop +#endif static bool FromString(VersionContainerInterface * const vci, pkgCacheFile &Cache, - std::string pkg, Version const &fallback, CacheSetHelper &helper, + std::string pkg, CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper, bool const onlyFromName = false); +#if __GNUC__ >= 4 + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + APT_DEPRECATED static bool FromString(VersionContainerInterface * const vci, pkgCacheFile &Cache, + std::string pkg, Version const &fallback, CacheSetHelper &helper, + bool const onlyFromName = false) { + return FromString(vci, Cache, pkg, (CacheSetHelper::VerSelector)fallback, helper, onlyFromName); + } +#if __GNUC__ >= 4 + #pragma GCC diagnostic pop +#endif static bool FromPackage(VersionContainerInterface * const vci, pkgCacheFile &Cache, - pkgCache::PkgIterator const &P, Version const &fallback, + pkgCache::PkgIterator const &P, CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper); +#if __GNUC__ >= 4 + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + APT_DEPRECATED static bool FromPackage(VersionContainerInterface * const vci, pkgCacheFile &Cache, + pkgCache::PkgIterator const &P, Version const &fallback, + CacheSetHelper &helper) { + return FromPackage(vci, Cache, P, (CacheSetHelper::VerSelector)fallback, helper); + } +#if __GNUC__ >= 4 + #pragma GCC diagnostic pop +#endif static bool FromModifierCommandLine(unsigned short &modID, VersionContainerInterface * const vci, @@ -560,8 +693,22 @@ public: static bool FromDependency(VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::DepIterator const &D, - Version const &selector, + CacheSetHelper::VerSelector const selector, CacheSetHelper &helper); +#if __GNUC__ >= 4 + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + APT_DEPRECATED static bool FromDependency(VersionContainerInterface * const vci, + pkgCacheFile &Cache, + pkgCache::DepIterator const &D, + Version const &selector, + CacheSetHelper &helper) { + return FromDependency(vci, Cache, D, (CacheSetHelper::VerSelector)selector, helper); + } +#if __GNUC__ >= 4 + #pragma GCC diagnostic pop +#endif protected: /*{{{*/ @@ -664,35 +811,64 @@ public: /*{{{*/ \param fallback version specification \param helper responsible for error and message handling */ static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline, - Version const &fallback, CacheSetHelper &helper) { + CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper) { VersionContainer vercon; VersionContainerInterface::FromCommandLine(&vercon, Cache, cmdline, fallback, helper); return vercon; } static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline, - Version const &fallback) { + CacheSetHelper::VerSelector const fallback) { CacheSetHelper helper; return FromCommandLine(Cache, cmdline, fallback, helper); } static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { - return FromCommandLine(Cache, cmdline, CANDINST); + return FromCommandLine(Cache, cmdline, CacheSetHelper::CANDINST); } - static VersionContainer FromString(pkgCacheFile &Cache, std::string const &pkg, - Version const &fallback, CacheSetHelper &helper, + CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper, bool const /*onlyFromName = false*/) { VersionContainer vercon; VersionContainerInterface::FromString(&vercon, Cache, pkg, fallback, helper); return vercon; } static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg, - Version const &fallback) { + CacheSetHelper::VerSelector const fallback) { CacheSetHelper helper; return FromString(Cache, pkg, fallback, helper); } static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg) { - return FromString(Cache, pkg, CANDINST); + return FromString(Cache, pkg, CacheSetHelper::CANDINST); + } +#if __GNUC__ >= 4 + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline, + Version const &fallback, CacheSetHelper &helper) { + VersionContainer vercon; + VersionContainerInterface::FromCommandLine(&vercon, Cache, cmdline, (CacheSetHelper::VerSelector)fallback, helper); + return vercon; + } + static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline, + Version const &fallback) { + CacheSetHelper helper; + return FromCommandLine(Cache, cmdline, (CacheSetHelper::VerSelector)fallback, helper); } + static VersionContainer FromString(pkgCacheFile &Cache, std::string const &pkg, + Version const &fallback, CacheSetHelper &helper, + bool const /*onlyFromName = false*/) { + VersionContainer vercon; + VersionContainerInterface::FromString(&vercon, Cache, pkg, (CacheSetHelper::VerSelector)fallback, helper); + return vercon; + } + static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg, + Version const &fallback) { + CacheSetHelper helper; + return FromString(Cache, pkg, (CacheSetHelper::VerSelector)fallback, helper); + } +#if __GNUC__ >= 4 + #pragma GCC diagnostic pop +#endif /** \brief returns all versions specified for the package @@ -701,18 +877,36 @@ public: /*{{{*/ \param fallback the version(s) you want to get \param helper the helper used for display and error handling */ static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, - Version const &fallback, CacheSetHelper &helper) { + CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper) { VersionContainer vercon; VersionContainerInterface::FromPackage(&vercon, Cache, P, fallback, helper); return vercon; } static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, - Version const &fallback) { + CacheSetHelper::VerSelector const fallback) { CacheSetHelper helper; return FromPackage(Cache, P, fallback, helper); } +#if __GNUC__ >= 4 + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, + Version const &fallback, CacheSetHelper &helper) { + VersionContainer vercon; + VersionContainerInterface::FromPackage(&vercon, Cache, P, (CacheSetHelper::VerSelector)fallback, helper); + return vercon; + } + static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, + Version const &fallback) { + CacheSetHelper helper; + return FromPackage(Cache, P, (CacheSetHelper::VerSelector)fallback, helper); + } +#if __GNUC__ >= 4 + #pragma GCC diagnostic pop +#endif static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P) { - return FromPackage(Cache, P, CANDIDATE); + return FromPackage(Cache, P, CacheSetHelper::CANDIDATE); } static std::map GroupedFromCommandLine( @@ -741,18 +935,36 @@ public: /*{{{*/ } static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D, - Version const &selector, CacheSetHelper &helper) { + CacheSetHelper::VerSelector const selector, CacheSetHelper &helper) { VersionContainer vercon; VersionContainerInterface::FromDependency(&vercon, Cache, D, selector, helper); return vercon; } static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D, - Version const &selector) { + CacheSetHelper::VerSelector const selector) { CacheSetHelper helper; return FromPackage(Cache, D, selector, helper); } +#if __GNUC__ >= 4 + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D, + Version const &selector, CacheSetHelper &helper) { + VersionContainer vercon; + VersionContainerInterface::FromDependency(&vercon, Cache, D, (CacheSetHelper::VerSelector)selector, helper); + return vercon; + } + static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D, + Version const &selector) { + CacheSetHelper helper; + return FromPackage(Cache, D, (CacheSetHelper::VerSelector)selector, helper); + } +#if __GNUC__ >= 4 + #pragma GCC diagnostic pop +#endif static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D) { - return FromPackage(Cache, D, CANDIDATE); + return FromPackage(Cache, D, CacheSetHelper::CANDIDATE); } /*}}}*/ }; /*}}}*/ -- cgit v1.2.3 From 1e064088bf7b3e29cd36d30760fb3e4143a1a49a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 4 Sep 2014 19:01:12 +0200 Subject: move PCI::From* methods into CacheSetHelper class The methods itself deal with the helper a lot, so it makes sense to move them to the helper itself, which helps also if we want to override some of these methods, the FromString mentioned in the bugreport being the obvious example. VCI is spared from this change for now as while it would fit with the same reasoning it much heavier entangled with the previous CacheSetHelper change, so moving it now would mean breaking the API. The PCI change is worthwhile on its own though as it is used by VCI. Closes: 686221 --- apt-pkg/cacheset.cc | 124 ++++++++++++++++++++++++++++------------------------ apt-pkg/cacheset.h | 102 +++++++++++++++++++++++++++++------------- 2 files changed, 139 insertions(+), 87 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/cacheset.cc b/apt-pkg/cacheset.cc index 3c38895e9..76a7e717e 100644 --- a/apt-pkg/cacheset.cc +++ b/apt-pkg/cacheset.cc @@ -37,8 +37,23 @@ #include /*}}}*/ namespace APT { -// FromTask - Return all packages in the cache from a specific task /*{{{*/ -bool PackageContainerInterface::FromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { + +// PackageFrom - selecting the appropriate method for package selection /*{{{*/ +bool CacheSetHelper::PackageFrom(enum PkgSelector const select, PackageContainerInterface * const pci, + pkgCacheFile &Cache, std::string const &pattern) { + switch (select) { + case UNKNOWN: return false; + case REGEX: return PackageFromRegEx(pci, Cache, pattern); + case TASK: return PackageFromTask(pci, Cache, pattern); + case FNMATCH: return PackageFromFnmatch(pci, Cache, pattern); + case PACKAGENAME: return PackageFromPackageName(pci, Cache, pattern); + case STRING: return PackageFromString(pci, Cache, pattern); + } + return false; +} + /*}}}*/ +// PackageFromTask - Return all packages in the cache from a specific task /*{{{*/ +bool CacheSetHelper::PackageFromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern) { size_t const archfound = pattern.find_last_of(':'); std::string arch = "native"; if (archfound != std::string::npos) { @@ -91,13 +106,13 @@ bool PackageContainerInterface::FromTask(PackageContainerInterface * const pci, continue; pci->insert(Pkg); - helper.showPackageSelection(Pkg, CacheSetHelper::TASK, pattern); + showPackageSelection(Pkg, CacheSetHelper::TASK, pattern); found = true; } regfree(&Pattern); if (found == false) { - helper.canNotFindPackage(CacheSetHelper::TASK, pci, Cache, pattern); + canNotFindPackage(CacheSetHelper::TASK, pci, Cache, pattern); pci->setConstructor(CacheSetHelper::UNKNOWN); return false; } @@ -108,8 +123,8 @@ bool PackageContainerInterface::FromTask(PackageContainerInterface * const pci, return true; } /*}}}*/ -// FromRegEx - Return all packages in the cache matching a pattern /*{{{*/ -bool PackageContainerInterface::FromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { +// PackageFromRegEx - Return all packages in the cache matching a pattern /*{{{*/ +bool CacheSetHelper::PackageFromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern) { static const char * const isregex = ".?+*|[^$"; if (pattern.find_first_of(isregex) == std::string::npos) return false; @@ -150,12 +165,12 @@ bool PackageContainerInterface::FromRegEx(PackageContainerInterface * const pci, } pci->insert(Pkg); - helper.showPackageSelection(Pkg, CacheSetHelper::REGEX, pattern); + showPackageSelection(Pkg, CacheSetHelper::REGEX, pattern); found = true; } if (found == false) { - helper.canNotFindPackage(CacheSetHelper::REGEX, pci, Cache, pattern); + canNotFindPackage(CacheSetHelper::REGEX, pci, Cache, pattern); pci->setConstructor(CacheSetHelper::UNKNOWN); return false; } @@ -166,12 +181,9 @@ bool PackageContainerInterface::FromRegEx(PackageContainerInterface * const pci, return true; } /*}}}*/ -// FromFnmatch - Returns the package defined by this fnmatch /*{{{*/ -bool -PackageContainerInterface::FromFnmatch(PackageContainerInterface * const pci, - pkgCacheFile &Cache, - std::string pattern, - CacheSetHelper &helper) +// PackageFromFnmatch - Returns the package defined by this fnmatch /*{{{*/ +bool CacheSetHelper::PackageFromFnmatch(PackageContainerInterface * const pci, + pkgCacheFile &Cache, std::string pattern) { static const char * const isfnmatch = ".?*[]!"; if (pattern.find_first_of(isfnmatch) == std::string::npos) @@ -213,12 +225,12 @@ PackageContainerInterface::FromFnmatch(PackageContainerInterface * const pci, } pci->insert(Pkg); - helper.showPackageSelection(Pkg, CacheSetHelper::FNMATCH, pattern); + showPackageSelection(Pkg, CacheSetHelper::FNMATCH, pattern); found = true; } if (found == false) { - helper.canNotFindPackage(CacheSetHelper::FNMATCH, pci, Cache, pattern); + canNotFindPackage(CacheSetHelper::FNMATCH, pci, Cache, pattern); pci->setConstructor(CacheSetHelper::UNKNOWN); return false; } @@ -229,9 +241,9 @@ PackageContainerInterface::FromFnmatch(PackageContainerInterface * const pci, return true; } /*}}}*/ -// FromName - Returns the package defined by this string /*{{{*/ -pkgCache::PkgIterator PackageContainerInterface::FromName(pkgCacheFile &Cache, - std::string const &str, CacheSetHelper &helper) { +// PackageFromName - Returns the package defined by this string /*{{{*/ +pkgCache::PkgIterator CacheSetHelper::PackageFromName(pkgCacheFile &Cache, + std::string const &str) { std::string pkg = str; size_t archfound = pkg.find_last_of(':'); std::string arch; @@ -252,13 +264,13 @@ pkgCache::PkgIterator PackageContainerInterface::FromName(pkgCacheFile &Cache, Pkg = Cache.GetPkgCache()->FindPkg(pkg, arch); if (Pkg.end() == true) - return helper.canNotFindPkgName(Cache, str); + return canNotFindPkgName(Cache, str); return Pkg; } /*}}}*/ -// FromGroup - Returns the package defined by this string /*{{{*/ -bool PackageContainerInterface::FromGroup(PackageContainerInterface * const pci, pkgCacheFile &Cache, - std::string pkg, CacheSetHelper &helper) { +// PackageFromPackageName - Returns the package defined by this string /*{{{*/ +bool CacheSetHelper::PackageFromPackageName(PackageContainerInterface * const pci, pkgCacheFile &Cache, + std::string pkg) { if (unlikely(Cache.GetPkgCache() == 0)) return false; @@ -298,7 +310,7 @@ bool PackageContainerInterface::FromGroup(PackageContainerInterface * const pci, } } - pkgCache::PkgIterator Pkg = helper.canNotFindPkgName(Cache, pkg); + pkgCache::PkgIterator Pkg = canNotFindPkgName(Cache, pkg); if (Pkg.end() == true) return false; @@ -306,18 +318,18 @@ bool PackageContainerInterface::FromGroup(PackageContainerInterface * const pci, return true; } /*}}}*/ -// FromString - Return all packages matching a specific string /*{{{*/ -bool PackageContainerInterface::FromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str, CacheSetHelper &helper) { +// PackageFromString - Return all packages matching a specific string /*{{{*/ +bool CacheSetHelper::PackageFromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str) { bool found = true; _error->PushToStack(); - if (FromGroup(pci, Cache, str, helper) == false && - FromTask(pci, Cache, str, helper) == false && + if (PackageFrom(CacheSetHelper::PACKAGENAME, pci, Cache, str) == false && + PackageFrom(CacheSetHelper::TASK, pci, Cache, str) == false && // FIXME: hm, hm, regexp/fnmatch incompatible? - FromFnmatch(pci, Cache, str, helper) == false && - FromRegEx(pci, Cache, str, helper) == false) + PackageFrom(CacheSetHelper::FNMATCH, pci, Cache, str) == false && + PackageFrom(CacheSetHelper::REGEX, pci, Cache, str) == false) { - helper.canNotFindPackage(CacheSetHelper::PACKAGENAME, pci, Cache, str); + canNotFindPackage(CacheSetHelper::PACKAGENAME, pci, Cache, str); found = false; } @@ -328,51 +340,50 @@ bool PackageContainerInterface::FromString(PackageContainerInterface * const pci return found; } /*}}}*/ -// FromCommandLine - Return all packages specified on commandline /*{{{*/ -bool PackageContainerInterface::FromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) { +// PackageFromCommandLine - Return all packages specified on commandline /*{{{*/ +bool CacheSetHelper::PackageFromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline) { bool found = false; for (const char **I = cmdline; *I != 0; ++I) - found |= PackageContainerInterface::FromString(pci, Cache, *I, helper); + found |= PackageFrom(CacheSetHelper::PACKAGENAME, pci, Cache, *I); return found; } /*}}}*/ // FromModifierCommandLine - helper doing the work for PKG:GroupedFromCommandLine /*{{{*/ -bool PackageContainerInterface::FromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci, +bool CacheSetHelper::PackageFromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci, pkgCacheFile &Cache, const char * cmdline, - std::list const &mods, CacheSetHelper &helper) { + std::list const &mods) { std::string str = cmdline; unsigned short fallback = modID; bool modifierPresent = false; - for (std::list::const_iterator mod = mods.begin(); + for (std::list::const_iterator mod = mods.begin(); mod != mods.end(); ++mod) { size_t const alength = strlen(mod->Alias); switch(mod->Pos) { - case Modifier::POSTFIX: + case PkgModifier::POSTFIX: if (str.compare(str.length() - alength, alength, mod->Alias, 0, alength) != 0) continue; str.erase(str.length() - alength); modID = mod->ID; break; - case Modifier::PREFIX: + case PkgModifier::PREFIX: continue; - case Modifier::NONE: + case PkgModifier::NONE: continue; } modifierPresent = true; break; } if (modifierPresent == true) { - bool const errors = helper.showErrors(false); - pkgCache::PkgIterator Pkg = FromName(Cache, cmdline, helper); - helper.showErrors(errors); - if (Pkg.end() == false) { - pci->insert(Pkg); + bool const errors = showErrors(false); + bool const found = PackageFrom(PACKAGENAME, pci, Cache, cmdline); + showErrors(errors); + if (found == true) { modID = fallback; return true; } } - return FromString(pci, Cache, str, helper); + return PackageFrom(CacheSetHelper::PACKAGENAME, pci, Cache, str); } /*}}}*/ // FromModifierCommandLine - helper doing the work for VER:GroupedFromCommandLine /*{{{*/ @@ -438,14 +449,13 @@ bool VersionContainerInterface::FromString(VersionContainerInterface * const vci CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper, bool const onlyFromName) { - PackageSet pkgset; - if(FileExists(pkg)) - { - PackageContainerInterface::FromString(&pkgset, Cache, pkg, helper); - if(pkgset.size() == 0) - return false; - return VersionContainerInterface::FromPackage(vci, Cache, pkgset.begin(), fallback, helper); - } + PackageSet pkgset; + if(FileExists(pkg)) { + helper.PackageFrom(CacheSetHelper::STRING, &pkgset, Cache, pkg); + if(pkgset.empty() == true) + return false; + return VersionContainerInterface::FromPackage(vci, Cache, pkgset.begin(), fallback, helper); + } std::string ver; bool verIsRel = false; @@ -456,9 +466,9 @@ bool VersionContainerInterface::FromString(VersionContainerInterface * const vci pkg.erase(vertag); } if (onlyFromName == false) - PackageContainerInterface::FromString(&pkgset, Cache, pkg, helper); + helper.PackageFrom(CacheSetHelper::STRING, &pkgset, Cache, pkg); else { - pkgset.insert(PackageContainerInterface::FromName(Cache, pkg, helper)); + helper.PackageFrom(CacheSetHelper::PACKAGENAME, &pkgset, Cache, pkg); } bool errors = true; @@ -611,6 +621,7 @@ void CacheSetHelper::canNotFindPackage(enum PkgSelector const select, case TASK: canNotFindTask(pci, Cache, pattern); break; case FNMATCH: canNotFindFnmatch(pci, Cache, pattern); break; case PACKAGENAME: canNotFindPackage(pci, Cache, pattern); break; + case STRING: canNotFindPackage(pci, Cache, pattern); break; case UNKNOWN: break; #if __GNUC__ >= 4 #pragma GCC diagnostic pop @@ -772,6 +783,7 @@ APT_CONST void CacheSetHelper::showPackageSelection(pkgCache::PkgIterator const #pragma GCC diagnostic pop #endif case PACKAGENAME: /* no suprises here */ break; + case STRING: /* handled by the special cases */ break; case UNKNOWN: break; } } diff --git a/apt-pkg/cacheset.h b/apt-pkg/cacheset.h index 57a956808..892ad2dfc 100644 --- a/apt-pkg/cacheset.h +++ b/apt-pkg/cacheset.h @@ -53,7 +53,25 @@ public: /*{{{*/ ShowError(ShowError), ErrorType(ErrorType) {} virtual ~CacheSetHelper() {} - enum PkgSelector { UNKNOWN, PACKAGENAME, REGEX, TASK, FNMATCH }; + enum PkgSelector { UNKNOWN, REGEX, TASK, FNMATCH, PACKAGENAME, STRING }; + + virtual bool PackageFrom(enum PkgSelector const select, PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern); + + virtual bool PackageFromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline); + + struct PkgModifier { + enum Position { NONE, PREFIX, POSTFIX }; + unsigned short ID; + const char * const Alias; + Position Pos; + PkgModifier (unsigned short const &id, const char * const alias, Position const &pos) : ID(id), Alias(alias), Pos(pos) {} + }; + virtual bool PackageFromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci, + pkgCacheFile &Cache, const char * cmdline, + std::list const &mods); + + // use PackageFrom(PACKAGENAME, …) instead + APT_DEPRECATED pkgCache::PkgIterator PackageFromName(pkgCacheFile &Cache, std::string const &pattern); /** \brief be notified about the package being selected via pattern * @@ -178,6 +196,12 @@ protected: pkgCache::PkgIterator const &Pkg); pkgCache::VerIterator canNotGetCandInstVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); + + bool PackageFromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern); + bool PackageFromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern); + bool PackageFromFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern); + bool PackageFromPackageName(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern); + bool PackageFromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern); }; /*}}}*/ class PackageContainerInterface { /*{{{*/ @@ -251,25 +275,34 @@ public: PackageContainerInterface() : ConstructedBy(CacheSetHelper::UNKNOWN) {} PackageContainerInterface(CacheSetHelper::PkgSelector const by) : ConstructedBy(by) {} - static bool FromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); - static bool FromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); - static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper); - static bool FromFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); - static bool FromGroup(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); - static bool FromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper); - static bool FromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper); - - struct Modifier { - enum Position { NONE, PREFIX, POSTFIX }; - unsigned short ID; - const char * const Alias; - Position Pos; - Modifier (unsigned short const &id, const char * const alias, Position const &pos) : ID(id), Alias(alias), Pos(pos) {} - }; + APT_DEPRECATED static bool FromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { + return helper.PackageFrom(CacheSetHelper::TASK, pci, Cache, pattern); } + APT_DEPRECATED static bool FromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { + return helper.PackageFrom(CacheSetHelper::REGEX, pci, Cache, pattern); } + APT_DEPRECATED static bool FromFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { + return helper.PackageFrom(CacheSetHelper::FNMATCH, pci, Cache, pattern); } + APT_DEPRECATED static bool FromGroup(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { + return helper.PackageFrom(CacheSetHelper::PACKAGENAME, pci, Cache, pattern); } + APT_DEPRECATED static bool FromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { + return helper.PackageFrom(CacheSetHelper::STRING, pci, Cache, pattern); } + APT_DEPRECATED static bool FromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) { + return helper.PackageFromCommandLine(pci, Cache, cmdline); } + + APT_DEPRECATED typedef CacheSetHelper::PkgModifier Modifier; - static bool FromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci, - pkgCacheFile &Cache, const char * cmdline, - std::list const &mods, CacheSetHelper &helper); +#if __GNUC__ >= 4 + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + APT_DEPRECATED static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { + return helper.PackageFromName(Cache, pattern); } + APT_DEPRECATED static bool FromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci, + pkgCacheFile &Cache, const char * cmdline, + std::list const &mods, CacheSetHelper &helper) { + return helper.PackageFromModifierCommandLine(modID, pci, Cache, cmdline, mods); } +#if __GNUC__ >= 4 + #pragma GCC diagnostic pop +#endif private: CacheSetHelper::PkgSelector ConstructedBy; @@ -369,7 +402,7 @@ public: /*{{{*/ \param helper responsible for error and message handling */ static PackageContainer FromTask(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { PackageContainer cont(CacheSetHelper::TASK); - PackageContainerInterface::FromTask(&cont, Cache, pattern, helper); + helper.PackageFrom(CacheSetHelper::TASK, &cont, Cache, pattern); return cont; } static PackageContainer FromTask(pkgCacheFile &Cache, std::string const &pattern) { @@ -387,7 +420,7 @@ public: /*{{{*/ \param helper responsible for error and message handling */ static PackageContainer FromRegEx(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { PackageContainer cont(CacheSetHelper::REGEX); - PackageContainerInterface::FromRegEx(&cont, Cache, pattern, helper); + helper.PackageFrom(CacheSetHelper::REGEX, &cont, Cache, pattern); return cont; } @@ -398,7 +431,7 @@ public: /*{{{*/ static PackageContainer FromFnmatch(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { PackageContainer cont(CacheSetHelper::FNMATCH); - PackageContainerInterface::FromFnmatch(&cont, Cache, pattern, helper); + helper.PackageFrom(CacheSetHelper::FNMATCH, &cont, Cache, pattern); return cont; } static PackageContainer FromFnMatch(pkgCacheFile &Cache, std::string const &pattern) { @@ -406,18 +439,25 @@ public: /*{{{*/ return FromFnmatch(Cache, pattern, helper); } +#if __GNUC__ >= 4 + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif /** \brief returns a package specified by a string \param Cache the package is in \param pattern String the package name should be extracted from \param helper responsible for error and message handling */ - static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { - return PackageContainerInterface::FromName(Cache, pattern, helper); + APT_DEPRECATED static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { + return helper.PackageFromName(Cache, pattern); } - static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern) { + APT_DEPRECATED static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern) { CacheSetHelper helper; - return PackageContainerInterface::FromName(Cache, pattern, helper); + return FromName(Cache, pattern, helper); } +#if __GNUC__ >= 4 + #pragma GCC diagnostic pop +#endif /** \brief returns all packages specified by a string @@ -426,7 +466,7 @@ public: /*{{{*/ \param helper responsible for error and message handling */ static PackageContainer FromString(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { PackageContainer cont; - PackageContainerInterface::FromString(&cont, Cache, pattern, helper); + helper.PackageFrom(CacheSetHelper::PACKAGENAME, &cont, Cache, pattern); return cont; } static PackageContainer FromString(pkgCacheFile &Cache, std::string const &pattern) { @@ -443,7 +483,7 @@ public: /*{{{*/ \param helper responsible for error and message handling */ static PackageContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) { PackageContainer cont; - PackageContainerInterface::FromCommandLine(&cont, Cache, cmdline, helper); + helper.PackageFromCommandLine(&cont, Cache, cmdline); return cont; } static PackageContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { @@ -465,14 +505,14 @@ public: /*{{{*/ static std::map GroupedFromCommandLine( pkgCacheFile &Cache, const char **cmdline, - std::list const &mods, + std::list const &mods, unsigned short const &fallback, CacheSetHelper &helper) { std::map pkgsets; for (const char **I = cmdline; *I != 0; ++I) { unsigned short modID = fallback; PackageContainer pkgset; - PackageContainerInterface::FromModifierCommandLine(modID, &pkgset, Cache, *I, mods, helper); + helper.PackageFromModifierCommandLine(modID, &pkgset, Cache, *I, mods); pkgsets[modID].insert(pkgset); } return pkgsets; @@ -480,7 +520,7 @@ public: /*{{{*/ static std::map GroupedFromCommandLine( pkgCacheFile &Cache, const char **cmdline, - std::list const &mods, + std::list const &mods, unsigned short const &fallback) { CacheSetHelper helper; return GroupedFromCommandLine(Cache, cmdline, -- cgit v1.2.3 From 3721cb019fd03ecd68c20bb22f231ec8fb5f83b1 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 7 Sep 2014 19:16:56 +0200 Subject: add an API for cache filters/matcher A lot of code deals with iterating over packages and checking for specific states. At the moment these are all handcrafted inplace, but that makes sharing common code which just differs in the states it checks rather difficult and is error prune. Having an API to construct arbitrary complex filters will come in handy for those. Git-Dch: Ignore --- apt-pkg/cachefilter.cc | 144 ++++++++++++++++++++++++++++++++++++++++--------- apt-pkg/cachefilter.h | 117 ++++++++++++++++++++++++++++++---------- 2 files changed, 209 insertions(+), 52 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/cachefilter.cc b/apt-pkg/cachefilter.cc index e388f2450..4362f43e3 100644 --- a/apt-pkg/cachefilter.cc +++ b/apt-pkg/cachefilter.cc @@ -6,6 +6,7 @@ // Include Files /*{{{*/ #include +#include #include #include #include @@ -22,7 +23,11 @@ /*}}}*/ namespace APT { namespace CacheFilter { -PackageNameMatchesRegEx::PackageNameMatchesRegEx(std::string const &Pattern) : d(NULL) {/*{{{*/ +APT_CONST Matcher::~Matcher() {} +APT_CONST PackageMatcher::~PackageMatcher() {} + +// Name matches RegEx /*{{{*/ +PackageNameMatchesRegEx::PackageNameMatchesRegEx(std::string const &Pattern) { pattern = new regex_t; int const Res = regcomp(pattern, Pattern.c_str(), REG_EXTENDED | REG_ICASE | REG_NOSUB); if (Res == 0) @@ -34,41 +39,36 @@ PackageNameMatchesRegEx::PackageNameMatchesRegEx(std::string const &Pattern) : d regerror(Res, pattern, Error, sizeof(Error)); _error->Error(_("Regex compilation error - %s"), Error); } - /*}}}*/ -bool PackageNameMatchesRegEx::operator() (pkgCache::PkgIterator const &Pkg) {/*{{{*/ +bool PackageNameMatchesRegEx::operator() (pkgCache::PkgIterator const &Pkg) { if (unlikely(pattern == NULL)) return false; else return regexec(pattern, Pkg.Name(), 0, 0, 0) == 0; } - /*}}}*/ -bool PackageNameMatchesRegEx::operator() (pkgCache::GrpIterator const &Grp) {/*{{{*/ +bool PackageNameMatchesRegEx::operator() (pkgCache::GrpIterator const &Grp) { if (unlikely(pattern == NULL)) return false; else return regexec(pattern, Grp.Name(), 0, 0, 0) == 0; } - /*}}}*/ -PackageNameMatchesRegEx::~PackageNameMatchesRegEx() { /*{{{*/ +PackageNameMatchesRegEx::~PackageNameMatchesRegEx() { if (pattern == NULL) return; regfree(pattern); delete pattern; } /*}}}*/ - -// Fnmatch support /*{{{*/ -//---------------------------------------------------------------------- -bool PackageNameMatchesFnmatch::operator() (pkgCache::PkgIterator const &Pkg) {/*{{{*/ +// Name matches Fnmatch /*{{{*/ +PackageNameMatchesFnmatch::PackageNameMatchesFnmatch(std::string const &Pattern) : + Pattern(Pattern) {} +bool PackageNameMatchesFnmatch::operator() (pkgCache::PkgIterator const &Pkg) { return fnmatch(Pattern.c_str(), Pkg.Name(), FNM_CASEFOLD) == 0; } - /*}}}*/ -bool PackageNameMatchesFnmatch::operator() (pkgCache::GrpIterator const &Grp) {/*{{{*/ +bool PackageNameMatchesFnmatch::operator() (pkgCache::GrpIterator const &Grp) { return fnmatch(Pattern.c_str(), Grp.Name(), FNM_CASEFOLD) == 0; } /*}}}*/ - -// CompleteArch to - tuple /*{{{*/ +// Architecture matches - specification /*{{{*/ //---------------------------------------------------------------------- /* The complete architecture, consisting of -. */ static std::string CompleteArch(std::string const &arch) { @@ -82,12 +82,10 @@ static std::string CompleteArch(std::string const &arch) { else if (arch == "any") return "*-*"; else return "linux-" + arch; } - /*}}}*/ -PackageArchitectureMatchesSpecification::PackageArchitectureMatchesSpecification(std::string const &pattern, bool const isPattern) :/*{{{*/ - literal(pattern), complete(CompleteArch(pattern)), isPattern(isPattern), d(NULL) { +PackageArchitectureMatchesSpecification::PackageArchitectureMatchesSpecification(std::string const &pattern, bool const isPattern) : + literal(pattern), complete(CompleteArch(pattern)), isPattern(isPattern) { } - /*}}}*/ -bool PackageArchitectureMatchesSpecification::operator() (char const * const &arch) {/*{{{*/ +bool PackageArchitectureMatchesSpecification::operator() (char const * const &arch) { if (strcmp(literal.c_str(), arch) == 0 || strcmp(complete.c_str(), arch) == 0) return true; @@ -96,16 +94,112 @@ bool PackageArchitectureMatchesSpecification::operator() (char const * const &ar return fnmatch(complete.c_str(), pkgarch.c_str(), 0) == 0; return fnmatch(pkgarch.c_str(), complete.c_str(), 0) == 0; } - /*}}}*/ -bool PackageArchitectureMatchesSpecification::operator() (pkgCache::PkgIterator const &Pkg) {/*{{{*/ +bool PackageArchitectureMatchesSpecification::operator() (pkgCache::PkgIterator const &Pkg) { return (*this)(Pkg.Arch()); +} +PackageArchitectureMatchesSpecification::~PackageArchitectureMatchesSpecification() { } /*}}}*/ -bool PackageArchitectureMatchesSpecification::operator() (pkgCache::VerIterator const &Ver) {/*{{{*/ - return (*this)(Ver.ParentPkg()); +// Package is new install /*{{{*/ +PackageIsNewInstall::PackageIsNewInstall(pkgCacheFile * const Cache) : Cache(Cache) {} +APT_PURE bool PackageIsNewInstall::operator() (pkgCache::PkgIterator const &Pkg) { + return (*Cache)[Pkg].NewInstall(); } +PackageIsNewInstall::~PackageIsNewInstall() {} /*}}}*/ -PackageArchitectureMatchesSpecification::~PackageArchitectureMatchesSpecification() { /*{{{*/ +// Generica like True, False, NOT, AND, OR /*{{{*/ +APT_CONST bool TrueMatcher::operator() (pkgCache::PkgIterator const &) { return true; } +APT_CONST bool TrueMatcher::operator() (pkgCache::GrpIterator const &) { return true; } +APT_CONST bool TrueMatcher::operator() (pkgCache::VerIterator const &) { return true; } + +APT_CONST bool FalseMatcher::operator() (pkgCache::PkgIterator const &) { return false; } +APT_CONST bool FalseMatcher::operator() (pkgCache::GrpIterator const &) { return false; } +APT_CONST bool FalseMatcher::operator() (pkgCache::VerIterator const &) { return false; } + +NOTMatcher::NOTMatcher(Matcher * const matcher) : matcher(matcher) {} +bool NOTMatcher::operator() (pkgCache::PkgIterator const &Pkg) { return ! (*matcher)(Pkg); } +bool NOTMatcher::operator() (pkgCache::GrpIterator const &Grp) { return ! (*matcher)(Grp); } +bool NOTMatcher::operator() (pkgCache::VerIterator const &Ver) { return ! (*matcher)(Ver); } +NOTMatcher::~NOTMatcher() { delete matcher; } + +ANDMatcher::ANDMatcher() {} +ANDMatcher::ANDMatcher(Matcher * const matcher1) { + AND(matcher1); +} +ANDMatcher::ANDMatcher(Matcher * const matcher1, Matcher * const matcher2) { + AND(matcher1).AND(matcher2); +} +ANDMatcher::ANDMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3) { + AND(matcher1).AND(matcher2).AND(matcher3); +} +ANDMatcher::ANDMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3, Matcher * const matcher4) { + AND(matcher1).AND(matcher2).AND(matcher3).AND(matcher4); +} +ANDMatcher::ANDMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3, Matcher * const matcher4, Matcher * const matcher5) { + AND(matcher1).AND(matcher2).AND(matcher3).AND(matcher4).AND(matcher5); +} +ANDMatcher& ANDMatcher::AND(Matcher * const matcher) { matchers.push_back(matcher); return *this; } +bool ANDMatcher::operator() (pkgCache::PkgIterator const &Pkg) { + for (std::vector::const_iterator M = matchers.begin(); M != matchers.end(); ++M) + if ((**M)(Pkg) == false) + return false; + return true; +} +bool ANDMatcher::operator() (pkgCache::GrpIterator const &Grp) { + for (std::vector::const_iterator M = matchers.begin(); M != matchers.end(); ++M) + if ((**M)(Grp) == false) + return false; + return true; +} +bool ANDMatcher::operator() (pkgCache::VerIterator const &Ver) { + for (std::vector::const_iterator M = matchers.begin(); M != matchers.end(); ++M) + if ((**M)(Ver) == false) + return false; + return true; +} +ANDMatcher::~ANDMatcher() { + for (std::vector::iterator M = matchers.begin(); M != matchers.end(); ++M) + delete *M; +} + +ORMatcher::ORMatcher() {} +ORMatcher::ORMatcher(Matcher * const matcher1) { + OR(matcher1); +} +ORMatcher::ORMatcher(Matcher * const matcher1, Matcher * const matcher2) { + OR(matcher1).OR(matcher2); +} +ORMatcher::ORMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3) { + OR(matcher1).OR(matcher2).OR(matcher3); +} +ORMatcher::ORMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3, Matcher * const matcher4) { + OR(matcher1).OR(matcher2).OR(matcher3).OR(matcher4); +} +ORMatcher::ORMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3, Matcher * const matcher4, Matcher * const matcher5) { + OR(matcher1).OR(matcher2).OR(matcher3).OR(matcher4).OR(matcher5); +} +ORMatcher& ORMatcher::OR(Matcher * const matcher) { matchers.push_back(matcher); return *this; } +bool ORMatcher::operator() (pkgCache::PkgIterator const &Pkg) { + for (std::vector::const_iterator M = matchers.begin(); M != matchers.end(); ++M) + if ((**M)(Pkg) == true) + return true; + return false; +} +bool ORMatcher::operator() (pkgCache::GrpIterator const &Grp) { + for (std::vector::const_iterator M = matchers.begin(); M != matchers.end(); ++M) + if ((**M)(Grp) == true) + return true; + return false; +} +bool ORMatcher::operator() (pkgCache::VerIterator const &Ver) { + for (std::vector::const_iterator M = matchers.begin(); M != matchers.end(); ++M) + if ((**M)(Ver) == true) + return true; + return false; +} +ORMatcher::~ORMatcher() { + for (std::vector::iterator M = matchers.begin(); M != matchers.end(); ++M) + delete *M; } /*}}}*/ diff --git a/apt-pkg/cachefilter.h b/apt-pkg/cachefilter.h index d9b957c67..b4697b773 100644 --- a/apt-pkg/cachefilter.h +++ b/apt-pkg/cachefilter.h @@ -10,28 +10,90 @@ #include #include +#include #include + +class pkgCacheFile; /*}}}*/ namespace APT { namespace CacheFilter { -class PackageMatcher { - public: - virtual bool operator() (pkgCache::PkgIterator const &/*Pkg*/) { - return false; }; - virtual bool operator() (pkgCache::GrpIterator const &/*Grp*/) { - return false; }; - virtual bool operator() (pkgCache::VerIterator const &/*Ver*/) { - return false; }; - - virtual ~PackageMatcher() {}; +class Matcher { +public: + virtual bool operator() (pkgCache::PkgIterator const &/*Pkg*/) = 0; + virtual bool operator() (pkgCache::GrpIterator const &/*Grp*/) = 0; + virtual bool operator() (pkgCache::VerIterator const &/*Ver*/) = 0; + virtual ~Matcher(); }; -// PackageNameMatchesRegEx /*{{{*/ -class PackageNameMatchesRegEx : public PackageMatcher { - /** \brief dpointer placeholder (for later in case we need it) */ - void *d; +class PackageMatcher : public Matcher { +public: + virtual bool operator() (pkgCache::PkgIterator const &Pkg) = 0; + virtual bool operator() (pkgCache::VerIterator const &Ver) { return (*this)(Ver.ParentPkg()); } + virtual bool operator() (pkgCache::GrpIterator const &/*Grp*/) { return false; } + virtual ~PackageMatcher(); +}; + +// Generica like True, False, NOT, AND, OR /*{{{*/ +class TrueMatcher : public Matcher { +public: + virtual bool operator() (pkgCache::PkgIterator const &Pkg); + virtual bool operator() (pkgCache::GrpIterator const &Grp); + virtual bool operator() (pkgCache::VerIterator const &Ver); +}; + +class FalseMatcher : public Matcher { +public: + virtual bool operator() (pkgCache::PkgIterator const &Pkg); + virtual bool operator() (pkgCache::GrpIterator const &Grp); + virtual bool operator() (pkgCache::VerIterator const &Ver); +}; + +class NOTMatcher : public Matcher { + Matcher * const matcher; +public: + NOTMatcher(Matcher * const matcher); + virtual bool operator() (pkgCache::PkgIterator const &Pkg); + virtual bool operator() (pkgCache::GrpIterator const &Grp); + virtual bool operator() (pkgCache::VerIterator const &Ver); + virtual ~NOTMatcher(); +}; + +class ANDMatcher : public Matcher { + std::vector matchers; +public: + // 5 ought to be enough for everybody… c++11 variadic templates would be nice + ANDMatcher(); + ANDMatcher(Matcher * const matcher1); + ANDMatcher(Matcher * const matcher1, Matcher * const matcher2); + ANDMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3); + ANDMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3, Matcher * const matcher4); + ANDMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3, Matcher * const matcher4, Matcher * const matcher5); + ANDMatcher& AND(Matcher * const matcher); + virtual bool operator() (pkgCache::PkgIterator const &Pkg); + virtual bool operator() (pkgCache::GrpIterator const &Grp); + virtual bool operator() (pkgCache::VerIterator const &Ver); + virtual ~ANDMatcher(); +}; +class ORMatcher : public Matcher { + std::vector matchers; +public: + // 5 ought to be enough for everybody… c++11 variadic templates would be nice + ORMatcher(); + ORMatcher(Matcher * const matcher1); + ORMatcher(Matcher * const matcher1, Matcher * const matcher2); + ORMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3); + ORMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3, Matcher * const matcher4); + ORMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3, Matcher * const matcher4, Matcher * const matcher5); + ORMatcher& OR(Matcher * const matcher); + virtual bool operator() (pkgCache::PkgIterator const &Pkg); + virtual bool operator() (pkgCache::GrpIterator const &Grp); + virtual bool operator() (pkgCache::VerIterator const &Ver); + virtual ~ORMatcher(); +}; + /*}}}*/ +class PackageNameMatchesRegEx : public PackageMatcher { /*{{{*/ regex_t* pattern; public: PackageNameMatchesRegEx(std::string const &Pattern); @@ -40,20 +102,16 @@ public: virtual ~PackageNameMatchesRegEx(); }; /*}}}*/ -// PackageNameMatchesFnmatch /*{{{*/ - class PackageNameMatchesFnmatch : public PackageMatcher{ - /** \brief dpointer placeholder (for later in case we need it) */ - void *d; - const std::string Pattern; +class PackageNameMatchesFnmatch : public PackageMatcher { /*{{{*/ + const std::string Pattern; public: - PackageNameMatchesFnmatch(std::string const &Pattern) - : Pattern(Pattern) {}; - virtual bool operator() (pkgCache::PkgIterator const &Pkg); + PackageNameMatchesFnmatch(std::string const &Pattern); + virtual bool operator() (pkgCache::PkgIterator const &Pkg); virtual bool operator() (pkgCache::GrpIterator const &Grp); virtual ~PackageNameMatchesFnmatch() {}; }; /*}}}*/ -// PackageArchitectureMatchesSpecification /*{{{*/ +class PackageArchitectureMatchesSpecification : public PackageMatcher { /*{{{*/ /** \class PackageArchitectureMatchesSpecification \brief matching against architecture specification strings @@ -62,12 +120,9 @@ public: debian-policy §11.1 "Architecture specification strings". Examples: i386, mipsel, linux-any, any-amd64, any */ -class PackageArchitectureMatchesSpecification : public PackageMatcher { std::string literal; std::string complete; bool isPattern; - /** \brief dpointer placeholder (for later in case we need it) */ - void *d; public: /** \brief matching against architecture specification strings * @@ -79,10 +134,18 @@ public: PackageArchitectureMatchesSpecification(std::string const &pattern, bool const isPattern = true); bool operator() (char const * const &arch); virtual bool operator() (pkgCache::PkgIterator const &Pkg); - virtual bool operator() (pkgCache::VerIterator const &Ver); virtual ~PackageArchitectureMatchesSpecification(); }; /*}}}*/ +class PackageIsNewInstall : public PackageMatcher { /*{{{*/ + pkgCacheFile * const Cache; +public: + PackageIsNewInstall(pkgCacheFile * const Cache); + virtual bool operator() (pkgCache::PkgIterator const &Pkg); + virtual ~PackageIsNewInstall(); +}; + /*}}}*/ + } } #endif -- cgit v1.2.3 From c029a8368d0f90d749ccba73fc9afe46e77d8b2f Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 26 Sep 2014 21:47:59 +0200 Subject: fix occurrence typo in tagfile comment Reported-By: codespell Git-Dch: Ignore --- apt-pkg/tagfile.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/tagfile.h b/apt-pkg/tagfile.h index db43bfbf9..3e84d8fd4 100644 --- a/apt-pkg/tagfile.h +++ b/apt-pkg/tagfile.h @@ -94,7 +94,7 @@ class pkgTagSection /** \brief amount of Tags in the current section * * Note: if a Tag is mentioned repeatly it will be counted multiple - * times, but only the last occurance is available via Find methods. + * times, but only the last occurrence is available via Find methods. */ unsigned int Count() const; bool Exists(const char* const Tag) const; -- cgit v1.2.3 From 25613a61f6f3b9e54d5229af7e2278d0fa54bdd9 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 26 Sep 2014 22:16:26 +0200 Subject: fix: Member variable 'X' is not initialized in the constructor. Reported-By: cppcheck Git-Dch: Ignore --- apt-pkg/acquire.cc | 21 ++++++--------------- apt-pkg/acquire.h | 2 +- apt-pkg/cdrom.cc | 10 +++++++--- apt-pkg/contrib/fileutl.cc | 2 +- apt-pkg/install-progress.cc | 2 ++ apt-pkg/install-progress.h | 5 ++--- apt-pkg/metaindex.h | 2 +- apt-pkg/pkgcache.cc | 1 + apt-pkg/pkgcachegen.h | 2 +- apt-pkg/tagfile.h | 2 +- 10 files changed, 23 insertions(+), 26 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 8467dab5b..f0a88a538 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -581,27 +581,18 @@ pkgAcquire::UriIterator pkgAcquire::UriEnd() // Acquire::MethodConfig::MethodConfig - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ -pkgAcquire::MethodConfig::MethodConfig() +pkgAcquire::MethodConfig::MethodConfig() : d(NULL), Next(0), SingleInstance(false), + Pipeline(false), SendConfig(false), LocalOnly(false), NeedsCleanup(false), + Removable(false) { - SingleInstance = false; - Pipeline = false; - SendConfig = false; - LocalOnly = false; - Removable = false; - Next = 0; } /*}}}*/ // Queue::Queue - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ -pkgAcquire::Queue::Queue(string Name,pkgAcquire *Owner) : Name(Name), - Owner(Owner) +pkgAcquire::Queue::Queue(string Name,pkgAcquire *Owner) : d(NULL), Next(0), + Name(Name), Items(0), Workers(0), Owner(Owner), PipeDepth(0), MaxPipeDepth(1) { - Items = 0; - Next = 0; - Workers = 0; - MaxPipeDepth = 1; - PipeDepth = 0; } /*}}}*/ // Queue::~Queue - Destructor /*{{{*/ @@ -805,7 +796,7 @@ void pkgAcquire::Queue::Bump() // AcquireStatus::pkgAcquireStatus - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ -pkgAcquireStatus::pkgAcquireStatus() : d(NULL), Update(true), MorePulses(false) +pkgAcquireStatus::pkgAcquireStatus() : d(NULL), Percent(0), Update(true), MorePulses(false) { Start(); } diff --git a/apt-pkg/acquire.h b/apt-pkg/acquire.h index 0113021b2..a92ecc24c 100644 --- a/apt-pkg/acquire.h +++ b/apt-pkg/acquire.h @@ -585,7 +585,7 @@ class pkgAcquire::UriIterator * * \param Q The queue over which this UriIterator should iterate. */ - UriIterator(pkgAcquire::Queue *Q) : CurQ(Q), CurItem(0) + UriIterator(pkgAcquire::Queue *Q) : d(NULL), CurQ(Q), CurItem(0) { while (CurItem == 0 && CurQ != 0) { diff --git a/apt-pkg/cdrom.cc b/apt-pkg/cdrom.cc index a5ad6a9ff..b97f7b036 100644 --- a/apt-pkg/cdrom.cc +++ b/apt-pkg/cdrom.cc @@ -913,10 +913,14 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/ return true; } /*}}}*/ -pkgUdevCdromDevices::pkgUdevCdromDevices() /*{{{*/ - : libudev_handle(NULL) +pkgUdevCdromDevices::pkgUdevCdromDevices() /*{{{*/ +: libudev_handle(NULL), udev_new(NULL), udev_enumerate_add_match_property(NULL), + udev_enumerate_scan_devices(NULL), udev_enumerate_get_list_entry(NULL), + udev_device_new_from_syspath(NULL), udev_enumerate_get_udev(NULL), + udev_list_entry_get_name(NULL), udev_device_get_devnode(NULL), + udev_enumerate_new(NULL), udev_list_entry_get_next(NULL), + udev_device_get_property_value(NULL), udev_enumerate_add_match_sysattr(NULL) { - } /*}}}*/ diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index e81f32a52..9e7702063 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -896,7 +896,7 @@ class FileFdPrivate { /*{{{*/ bool eof; bool compressing; - LZMAFILE() : file(NULL), eof(false), compressing(false) {} + LZMAFILE() : file(NULL), eof(false), compressing(false) { buffer[0] = '\0'; } ~LZMAFILE() { if (compressing == true) { diff --git a/apt-pkg/install-progress.cc b/apt-pkg/install-progress.cc index cf6c85912..0d180d59b 100644 --- a/apt-pkg/install-progress.cc +++ b/apt-pkg/install-progress.cc @@ -21,6 +21,8 @@ namespace APT { namespace Progress { +PackageManager::PackageManager() : d(NULL), percentage(0.0), last_reported_progress(-1) {}; +PackageManager::~PackageManager() {}; /* Return a APT::Progress::PackageManager based on the global * apt configuration (i.e. APT::Status-Fd and APT::Status-deb822-Fd) diff --git a/apt-pkg/install-progress.h b/apt-pkg/install-progress.h index 5d1a20e9b..912700e8d 100644 --- a/apt-pkg/install-progress.h +++ b/apt-pkg/install-progress.h @@ -26,9 +26,8 @@ namespace Progress { int last_reported_progress; public: - PackageManager() - : percentage(0.0), last_reported_progress(-1) {}; - virtual ~PackageManager() {}; + PackageManager(); + virtual ~PackageManager(); /* Global Start/Stop */ virtual void Start(int /*child_pty*/=-1) {}; diff --git a/apt-pkg/metaindex.h b/apt-pkg/metaindex.h index ffabaadbf..7c4d0c1aa 100644 --- a/apt-pkg/metaindex.h +++ b/apt-pkg/metaindex.h @@ -53,7 +53,7 @@ class metaIndex metaIndex(std::string const &URI, std::string const &Dist, char const * const Type) - : Indexes(NULL), Type(Type), URI(URI), Dist(Dist) + : Indexes(NULL), Type(Type), URI(URI), Dist(Dist), Trusted(false) { /* nothing */ } diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index 4ab9e2a4b..572685ba5 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -84,6 +84,7 @@ pkgCache::Header::Header() FileList = 0; VerSysName = 0; Architecture = 0; + Architectures = 0; HashTableSize = _config->FindI("APT::Cache-HashTableSize", 10 * 1048); memset(Pools,0,sizeof(Pools)); diff --git a/apt-pkg/pkgcachegen.h b/apt-pkg/pkgcachegen.h index 84777b912..e1d22b88f 100644 --- a/apt-pkg/pkgcachegen.h +++ b/apt-pkg/pkgcachegen.h @@ -193,7 +193,7 @@ class pkgCacheGenerator::ListParser virtual bool CollectFileProvides(pkgCache &/*Cache*/, pkgCache::VerIterator &/*Ver*/) {return true;}; - ListParser() : FoundFileDeps(false) {}; + ListParser() : Owner(NULL), OldDepLast(NULL), FoundFileDeps(false) {}; virtual ~ListParser() {}; }; /*}}}*/ diff --git a/apt-pkg/tagfile.h b/apt-pkg/tagfile.h index 3e84d8fd4..39ec94d86 100644 --- a/apt-pkg/tagfile.h +++ b/apt-pkg/tagfile.h @@ -43,7 +43,7 @@ class pkgTagSection unsigned int StartValue; unsigned int NextInBucket; - TagData(unsigned int const StartTag) : StartTag(StartTag), NextInBucket(0) {} + TagData(unsigned int const StartTag) : StartTag(StartTag), EndTag(0), StartValue(0), NextInBucket(0) {} }; std::vector Tags; unsigned int LookupTable[0x100]; -- cgit v1.2.3 From bf3ad91fdf4967fe107e08a6887f9ed51f4f5eea Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 26 Sep 2014 22:55:56 +0200 Subject: =?UTF-8?q?fix:=20warning:=20extra=20=E2=80=98;=E2=80=99=20[-Wpeda?= =?UTF-8?q?ntic]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reported-By: gcc -Wpedantic Git-Dch: Ignore --- apt-pkg/packagemanager.cc | 2 +- apt-pkg/packagemanager.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index e4cd1dc3b..101912f9d 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -1080,7 +1080,7 @@ pkgPackageManager::DoInstallPostFork(APT::Progress::PackageManager *progress) return Failed; return Res; -}; +} #else pkgPackageManager::OrderResult pkgPackageManager::DoInstallPostFork(int statusFd) diff --git a/apt-pkg/packagemanager.h b/apt-pkg/packagemanager.h index 4972dcd04..5bcd2045d 100644 --- a/apt-pkg/packagemanager.h +++ b/apt-pkg/packagemanager.h @@ -47,8 +47,8 @@ class pkgRecords; namespace APT { namespace Progress { class PackageManager; - }; -}; + } +} class pkgPackageManager : protected pkgCache::Namespace -- cgit v1.2.3 From 12841e8320aa499554ac50b102b222900bb1b879 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 24 Jan 2014 23:48:11 +0100 Subject: use apt-key adv (+ gnupg) instead of gpgv for verify apt-key does the keyring merge as we need it, so we just call it instead of reimplementing it to do the merging before gpgv. This means we don't use gpgv anymore (we never depended on it explicitly - bad style), but it also means that the message in apt-cdrom add is a bit less friendly as it says loudly "untrusted key", but for a one-time command its okay. --- apt-pkg/contrib/gpgv.cc | 63 ++++++++++++++----------------------------------- 1 file changed, 18 insertions(+), 45 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/gpgv.cc b/apt-pkg/contrib/gpgv.cc index f24dd9640..56e26ab99 100644 --- a/apt-pkg/contrib/gpgv.cc +++ b/apt-pkg/contrib/gpgv.cc @@ -32,50 +32,29 @@ static char * GenerateTemporaryFileTemplate(const char *basename) /*{{{*/ /*}}}*/ // ExecGPGV - returns the command needed for verify /*{{{*/ // --------------------------------------------------------------------- -/* Generating the commandline for calling gpgv is somehow complicated as +/* Generating the commandline for calling gpg is somehow complicated as we need to add multiple keyrings and user supplied options. - Also, as gpgv has no options to enforce a certain reduced style of + Also, as gpg has no options to enforce a certain reduced style of clear-signed files (=the complete content of the file is signed and the content isn't encoded) we do a divide and conquer approach here - and split up the clear-signed file in message and signature for gpgv + and split up the clear-signed file in message and signature for gpg. + And as a cherry on the cake, we use our apt-key wrapper to do part + of the lifting in regards to merging keyrings. Fun for the whole family. */ void ExecGPGV(std::string const &File, std::string const &FileGPG, int const &statusfd, int fd[2]) { #define EINTERNAL 111 - std::string const gpgvpath = _config->Find("Dir::Bin::gpg", "/usr/bin/gpgv"); - // FIXME: remove support for deprecated APT::GPGV setting - std::string const trustedFile = _config->Find("APT::GPGV::TrustedKeyring", _config->FindFile("Dir::Etc::Trusted")); - std::string const trustedPath = _config->FindDir("Dir::Etc::TrustedParts"); + std::string const aptkey = _config->FindFile("Dir::Bin::apt-key", "/usr/bin/apt-key"); bool const Debug = _config->FindB("Debug::Acquire::gpgv", false); - if (Debug == true) - { - std::clog << "gpgv path: " << gpgvpath << std::endl; - std::clog << "Keyring file: " << trustedFile << std::endl; - std::clog << "Keyring path: " << trustedPath << std::endl; - } - - std::vector keyrings; - if (DirectoryExists(trustedPath)) - keyrings = GetListOfFilesInDir(trustedPath, "gpg", false, true); - if (RealFileExists(trustedFile) == true) - keyrings.push_back(trustedFile); - std::vector Args; - Args.reserve(30); - - if (keyrings.empty() == true) - { - // TRANSLATOR: %s is the trusted keyring parts directory - ioprintf(std::cerr, _("No keyring installed in %s."), - _config->FindDir("Dir::Etc::TrustedParts").c_str()); - exit(EINTERNAL); - } + Args.reserve(10); - Args.push_back(gpgvpath.c_str()); - Args.push_back("--ignore-time-conflict"); + Args.push_back(aptkey.c_str()); + Args.push_back("--quiet"); + Args.push_back("adv"); char statusfdstr[10]; if (statusfd != -1) @@ -85,13 +64,6 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG, Args.push_back(statusfdstr); } - for (std::vector::const_iterator K = keyrings.begin(); - K != keyrings.end(); ++K) - { - Args.push_back("--keyring"); - Args.push_back(K->c_str()); - } - Configuration::Item const *Opts; Opts = _config->Tree("Acquire::gpgv::Options"); if (Opts != 0) @@ -104,6 +76,7 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG, Args.push_back(Opts->Value.c_str()); } } + Args.push_back("--verify"); enum { DETACHED, CLEARSIGNED } releaseSignature = (FileGPG != File) ? DETACHED : CLEARSIGNED; std::vector dataHeader; @@ -160,7 +133,7 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG, if (Debug == true) { - std::clog << "Preparing to exec: " << gpgvpath; + std::clog << "Preparing to exec: "; for (std::vector::const_iterator a = Args.begin(); *a != NULL; ++a) std::clog << " " << *a; std::clog << std::endl; @@ -168,7 +141,7 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG, if (statusfd != -1) { - int const nullfd = open("/dev/null", O_RDONLY); + int const nullfd = open("/dev/null", O_WRONLY); close(fd[0]); // Redirect output to /dev/null; we read from the status fd if (statusfd != STDOUT_FILENO) @@ -185,7 +158,7 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG, if (releaseSignature == DETACHED) { - execvp(gpgvpath.c_str(), (char **) &Args[0]); + execvp(Args[0], (char **) &Args[0]); ioprintf(std::cerr, "Couldn't execute %s to check %s", Args[0], File.c_str()); exit(EINTERNAL); } @@ -205,7 +178,7 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG, { if (statusfd != -1) dup2(fd[1], statusfd); - execvp(gpgvpath.c_str(), (char **) &Args[0]); + execvp(Args[0], (char **) &Args[0]); ioprintf(std::cerr, "Couldn't execute %s to check %s", Args[0], File.c_str()); UNLINK_EXIT(EINTERNAL); } @@ -216,7 +189,7 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG, { if (errno == EINTR) continue; - ioprintf(std::cerr, _("Waited for %s but it wasn't there"), "gpgv"); + ioprintf(std::cerr, _("Waited for %s but it wasn't there"), "apt-key"); UNLINK_EXIT(EINTERNAL); } #undef UNLINK_EXIT @@ -229,14 +202,14 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG, // check if it exit'ed normally … if (WIFEXITED(Status) == false) { - ioprintf(std::cerr, _("Sub-process %s exited unexpectedly"), "gpgv"); + ioprintf(std::cerr, _("Sub-process %s exited unexpectedly"), "apt-key"); exit(EINTERNAL); } // … and with a good exit code if (WEXITSTATUS(Status) != 0) { - ioprintf(std::cerr, _("Sub-process %s returned an error code (%u)"), "gpgv", WEXITSTATUS(Status)); + ioprintf(std::cerr, _("Sub-process %s returned an error code (%u)"), "apt-key", WEXITSTATUS(Status)); exit(WEXITSTATUS(Status)); } -- cgit v1.2.3 From 33a2267214eed2a11281c9f93b8cf10b4c436d94 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 6 Feb 2014 17:56:28 +0100 Subject: add --readonly option for apt-key adv Some advanced commands can be executed without the keyring being modified like --verify, so this adds an option to disable the mergeback and uses it for our gpg calling code. Git-Dch: Ignore --- apt-pkg/contrib/gpgv.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/gpgv.cc b/apt-pkg/contrib/gpgv.cc index 56e26ab99..cd17cd536 100644 --- a/apt-pkg/contrib/gpgv.cc +++ b/apt-pkg/contrib/gpgv.cc @@ -54,6 +54,7 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG, Args.push_back(aptkey.c_str()); Args.push_back("--quiet"); + Args.push_back("--readonly"); Args.push_back("adv"); char statusfdstr[10]; -- cgit v1.2.3 From c46a36adaf51fc28464ea1a0e826c754ee60672b Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 14 Apr 2014 18:24:17 +0200 Subject: add and use 'apt-key verify' which prefers gpgv over gpg gnupg/gnupg2 can do verify just fine of course, so we don't need to use gpgv here, but it is what we always used in the past, so there might be scripts expecting a certain output and more importantly the output of apt-cdrom contains messages from gpg and even with all the settings we activate to prevent it, it still shows (in some versions) a quiet scary: "gpg: WARNING: Using untrusted key!" message. Keeping the use of gpgv is the simplest way to prevent it. We are increasing also the "Breaks: apt" version from libapt as it requires a newer apt-key than might be installed in partial upgrades. --- apt-pkg/contrib/gpgv.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/gpgv.cc b/apt-pkg/contrib/gpgv.cc index cd17cd536..9d798cca9 100644 --- a/apt-pkg/contrib/gpgv.cc +++ b/apt-pkg/contrib/gpgv.cc @@ -55,7 +55,7 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG, Args.push_back(aptkey.c_str()); Args.push_back("--quiet"); Args.push_back("--readonly"); - Args.push_back("adv"); + Args.push_back("verify"); char statusfdstr[10]; if (statusfd != -1) @@ -77,7 +77,6 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG, Args.push_back(Opts->Value.c_str()); } } - Args.push_back("--verify"); enum { DETACHED, CLEARSIGNED } releaseSignature = (FileGPG != File) ? DETACHED : CLEARSIGNED; std::vector dataHeader; -- cgit v1.2.3 From 5e49cbb7b65a79cf76ba251f6493fbd75e812466 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 27 Sep 2014 00:46:43 +0200 Subject: fix: Consecutive return, break, continue, goto or throw statements are unnecessary. Git-Dch: Ignore Reported-By: cppcheck --- apt-pkg/contrib/fileutl.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 9e7702063..df409fa36 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -2126,10 +2126,8 @@ bool Popen(const char* Args[], FileFd &Fd, pid_t &Child, FileFd::OpenMode Mode) int Pipe[2] = {-1, -1}; if(pipe(Pipe) != 0) - { return _error->Errno("pipe", _("Failed to create subprocess IPC")); - return NULL; - } + std::set keep_fds; keep_fds.insert(Pipe[0]); keep_fds.insert(Pipe[1]); -- cgit v1.2.3 From 804de19f5f89a94d445edc3b1b1cf95b55f71258 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 27 Sep 2014 00:49:25 +0200 Subject: fix: Prefer prefix ++/-- operators for non-primitive types Git-Dch: Ignore Reported-By: cppcheck --- apt-pkg/pkgcachegen.cc | 2 +- apt-pkg/sourcelist.cc | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index 6df3d5ebd..6bb246e9f 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -362,7 +362,7 @@ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator /* We know the list is sorted so we use that fact in the search. Insertion of new versions is done with correct sorting */ int Res = 1; - for (; Ver.end() == false; LastVer = &Ver->NextVer, Ver++) + for (; Ver.end() == false; LastVer = &Ver->NextVer, ++Ver) { Res = Cache.VS->CmpVersion(Version,Ver.VerStr()); // Version is higher as current version - insert here diff --git a/apt-pkg/sourcelist.cc b/apt-pkg/sourcelist.cc index e37899ec6..7170e8b5b 100644 --- a/apt-pkg/sourcelist.cc +++ b/apt-pkg/sourcelist.cc @@ -119,7 +119,7 @@ bool pkgSourceList::Type::ParseStanza(vector &List, std::vector list_section = StringSplit(Section, " "); for (std::vector::const_iterator U = list_uris.begin(); - U != list_uris.end(); U++) + U != list_uris.end(); ++U) { std::string URI = (*U); if (!FixupURI(URI)) @@ -129,10 +129,10 @@ bool pkgSourceList::Type::ParseStanza(vector &List, } for (std::vector::const_iterator I = list_dist.begin(); - I != list_dist.end(); I++) + I != list_dist.end(); ++I) { for (std::vector::const_iterator J = list_section.begin(); - J != list_section.end(); J++) + J != list_section.end(); ++J) { if (CreateItem(List, URI, (*I), (*J), Options) == false) { @@ -408,7 +408,7 @@ int pkgSourceList::ParseFileDeb822(string File) string const types = Tags.FindS("Types"); std::vector list_types = StringSplit(types, " "); for (std::vector::const_iterator I = list_types.begin(); - I != list_types.end(); I++) + I != list_types.end(); ++I) { Type *Parse = Type::GetType((*I).c_str()); if (Parse == 0) -- cgit v1.2.3 From 9d02c1ac77717a2a8055e56dad4974abb15c800b Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 27 Sep 2014 00:51:03 +0200 Subject: fix: The class 'pkgSourceList' defines member variable with name 'SrcList' also defined in its parent class 'pkgSource' Git-Dch: Ignore Reported-By: cppcheck --- apt-pkg/sourcelist.h | 4 ---- 1 file changed, 4 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/sourcelist.h b/apt-pkg/sourcelist.h index 261dd8161..35b786e1a 100644 --- a/apt-pkg/sourcelist.h +++ b/apt-pkg/sourcelist.h @@ -96,13 +96,9 @@ class pkgSourceList : public pkgSource public: - std::vector SrcList; - int ParseFileDeb822(std::string File); bool ParseFileOldStyle(std::string File); - public: - bool ReadMainList(); bool Read(std::string File); -- cgit v1.2.3 From a221efc331693f8905da870141756c892911c433 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 20 Jun 2014 19:34:40 +0200 Subject: store source name and version in binary cache Accessing the package records to acquire this information is pretty costly, so that information wasn't used so far in many places. The most noticeable user by far is EDSP at the moment, but there are ideas to change that which this commit tries to enable. --- apt-pkg/cacheiterators.h | 6 ++++++ apt-pkg/deb/deblistparser.cc | 51 ++++++++++++++++++++++++++++++++++++++++++++ apt-pkg/deb/dpkgpm.cc | 7 +----- apt-pkg/edsp.cc | 6 +----- apt-pkg/pkgcache.h | 6 ++++++ 5 files changed, 65 insertions(+), 11 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h index 12a03eb07..b0c02d4a2 100644 --- a/apt-pkg/cacheiterators.h +++ b/apt-pkg/cacheiterators.h @@ -215,6 +215,12 @@ class pkgCache::VerIterator : public Iterator { // Accessors inline const char *VerStr() const {return S->VerStr == 0?0:Owner->StrP + S->VerStr;} inline const char *Section() const {return S->Section == 0?0:Owner->StrP + S->Section;} + /** \brief source package name this version comes from + Always contains the name, even if it is the same as the binary name */ + inline const char *SourcePkgName() const {return Owner->StrP + S->SourcePkgName;} + /** \brief source version this version comes from + Always contains the version string, even if it is the same as the binary version */ + inline const char *SourceVerStr() const {return Owner->StrP + S->SourceVerStr;} inline const char *Arch() const { if ((S->MultiArch & pkgCache::Version::All) == pkgCache::Version::All) return "all"; diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index 9919d2036..103b126de 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -141,6 +141,57 @@ bool debListParser::NewVersion(pkgCache::VerIterator &Ver) map_stringitem_t const idx = StoreString(pkgCacheGenerator::SECTION, Start, Stop - Start); Ver->Section = idx; } + // Parse the source package name + pkgCache::GrpIterator const G = Ver.ParentPkg().Group(); + Ver->SourcePkgName = G->Name; + Ver->SourceVerStr = Ver->VerStr; + if (Section.Find("Source",Start,Stop) == true) + { + const char * const Space = (const char * const) memchr(Start, ' ', Stop - Start); + pkgCache::VerIterator V; + + if (Space != NULL) + { + Stop = Space; + const char * const Open = (const char * const) memchr(Space, '(', Stop - Space); + if (likely(Open != NULL)) + { + const char * const Close = (const char * const) memchr(Open, ')', Stop - Open); + if (likely(Close != NULL)) + { + std::string const version(Open + 1, (Close - Open) - 1); + if (version != Ver.VerStr()) + { + map_stringitem_t const idx = StoreString(pkgCacheGenerator::VERSION, version); + Ver->SourceVerStr = idx; + } + } + } + } + + std::string const pkgname(Start, Stop - Start); + if (pkgname != G.Name()) + { + for (pkgCache::PkgIterator P = G.PackageList(); P.end() == false; P = G.NextPkg(P)) + { + for (V = P.VersionList(); V.end() == false; ++V) + { + if (pkgname == V.SourcePkgName()) + { + Ver->SourcePkgName = V->SourcePkgName; + break; + } + } + if (V.end() == false) + break; + } + if (V.end() == true) + { + map_stringitem_t const idx = StoreString(pkgCacheGenerator::PKGNAME, pkgname); + Ver->SourcePkgName = idx; + } + } + } Ver->MultiArch = ParseMultiArch(true); // Archive Size diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index a5c05d5ea..95fae9a28 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -1754,11 +1754,6 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg) if (Ver.end() == true) return; pkgver = Ver.VerStr() == NULL ? "unknown" : Ver.VerStr(); - pkgRecords Recs(Cache); - pkgRecords::Parser &Parse = Recs.Lookup(Ver.FileList()); - srcpkgname = Parse.SourcePkg(); - if(srcpkgname.empty()) - srcpkgname = pkgname; // if the file exists already, we check: // - if it was reported already (touched by apport). @@ -1809,7 +1804,7 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg) time_t now = time(NULL); fprintf(report, "Date: %s" , ctime(&now)); fprintf(report, "Package: %s %s\n", pkgname.c_str(), pkgver.c_str()); - fprintf(report, "SourcePackage: %s\n", srcpkgname.c_str()); + fprintf(report, "SourcePackage: %s\n", Ver.SourcePkgName()); fprintf(report, "ErrorMessage:\n %s\n", errormsg); // ensure that the log is flushed diff --git a/apt-pkg/edsp.cc b/apt-pkg/edsp.cc index 0d0418e06..2ba914b16 100644 --- a/apt-pkg/edsp.cc +++ b/apt-pkg/edsp.cc @@ -95,12 +95,8 @@ bool EDSP::WriteLimitedScenario(pkgDepCache &Cache, FILE* output, void EDSP::WriteScenarioVersion(pkgDepCache &Cache, FILE* output, pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const &Ver) { - pkgRecords Recs(Cache); - pkgRecords::Parser &rec = Recs.Lookup(Ver.FileList()); - string srcpkg = rec.SourcePkg().empty() ? Pkg.Name() : rec.SourcePkg(); - fprintf(output, "Package: %s\n", Pkg.Name()); - fprintf(output, "Source: %s\n", srcpkg.c_str()); + fprintf(output, "Source: %s\n", Ver.SourcePkgName()); fprintf(output, "Architecture: %s\n", Ver.Arch()); fprintf(output, "Version: %s\n", Ver.VerStr()); if (Pkg.CurrentVer() == Ver) diff --git a/apt-pkg/pkgcache.h b/apt-pkg/pkgcache.h index 4284a318c..6a89eabd7 100644 --- a/apt-pkg/pkgcache.h +++ b/apt-pkg/pkgcache.h @@ -510,6 +510,12 @@ struct pkgCache::Version map_stringitem_t VerStr; /** \brief section this version is filled in */ map_stringitem_t Section; + /** \brief source package name this version comes from + Always contains the name, even if it is the same as the binary name */ + map_stringitem_t SourcePkgName; + /** \brief source version this version comes from + Always contains the version string, even if it is the same as the binary version */ + map_stringitem_t SourceVerStr; /** \brief Multi-Arch capabilities of a package version */ enum VerMultiArch { None = 0, /*!< is the default and doesn't trigger special behaviour */ -- cgit v1.2.3 From 43acd01979039b248cb7f033b82e36d778d0ebec Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 27 Sep 2014 19:45:30 +0200 Subject: allow fetcher setup without directory creation apt-get download and changelog as well as apt-helper reuse the acquire system for their own proposes without requiring the directories the fetcher wants to create, which is a problem if you run them as non-root and the directories do not exist as it greets you with: E: Archives directory /var/cache/apt/archives/partial is missing. - Acquire (13: Permission denied) Closes: 762898 --- apt-pkg/acquire.cc | 30 +++++++++++++++++------------- apt-pkg/acquire.h | 5 ++++- 2 files changed, 21 insertions(+), 14 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index f0a88a538..8119e4487 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -73,23 +73,27 @@ pkgAcquire::pkgAcquire(pkgAcquireStatus *Progress) : LockFD(-1), Queues(0), Wor // --------------------------------------------------------------------- /* Do everything needed to be a complete Acquire object and report the success (or failure) back so the user knows that something is wrong… */ -bool pkgAcquire::Setup(pkgAcquireStatus *Progress, string const &Lock) +bool pkgAcquire::Setup(pkgAcquireStatus *Progress, string const &Lock, + bool const createDirectories) { Log = Progress; // check for existence and possibly create auxiliary directories - string const listDir = _config->FindDir("Dir::State::lists"); - string const partialListDir = listDir + "partial/"; - string const archivesDir = _config->FindDir("Dir::Cache::Archives"); - string const partialArchivesDir = archivesDir + "partial/"; - - if (CreateAPTDirectoryIfNeeded(_config->FindDir("Dir::State"), partialListDir) == false && - CreateAPTDirectoryIfNeeded(listDir, partialListDir) == false) - return _error->Errno("Acquire", _("List directory %spartial is missing."), listDir.c_str()); - - if (CreateAPTDirectoryIfNeeded(_config->FindDir("Dir::Cache"), partialArchivesDir) == false && - CreateAPTDirectoryIfNeeded(archivesDir, partialArchivesDir) == false) - return _error->Errno("Acquire", _("Archives directory %spartial is missing."), archivesDir.c_str()); + if (createDirectories == true) + { + string const listDir = _config->FindDir("Dir::State::lists"); + string const partialListDir = listDir + "partial/"; + string const archivesDir = _config->FindDir("Dir::Cache::Archives"); + string const partialArchivesDir = archivesDir + "partial/"; + + if (CreateAPTDirectoryIfNeeded(_config->FindDir("Dir::State"), partialListDir) == false && + CreateAPTDirectoryIfNeeded(listDir, partialListDir) == false) + return _error->Errno("Acquire", _("List directory %spartial is missing."), listDir.c_str()); + + if (CreateAPTDirectoryIfNeeded(_config->FindDir("Dir::Cache"), partialArchivesDir) == false && + CreateAPTDirectoryIfNeeded(archivesDir, partialArchivesDir) == false) + return _error->Errno("Acquire", _("Archives directory %spartial is missing."), archivesDir.c_str()); + } if (Lock.empty() == true || _config->FindB("Debug::NoLocking", false) == true) return true; diff --git a/apt-pkg/acquire.h b/apt-pkg/acquire.h index a92ecc24c..7bceb4323 100644 --- a/apt-pkg/acquire.h +++ b/apt-pkg/acquire.h @@ -352,8 +352,11 @@ class pkgAcquire * \param Lock defines a lock file that should be acquired to ensure * only one Acquire class is in action at the time or an empty string * if no lock file should be used. + * \param createDirectories can be used to disable the creation of directories, + * e.g. if the fetcher is used with different directories later on */ - bool Setup(pkgAcquireStatus *Progress = NULL, std::string const &Lock = ""); + bool Setup(pkgAcquireStatus *Progress = NULL, std::string const &Lock = "", + bool const createDirectories = true); void SetLog(pkgAcquireStatus *Progress) { Log = Progress; } -- cgit v1.2.3 From c4b91cbe7cd24126ead1c3fd4b89ff7069bcc148 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 28 Sep 2014 01:25:21 +0200 Subject: allow options between command and -- on commandline This used to work before we implemented a stricter commandline parser and e.g. the dd-schroot-cmd command constructs commandlines like this. Reported-By: Helmut Grohne --- apt-pkg/contrib/cmndline.cc | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/cmndline.cc b/apt-pkg/contrib/cmndline.cc index 3799c822d..93c1f4664 100644 --- a/apt-pkg/contrib/cmndline.cc +++ b/apt-pkg/contrib/cmndline.cc @@ -47,23 +47,26 @@ CommandLine::~CommandLine() char const * CommandLine::GetCommand(Dispatch const * const Map, unsigned int const argc, char const * const * const argv) { - // if there is a -- on the line there must be the word we search for around it - // as -- marks the end of the options, just not sure if the command can be - // considered an option or not, so accept both + // if there is a -- on the line there must be the word we search for either + // before it (as -- marks the end of the options) or right after it (as we can't + // decide if the command is actually an option, given that in theory, you could + // have parameters named like commands) for (size_t i = 1; i < argc; ++i) { if (strcmp(argv[i], "--") != 0) continue; - ++i; - if (i < argc) + // check if command is before -- + for (size_t k = 1; k < i; ++k) for (size_t j = 0; Map[j].Match != NULL; ++j) - if (strcmp(argv[i], Map[j].Match) == 0) + if (strcmp(argv[k], Map[j].Match) == 0) return Map[j].Match; - i -= 2; - if (i != 0) + // see if the next token after -- is the command + ++i; + if (i < argc) for (size_t j = 0; Map[j].Match != NULL; ++j) if (strcmp(argv[i], Map[j].Match) == 0) return Map[j].Match; + // we found a --, but not a command return NULL; } // no --, so search for the first word matching a command -- cgit v1.2.3 From ffbe056dc554b3f1fdf79b4726415a70f6d59dc1 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 28 Sep 2014 01:57:49 +0200 Subject: replace c-string Mode with c++-string ActiveSubprocess A long-lasting FIXME in the acquire code points out the problem that we e.g. for decompressors assign c-string representations of c++-strings to the Mode variable, which e.g. cppcheck points out as very bad. In practice, nothing major happens as the c++-strings do not run out of scope until Mode would do, but that is bad style and fragile, so the obvious proper fix is to use a c++ string for storage to begin with. The slight complications stems from the fact that progress reporting code in frontends potentially uses Mode and compares it with NULL, which can't be done with std::string, so instead of just changing the type we introduce a new variable and deprecate the old one. Git-Dch: Ignore --- apt-pkg/acquire-item.cc | 52 ++++++++++++++++++++++++++++++++++++++++++++++--- apt-pkg/acquire-item.h | 7 ++++++- 2 files changed, 55 insertions(+), 4 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index a3e02cb53..d1c1f8c5a 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -64,6 +64,10 @@ static void printHashSumComparision(std::string const &URI, HashStringList const /*}}}*/ // Acquire::Item::Item - Constructor /*{{{*/ +#if __GNUC__ >= 4 + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif pkgAcquire::Item::Item(pkgAcquire *Owner, HashStringList const &ExpectedHashes) : Owner(Owner), FileSize(0), PartialSize(0), Mode(0), ID(0), Complete(false), Local(false), QueueCounter(0), ExpectedAdditionalItems(0), @@ -72,6 +76,9 @@ pkgAcquire::Item::Item(pkgAcquire *Owner, HashStringList const &ExpectedHashes) Owner->Add(this); Status = StatIdle; } +#if __GNUC__ >= 4 + #pragma GCC diagnostic pop +#endif /*}}}*/ // Acquire::Item::~Item - Destructor /*{{{*/ // --------------------------------------------------------------------- @@ -774,7 +781,15 @@ void pkgAcqIndexDiffs::Done(string Message,unsigned long long Size, HashStringLi Local = true; Desc.URI = "rred:" + FinalFile; QueueURI(Desc); + ActiveSubprocess = "rred"; +#if __GNUC__ >= 4 + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif Mode = "rred"; +#if __GNUC__ >= 4 + #pragma GCC diagnostic pop +#endif return; } @@ -894,7 +909,15 @@ void pkgAcqIndexMergeDiffs::Done(string Message,unsigned long long Size,HashStri Local = true; Desc.URI = "rred:" + FinalFile; QueueURI(Desc); + ActiveSubprocess = "rred"; +#if __GNUC__ >= 4 + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif Mode = "rred"; +#if __GNUC__ >= 4 + #pragma GCC diagnostic pop +#endif return; } // success in download/apply all diffs, clean up @@ -1191,7 +1214,15 @@ void pkgAcqIndex::Done(string Message,unsigned long long Size,HashStringList con DestFile += ".decomp"; Desc.URI = "copy:" + FileName; QueueURI(Desc); + ActiveSubprocess = "copy"; +#if __GNUC__ >= 4 + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif Mode = "copy"; +#if __GNUC__ >= 4 + #pragma GCC diagnostic pop +#endif return; } @@ -1251,8 +1282,15 @@ void pkgAcqIndex::Done(string Message,unsigned long long Size,HashStringList con Desc.URI = decompProg + ":" + FileName; QueueURI(Desc); - // FIXME: this points to a c++ string that goes out of scope - Mode = decompProg.c_str(); + ActiveSubprocess = decompProg; +#if __GNUC__ >= 4 + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + Mode = ActiveSubprocess.c_str(); +#if __GNUC__ >= 4 + #pragma GCC diagnostic pop +#endif } /*}}}*/ // AcqIndexTrans::pkgAcqIndexTrans - Constructor /*{{{*/ @@ -1554,7 +1592,15 @@ void pkgAcqMetaIndex::Done(string Message,unsigned long long Size,HashStringList AuthPass = true; Desc.URI = "gpgv:" + SigFile; QueueURI(Desc); - Mode = "gpgv"; + ActiveSubprocess = "gpgv"; +#if __GNUC__ >= 4 + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + Mode = "gpgv"; +#if __GNUC__ >= 4 + #pragma GCC diagnostic pop +#endif return; } } diff --git a/apt-pkg/acquire-item.h b/apt-pkg/acquire-item.h index d0a61f5ec..74b5de675 100644 --- a/apt-pkg/acquire-item.h +++ b/apt-pkg/acquire-item.h @@ -133,7 +133,12 @@ class pkgAcquire::Item : public WeakPointable /** \brief If not \b NULL, contains the name of a subprocess that * is operating on this object (for instance, "gzip" or "gpgv"). */ - const char *Mode; + APT_DEPRECATED const char *Mode; + + /** \brief contains the name of the subprocess that is operating on this object + * (for instance, "gzip", "rred" or "gpgv"). This is obsoleting #Mode from above + * as it can manage the lifetime of included string properly. */ + std::string ActiveSubprocess; /** \brief A client-supplied unique identifier. * -- cgit v1.2.3