summaryrefslogtreecommitdiff
path: root/apt-pkg/algorithms.h
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2020-12-17 13:24:56 +0100
committerJulian Andres Klode <julian.klode@canonical.com>2021-01-04 10:46:48 +0100
commit04085f46dea9a95dd86123ac00187a63cc4ba2c0 (patch)
tree654ce33cec489562c663ddcf77dcd8a6a2b3f428 /apt-pkg/algorithms.h
parent290a4cf9455f45895718ed698147061fcd0a2dcb (diff)
Determine autoremovable kernels at run-time
Our kernel autoremoval helper script protects the currently booted kernel, but it only runs whenever we install or remove a kernel, causing it to protect the kernel that was booted at that point in time, which is not necessarily the same kernel as the one that is running right now. Reimplement the logic in C++ such that we can calculate it at run-time: Provide a function to produce a regular expression that matches all kernels that need protecting, and by changing the default root set function in the DepCache to make use of that expression. Note that the code groups the kernels by versions as before, and then marks all kernel packages with the same version. This optimized version inserts a virtual package $kernel into the cache when building it to avoid having to iterate over all packages in the cache to find the installed ones, significantly improving performance at a minor cost when building the cache. LP: #1615381
Diffstat (limited to 'apt-pkg/algorithms.h')
-rw-r--r--apt-pkg/algorithms.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/apt-pkg/algorithms.h b/apt-pkg/algorithms.h
index fc578a4ca..12a77d4b8 100644
--- a/apt-pkg/algorithms.h
+++ b/apt-pkg/algorithms.h
@@ -29,11 +29,13 @@
#ifndef PKGLIB_ALGORITHMS_H
#define PKGLIB_ALGORITHMS_H
+#include <apt-pkg/cachefilter.h>
#include <apt-pkg/depcache.h>
#include <apt-pkg/packagemanager.h>
#include <apt-pkg/pkgcache.h>
#include <iostream>
+#include <memory>
#include <string>
#include <apt-pkg/macros.h>
@@ -146,5 +148,17 @@ APT_PUBLIC bool pkgFixBroken(pkgDepCache &Cache);
APT_PUBLIC void pkgPrioSortList(pkgCache &Cache,pkgCache::Version **List);
+namespace APT
+{
+namespace KernelAutoRemoveHelper
+{
+// Public for linking to apt-private, but no A{P,B}I guarantee.
+APT_PUBLIC std::unique_ptr<APT::CacheFilter::Matcher> GetProtectedKernelsFilter(pkgCache *cache, bool returnRemove = false);
+std::string GetProtectedKernelsRegex(pkgCache *cache, bool ReturnRemove = false);
+std::string getUname(std::string const &packageName);
+
+} // namespace KernelAutoRemoveHelper
+
+} // namespace APT
#endif