summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apt-pkg/depcache.cc33
-rw-r--r--apt-pkg/depcache.h6
-rwxr-xr-xtest/integration/test-apt-get-autoremove25
3 files changed, 48 insertions, 16 deletions
diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc
index 0f45fec90..7c016a5e7 100644
--- a/apt-pkg/depcache.cc
+++ b/apt-pkg/depcache.cc
@@ -1873,28 +1873,29 @@ bool pkgDepCache::MarkRequired(InRootSetFunc &userFunc)
if (PkgState[P->ID].Marked || IsPkgInBoringState(P, PkgState))
continue;
+ const char *reason = nullptr;
+
if ((PkgState[P->ID].Flags & Flag::Auto) == 0)
- ;
- else if ((P->Flags & Flag::Essential) || (P->Flags & Flag::Important))
- ;
- // be nice even then a required package violates the policy (#583517)
- // and do the full mark process also for required packages
+ reason = "Manual-Installed";
+ else if (P->Flags & Flag::Essential)
+ reason = "Essential";
+ else if (P->Flags & Flag::Important)
+ reason = "Important";
else if (P->CurrentVer != 0 && P.CurrentVer()->Priority == pkgCache::State::Required)
- ;
+ reason = "Required";
else if (userFunc.InRootSet(P))
- ;
- // packages which can't be changed (like holds) can't be garbage
+ reason = "Blacklisted [APT::NeverAutoRemove]";
else if (IsModeChangeOk(ModeGarbage, P, 0, false) == false)
- ;
+ reason = "Hold";
else
continue;
if (PkgState[P->ID].Install())
MarkPackage(P, PkgState[P->ID].InstVerIter(*this),
- follow_recommends, follow_suggests);
+ follow_recommends, follow_suggests, reason);
else
MarkPackage(P, P.CurrentVer(),
- follow_recommends, follow_suggests);
+ follow_recommends, follow_suggests, reason);
}
return true;
@@ -1904,7 +1905,8 @@ bool pkgDepCache::MarkRequired(InRootSetFunc &userFunc)
void pkgDepCache::MarkPackage(const pkgCache::PkgIterator &Pkg,
const pkgCache::VerIterator &Ver,
bool const &follow_recommends,
- bool const &follow_suggests)
+ bool const &follow_suggests,
+ const char *reason)
{
{
pkgDepCache::StateCache &state = PkgState[Pkg->ID];
@@ -1919,7 +1921,8 @@ void pkgDepCache::MarkPackage(const pkgCache::PkgIterator &Pkg,
bool const debug_autoremove = _config->FindB("Debug::pkgAutoRemove", false);
if(debug_autoremove)
- std::clog << "Marking: " << Pkg.FullName() << " " << Ver.VerStr() << std::endl;
+ std::clog << "Marking: " << Pkg.FullName() << " " << Ver.VerStr()
+ << " (" << reason << ")" << std::endl;
for (auto D = Ver.DependsList(); D.end() == false; ++D)
{
@@ -1976,7 +1979,7 @@ void pkgDepCache::MarkPackage(const pkgCache::PkgIterator &Pkg,
std::clog << "Following dep: " << APT::PrettyDep(this, D)
<< ", provided by " << PP.FullName() << " " << PV.VerStr()
<< " (" << providers.size() << "/" << prvsize << ")"<< std::endl;
- MarkPackage(PP, PV, follow_recommends, follow_suggests);
+ MarkPackage(PP, PV, follow_recommends, follow_suggests, "Provider");
}
}
@@ -1991,7 +1994,7 @@ void pkgDepCache::MarkPackage(const pkgCache::PkgIterator &Pkg,
if (debug_autoremove)
std::clog << "Following dep: " << APT::PrettyDep(this, D) << std::endl;
- MarkPackage(T, TV, follow_recommends, follow_suggests);
+ MarkPackage(T, TV, follow_recommends, follow_suggests, "Dependency");
}
}
/*}}}*/
diff --git a/apt-pkg/depcache.h b/apt-pkg/depcache.h
index 4536f3b52..724bf566e 100644
--- a/apt-pkg/depcache.h
+++ b/apt-pkg/depcache.h
@@ -88,11 +88,15 @@ class pkgDepCache : protected pkgCache::Namespace
*
* \param follow_suggests If \b true, suggestions of the package
* will be recursively marked.
+ *
+ * \param reason The reason why the package is being marked.
+ * (Used in logging when Debug::pkgAutoRemove is set.)
*/
APT_HIDDEN void MarkPackage(const pkgCache::PkgIterator &pkg,
const pkgCache::VerIterator &ver,
bool const &follow_recommends,
- bool const &follow_suggests);
+ bool const &follow_suggests,
+ const char *reason);
/** \brief Update the Marked field of all packages.
*
diff --git a/test/integration/test-apt-get-autoremove b/test/integration/test-apt-get-autoremove
index 6f3452fbd..4dba4f164 100755
--- a/test/integration/test-apt-get-autoremove
+++ b/test/integration/test-apt-get-autoremove
@@ -9,6 +9,12 @@ configarchitecture 'i386'
buildsimplenativepackage 'unrelated' 'all' '1' 'unstable'
buildsimplenativepackage 'po-debconf' 'all' '1.0.16' 'unstable'
buildsimplenativepackage 'debhelper' 'all' '8.0.0' 'unstable' 'Depends: po-debconf'
+buildsimplenativepackage 'base-files' 'all' '10' 'unstable' 'Essential: yes'
+buildsimplenativepackage 'fdisk' 'all' '2.30.2' 'unstable' 'XB-Important: yes'
+buildsimplenativepackage 'linux-image' 'all' '4.9.80' 'unstable'
+buildsimplenativepackage 'hold-me' 'all' '1.0' 'unstable'
+buildsimplenativepackage 'remove-me' 'all' '1.0' 'unstable'
+buildsimplenativepackage 'system-base' 'all' '1.0' 'unstable' 'Depends: unrelated, base-files, fdisk, linux-image, hold-me, remove-me'
setupaptarchive
testsuccess aptget install unrelated debhelper -y
@@ -158,6 +164,25 @@ testsuccess aptget install debhelper --solver apt -y -o Debug::pkgDepCache::Mark
testmarkedauto 'po-debconf'
testdpkgstatus 'pi' '1' 'unrelated'
+testsuccess aptget install system-base debhelper -y
+testdpkginstalled 'debhelper' 'po-debconf' 'system-base' 'base-files' 'fdisk' 'linux-image' 'hold-me' 'remove-me'
+testsuccess aptmark hold 'hold-me'
+echo 'APT::NeverAutoRemove { "^linux-image$"; };' > rootdir/etc/apt/apt.conf.d/00autoremove
+testsuccess aptget remove system-base -y
+testsuccess aptget autoremove -y -o Debug::pkgAutoRemove=yes
+DEBUGLOG=${TMPWORKINGDIRECTORY}/rootdir/tmp/autoremove.debuglog
+cp "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" "$DEBUGLOG"
+testsuccess grep -Fx 'Marking: fdisk:i386 2.30.2 (Important)' "$DEBUGLOG"
+testsuccess grep -Fx 'Marking: base-files:i386 10 (Essential)' "$DEBUGLOG"
+testsuccess grep -Fx 'Marking: unrelated:i386 1 (Manual-Installed)' "$DEBUGLOG"
+testsuccess grep -Fx 'Marking: hold-me:i386 1.0 (Hold)' "$DEBUGLOG"
+testsuccess grep -Fx 'Marking: po-debconf:i386 1.0.16 (Dependency)' "$DEBUGLOG"
+testsuccess grep -Fx 'Marking: linux-image:i386 4.9.80 (Blacklisted [APT::NeverAutoRemove])' "$DEBUGLOG"
+testdpkginstalled 'debhelper' 'po-debconf' 'base-files' 'fdisk' 'linux-image'
+testdpkgstatus 'hi' '1' 'hold-me'
+testdpkgnotinstalled 'remove-me'
+testdpkgstatus 'pi' '1' 'unrelated'
+
insertinstalledpackage 'bar' 'all' '1' 'Depends: foo-provider'
insertinstalledpackage 'foo-multi1-1' 'all' '1' 'Provides: foo-provider
Source: foo-multi (1)'