summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2021-03-18 17:37:49 +0100
committerDavid Kalnischkies <david@kalnischkies.de>2021-04-26 13:00:24 +0200
commitd6f3458badf2cfea3ca7de7632ae31daff5742be (patch)
tree7acc19c1e590fe8c2c81ef6609fa1a5a863d90da /apt-pkg
parent9a54e70c1040379fb06827bacb461c61e341e694 (diff)
Call MarkAndSweep only manually in apt-get for autoremove
An interactive tool like aptitude needs these flags current far more often than we do as a user can see them in apt only in one very well defined place – the autoremove display block – so we don't need to run it up to four times while a normal "apt install" is processed as that is just busywork. The effect on runtime is minimal, as a single run doesn't take too long anyhow, but it cuts down tremendously on debug output at the expense of requiring some manual handholding. This is opt-in so that aptitude doesn't need to change nor do we need to change our own tools like "apt list" where it is working correctly as intended. A special flag and co is needed as we want to prevent the ActionGroup inside pkgDepCache::Init to be inhibited already so we need to insert ourselves while the DepCache is still in the process of being built. This is also the reason why the debug output in some tests changed to all unmarked, but that is fine as the marking could have been already obsoleted by the actions taken, just inhibited by a proper action group.
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/cachefile.cc7
-rw-r--r--apt-pkg/cachefile.h2
-rw-r--r--apt-pkg/depcache.cc34
-rw-r--r--apt-pkg/depcache.h5
4 files changed, 32 insertions, 16 deletions
diff --git a/apt-pkg/cachefile.cc b/apt-pkg/cachefile.cc
index 5355994d3..4c3cc9586 100644
--- a/apt-pkg/cachefile.cc
+++ b/apt-pkg/cachefile.cc
@@ -42,6 +42,7 @@
struct pkgCacheFile::Private
{
bool WithLock = false;
+ bool InhibitActionGroups = false;
};
// CacheFile::CacheFile - Constructor /*{{{*/
@@ -199,6 +200,8 @@ bool pkgCacheFile::BuildDepCache(OpProgress *Progress)
DCache.reset(new pkgDepCache(Cache,Policy));
if (_error->PendingError() == true)
return false;
+ if (d->InhibitActionGroups)
+ DCache->IncreaseActionGroupLevel();
if (DCache->Init(Progress) == false)
return false;
@@ -376,3 +379,7 @@ void pkgCacheFile::Close()
SrcList = NULL;
}
/*}}}*/
+void pkgCacheFile::InhibitActionGroups(bool const yes)
+{
+ d->InhibitActionGroups = yes;
+}
diff --git a/apt-pkg/cachefile.h b/apt-pkg/cachefile.h
index b24908216..4e26e6dab 100644
--- a/apt-pkg/cachefile.h
+++ b/apt-pkg/cachefile.h
@@ -69,6 +69,8 @@ class APT_PUBLIC pkgCacheFile
void Close();
bool AddIndexFile(pkgIndexFile * const File);
+ // Starts DepCache with a claim of one ActionGroup already active
+ void InhibitActionGroups(bool yes);
inline pkgCache* GetPkgCache() { BuildCaches(NULL, false); return Cache; };
inline pkgDepCache* GetDepCache() { BuildDepCache(); return DCache; };
diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc
index 13beeb713..a958e6c76 100644
--- a/apt-pkg/depcache.cc
+++ b/apt-pkg/depcache.cc
@@ -88,31 +88,35 @@ ConfigValueInSubTree(const char* SubTree, const char *needle)
pkgDepCache::ActionGroup::ActionGroup(pkgDepCache &cache) : /*{{{*/
d(NULL), cache(cache), released(false)
{
- ++cache.group_level;
+ cache.IncreaseActionGroupLevel();
}
void pkgDepCache::ActionGroup::release()
{
- if(!released)
- {
- if(cache.group_level == 0)
- std::cerr << "W: Unbalanced action groups, expect badness" << std::endl;
- else
- {
- --cache.group_level;
-
- if(cache.group_level == 0)
- cache.MarkAndSweep();
- }
-
- released = true;
- }
+ if(released)
+ return;
+ released = true;
+ if (cache.DecreaseActionGroupLevel() == 0)
+ cache.MarkAndSweep();
}
pkgDepCache::ActionGroup::~ActionGroup()
{
release();
}
+int pkgDepCache::IncreaseActionGroupLevel()
+{
+ return ++group_level;
+}
+int pkgDepCache::DecreaseActionGroupLevel()
+{
+ if(group_level == 0)
+ {
+ std::cerr << "W: Unbalanced action groups, expect badness\n";
+ return -1;
+ }
+ return --group_level;
+}
/*}}}*/
// DepCache::pkgDepCache - Constructors /*{{{*/
// ---------------------------------------------------------------------
diff --git a/apt-pkg/depcache.h b/apt-pkg/depcache.h
index 9a6019092..e0c5c4069 100644
--- a/apt-pkg/depcache.h
+++ b/apt-pkg/depcache.h
@@ -298,7 +298,10 @@ class APT_PUBLIC pkgDepCache : protected pkgCache::Namespace
int group_level;
friend class ActionGroup;
-
+ public:
+ int IncreaseActionGroupLevel();
+ int DecreaseActionGroupLevel();
+
protected:
// State information