diff options
Diffstat (limited to 'apt-pkg')
-rw-r--r-- | apt-pkg/cachefilter-patterns.cc | 4 | ||||
-rw-r--r-- | apt-pkg/cachefilter-patterns.h | 35 |
2 files changed, 39 insertions, 0 deletions
diff --git a/apt-pkg/cachefilter-patterns.cc b/apt-pkg/cachefilter-patterns.cc index 6b506b740..b97d65a03 100644 --- a/apt-pkg/cachefilter-patterns.cc +++ b/apt-pkg/cachefilter-patterns.cc @@ -220,8 +220,12 @@ std::unique_ptr<APT::CacheFilter::Matcher> PatternParser::aPattern(std::unique_p return std::make_unique<APT::CacheFilter::PackageNameMatchesRegEx>(aWord(node->arguments[0])); if (node->matches("?not", 1, 1)) return std::make_unique<APT::CacheFilter::NOTMatcher>(aPattern(node->arguments[0]).release()); + if (node->matches("?obsolete", 0, 0)) + return std::make_unique<Patterns::PackageIsObsolete>(); if (node->matches("?true", 0, 0)) return std::make_unique<APT::CacheFilter::TrueMatcher>(); + if (node->matches("?upgradable", 0, 0)) + return std::make_unique<Patterns::PackageIsUpgradable>(file); if (node->matches("?x-name-fnmatch", 1, 1)) return std::make_unique<APT::CacheFilter::PackageNameMatchesFnmatch>(aWord(node->arguments[0])); diff --git a/apt-pkg/cachefilter-patterns.h b/apt-pkg/cachefilter-patterns.h index 4c2ef48df..68ad32f9a 100644 --- a/apt-pkg/cachefilter-patterns.h +++ b/apt-pkg/cachefilter-patterns.h @@ -138,6 +138,41 @@ struct PackageIsGarbage : public PackageMatcher return (*Cache)[Pkg].Garbage; } }; + +struct PackageIsObsolete : public PackageMatcher +{ + bool operator()(pkgCache::PkgIterator const &pkg) override + { + // This code can be written without loops, as aptitude does, but it + // is far less readable. + if (pkg.CurrentVer().end()) + return false; + + // See if there is any version that exists in a repository, + // if so return false + for (auto ver = pkg.VersionList(); !ver.end(); ver++) + { + for (auto file = ver.FileList(); !file.end(); file++) + { + if ((file.File()->Flags & pkgCache::Flag::NotSource) == 0) + return false; + } + } + + return true; + } +}; + +struct PackageIsUpgradable : public PackageMatcher +{ + pkgCacheFile *Cache; + explicit PackageIsUpgradable(pkgCacheFile *Cache) : Cache(Cache) {} + bool operator()(pkgCache::PkgIterator const &Pkg) override + { + assert(Cache != nullptr); + return Pkg->CurrentVer != 0 && (*Cache)[Pkg].Upgradable(); + } +}; } // namespace Patterns } // namespace Internal } // namespace APT |