summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2024-07-05 17:06:39 +0000
committerJulian Andres Klode <jak@debian.org>2024-07-05 17:06:39 +0000
commit31100f35b97663a3d180bd57b616dcc5cb425795 (patch)
tree57c94b7a34d031319f4a4fd4c0764aa477450007
parent761852064521d9f34d3179c002427658342b6f03 (diff)
parentc575648f41ff09e72988976f8150e9bb51781cd4 (diff)
Merge branch 'print-installed-version-for-removed-packages' into 'main'
Show installed version (not candidate version) while removing a package See merge request apt-team/apt!362
-rw-r--r--apt-private/private-install.cc2
-rw-r--r--apt-private/private-output.cc10
-rw-r--r--apt-private/private-output.h2
-rwxr-xr-xtest/integration/test-apt-get-autoremove42
4 files changed, 54 insertions, 2 deletions
diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc
index 599caac6d..57b5c0d5e 100644
--- a/apt-private/private-install.cc
+++ b/apt-private/private-install.cc
@@ -729,7 +729,7 @@ bool DoAutomaticRemove(CacheFile &Cache)
"The following packages were automatically installed and are no longer required:",
autoRemoveCount), Universe,
[&Cache](pkgCache::PkgIterator const &Pkg) { return (*Cache)[Pkg].Garbage == true && (*Cache)[Pkg].Delete() == false; },
- &PrettyFullName, CandidateVersion(&Cache), "", note);
+ &PrettyFullName, CurrentVersion(&Cache), "", note);
}
else
{
diff --git a/apt-private/private-output.cc b/apt-private/private-output.cc
index 2e8109583..4a946f2b8 100644
--- a/apt-private/private-output.cc
+++ b/apt-private/private-output.cc
@@ -596,7 +596,7 @@ void ShowDel(ostream &out,CacheFile &Cache)
str.append("*");
return str;
},
- CandidateVersion(&Cache),
+ CurrentVersion(&Cache),
"action::remove");
}
/*}}}*/
@@ -888,6 +888,14 @@ std::string PrettyFullName(pkgCache::PkgIterator const &Pkg)
{
return Pkg.FullName(true);
}
+std::string CurrentVersion(pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg)
+{
+ return (*Cache)[Pkg].CurVersion;
+}
+std::function<std::string(pkgCache::PkgIterator const &)> CurrentVersion(pkgCacheFile * const Cache)
+{
+ return std::bind(static_cast<std::string(*)(pkgCacheFile * const, pkgCache::PkgIterator const&)>(&CurrentVersion), Cache, std::placeholders::_1);
+}
std::string CandidateVersion(pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg)
{
return (*Cache)[Pkg].CandVersion;
diff --git a/apt-private/private-output.h b/apt-private/private-output.h
index 0eba6f4fb..8e1d47225 100644
--- a/apt-private/private-output.h
+++ b/apt-private/private-output.h
@@ -132,6 +132,8 @@ APT_PUBLIC bool YnPrompt(char const *const Question, bool Default = true);
bool YnPrompt(char const * const Question, bool const Default, bool const ShowGlobalErrors, std::ostream &c1o, std::ostream &c2o);
APT_PUBLIC std::string PrettyFullName(pkgCache::PkgIterator const &Pkg);
+std::string CurrentVersion(pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg);
+std::function<std::string(pkgCache::PkgIterator const &)> CurrentVersion(pkgCacheFile * const Cache);
std::string CandidateVersion(pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg);
std::function<std::string(pkgCache::PkgIterator const &)> CandidateVersion(pkgCacheFile * const Cache);
std::string CurrentToCandidateVersion(pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg);
diff --git a/test/integration/test-apt-get-autoremove b/test/integration/test-apt-get-autoremove
index 9454df5c8..af474200d 100755
--- a/test/integration/test-apt-get-autoremove
+++ b/test/integration/test-apt-get-autoremove
@@ -264,3 +264,45 @@ Purg foo-plus-2 [1]' apt autopurge -s
testdpkgstatus 'pi' '1' 'unrelated'
testsuccess apt purge unrelated -y
+
+insertinstalledpackage 'foo-has-update' 'all' '1'
+insertpackage 'stable' 'foo-has-update' 'all' '2'
+testsuccess aptmark auto 'foo-has-update'
+
+setupaptarchive
+
+# Test removed package version (with -V flag), when package has update
+testsuccessequal 'Reading package lists...
+Building dependency tree...
+Reading state information...
+The following packages will be REMOVED:
+ foo-has-update (1)
+ foo-multi1-1 (1)
+ foo-multi1-2 (1)
+ foo-multi2-1 (1)
+ foo-multi2-2 (1)
+ foo-plus-1 (1)
+ foo-plus-2 (1)
+0 upgraded, 0 newly installed, 7 to remove and 0 not upgraded.
+Remv foo-has-update [1]
+Remv foo-multi1-1 [1]
+Remv foo-multi1-2 [1]
+Remv foo-multi2-1 [1]
+Remv foo-multi2-2 [1]
+Remv foo-plus-1 [1]
+Remv foo-plus-2 [1]' apt autoremove -sV
+
+# Test automatic removed package version (with -V flag), when package has update
+testsuccessequal "Reading package lists...
+Building dependency tree...
+Reading state information...
+The following packages were automatically installed and are no longer required:
+ foo-has-update (1)
+ foo-multi1-1 (1)
+ foo-multi1-2 (1)
+ foo-multi2-1 (1)
+ foo-multi2-2 (1)
+ foo-plus-1 (1)
+ foo-plus-2 (1)
+Use 'apt autoremove' to remove them.
+0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded." apt remove -sV