From 10755b590311356ecdaa38dbfdf552b6b8fdaddc Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 26 Feb 2025 12:18:02 +0100 Subject: refactor obsolete checks to use VerFileIterator::Downloadable() --- apt-pkg/cachefilter-patterns.h | 7 ++----- apt-pkg/solver3.cc | 11 +++++------ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/apt-pkg/cachefilter-patterns.h b/apt-pkg/cachefilter-patterns.h index 07b7ac61b..8d8a62a9f 100644 --- a/apt-pkg/cachefilter-patterns.h +++ b/apt-pkg/cachefilter-patterns.h @@ -249,11 +249,8 @@ struct APT_HIDDEN PackageIsObsolete : public PackageMatcher // 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; - } + if (ver.Downloadable()) + return false; } return true; diff --git a/apt-pkg/solver3.cc b/apt-pkg/solver3.cc index 7117296ab..c1a1098b5 100644 --- a/apt-pkg/solver3.cc +++ b/apt-pkg/solver3.cc @@ -336,12 +336,11 @@ bool APT::Solver::Obsolete(pkgCache::PkgIterator pkg) const if (ObsoletedByNewerSourceVersion(ver)) return true; - for (auto file = ver.FileList(); !file.end(); file++) - if ((file.File()->Flags & pkgCache::Flag::NotSource) == 0) - { - pkgObsolete[pkg] = 1; - return false; - } + if (ver.Downloadable()) + { + pkgObsolete[pkg] = 1; + return false; + } if (debug >= 3) std::cerr << "Obsolete: " << ver.ParentPkg().FullName() << "=" << ver.VerStr() << " - not installable\n"; pkgObsolete[pkg] = 2; -- cgit v1.2.3-70-g09d2 From b33677749142e0997121d358277b18136bdbef87 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 26 Feb 2025 12:18:39 +0100 Subject: Consider 0-size debs not downloadable, set a size in EDSP EDSP dumps all appear as a single file, so we cannot determine correctly if a package is obsolete. We can fix this by ensuring that only debs with a size are downloadable, and then by faking a size in EDSP: The size is 1 if APT-Release is set (there is a source to download it from) or 0 otherwise. This ensures that the obsolete logic in solver3 works correctly, as well as the obsolete patterns, if anyone could actually use it on the EDSP files. --- apt-pkg/edsp/edsplistparser.cc | 2 ++ apt-pkg/pkgcache.cc | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/apt-pkg/edsp/edsplistparser.cc b/apt-pkg/edsp/edsplistparser.cc index f591a6a54..14967e110 100644 --- a/apt-pkg/edsp/edsplistparser.cc +++ b/apt-pkg/edsp/edsplistparser.cc @@ -56,6 +56,8 @@ bool edspLikeListParser::NewVersion(pkgCache::VerIterator &Ver) } } + // Fake a size such that the deb appears downloadable if it has a source + Ver->Size = Section.Exists("APT-Release"); return true; } /*}}}*/ diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index a27b1b054..4101fb4e5 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -864,6 +864,10 @@ int pkgCache::VerIterator::CompareVer(const VerIterator &B) const /* */ APT_PURE bool pkgCache::VerIterator::Downloadable() const { + // A zero size deb is not downloadable + if (S->Size == 0) + return false; + VerFileIterator Files = FileList(); for (; Files.end() == false; ++Files) if (Files.File().Flagged(pkgCache::Flag::NotSource) == false) -- cgit v1.2.3-70-g09d2 From 45b04762e1990a761a7c308f9e73a286a92f908a Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 3 Mar 2025 11:20:52 +0100 Subject: edsp: Write 'Size' to the EDSP files This allows solvers to optimize by download size; and gives us a better means of interpreting "downloadable" debs (they must have a size > 0 after all). --- apt-pkg/edsp.cc | 2 ++ apt-pkg/edsp/edsplistparser.cc | 7 +++++-- test/integration/test-external-dependency-solver-protocol | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/apt-pkg/edsp.cc b/apt-pkg/edsp.cc index 6e02369c9..196f9d307 100644 --- a/apt-pkg/edsp.cc +++ b/apt-pkg/edsp.cc @@ -243,6 +243,8 @@ static bool WriteScenarioEDSPVersion(pkgDepCache &Cache, FileFd &output, pkgCach WriteOkay(Okay, output, "\nPriority: ", Prio); if (Ver->Section != 0) WriteOkay(Okay, output, "\nSection: ", Ver.Section()); + if (Ver->Size != 0) + WriteOkay(Okay, output, "\nSize: ", Ver->Size); if (Pkg.CurrentVer() == Ver) WriteOkay(Okay, output, "\nInstalled: yes"); if (Pkg->SelectedState == pkgCache::State::Hold || diff --git a/apt-pkg/edsp/edsplistparser.cc b/apt-pkg/edsp/edsplistparser.cc index 14967e110..a3cdf794f 100644 --- a/apt-pkg/edsp/edsplistparser.cc +++ b/apt-pkg/edsp/edsplistparser.cc @@ -56,8 +56,11 @@ bool edspLikeListParser::NewVersion(pkgCache::VerIterator &Ver) } } - // Fake a size such that the deb appears downloadable if it has a source - Ver->Size = Section.Exists("APT-Release"); + // If we have a Size field, use it, otherwise fake one based on APT-Release to + // be able to distinguish downloadable debs from installed ones. + Ver->Size = Section.Exists(pkgTagSection::Key::Size) + ? Section.FindI(pkgTagSection::Key::Size) + : Section.Exists("APT-Release"); return true; } /*}}}*/ diff --git a/test/integration/test-external-dependency-solver-protocol b/test/integration/test-external-dependency-solver-protocol index 81204fc19..bc32886c5 100755 --- a/test/integration/test-external-dependency-solver-protocol +++ b/test/integration/test-external-dependency-solver-protocol @@ -189,6 +189,7 @@ Source: stuff Source-Version: 3 Priority: optional Section: other +Size: 42 APT-Release: a=experimental,n=experimental,c=main,b=all APT-Pin: 1 @@ -202,6 +203,7 @@ Source: stuff Source-Version: 2 Priority: optional Section: other +Size: 42 APT-Release: a=unstable,n=sid,c=main,b=all APT-Pin: 500 -- cgit v1.2.3-70-g09d2