summaryrefslogtreecommitdiffstats
path: root/apt-pkg/depcache.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 19:05:54 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 19:05:54 +0000
commitf768fbfe45055f9ab5260ee04bb4c2706bfd6e44 (patch)
tree8b11d8fa50d831770d3eeb4d01abf67b9e598572 /apt-pkg/depcache.cc
parentAdding upstream version 2.9.0. (diff)
downloadapt-f768fbfe45055f9ab5260ee04bb4c2706bfd6e44.tar.xz
apt-f768fbfe45055f9ab5260ee04bb4c2706bfd6e44.zip
Adding upstream version 2.9.1.upstream/2.9.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'apt-pkg/depcache.cc')
-rw-r--r--apt-pkg/depcache.cc56
1 files changed, 56 insertions, 0 deletions
diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc
index e3e8d62..76a5c09 100644
--- a/apt-pkg/depcache.cc
+++ b/apt-pkg/depcache.cc
@@ -42,6 +42,7 @@
#include <unordered_map>
#include <utility>
#include <vector>
+#include <dirent.h>
#include <sys/stat.h>
@@ -2613,3 +2614,58 @@ bool pkgDepCache::PhasingApplied(pkgCache::PkgIterator Pkg) const
return true;
}
/*}}}*/
+
+// DepCache::BootSize /*{{{*/
+double pkgDepCache::BootSize(bool initrdOnly)
+{
+ double BootSize = 0;
+ int BootCount = 0;
+ auto VirtualKernelPkg = FindPkg("$kernel", "any");
+ if (VirtualKernelPkg.end())
+ return 0;
+
+ for (pkgCache::PrvIterator Prv = VirtualKernelPkg.ProvidesList(); Prv.end() == false; ++Prv)
+ {
+ auto Pkg = Prv.OwnerPkg();
+ if ((*this)[Pkg].NewInstall())
+ BootSize += (*this)[Pkg].InstallVer->InstalledSize, BootCount++;
+ }
+ if (BootCount == 0)
+ return 0;
+ if (initrdOnly)
+ BootSize = 0;
+
+ DIR *boot = opendir(_config->FindDir("Dir::Boot").c_str());
+ struct dirent *ent;
+ if (boot)
+ {
+ double initrdSize = 0;
+ double mapSize = 0;
+ while ((ent = readdir(boot)))
+ {
+ enum
+ {
+ INITRD,
+ MAP
+ } type;
+ if (APT::String::Startswith(ent->d_name, "initrd.img-"))
+ type = INITRD;
+ else if (APT::String::Startswith(ent->d_name, "System.map-"))
+ type = MAP;
+ else
+ continue;
+
+ auto path = _config->FindDir("Dir::Boot") + ent->d_name;
+
+ if (struct stat st; stat(path.c_str(), &st) == 0)
+ {
+ double &targetSize = type == INITRD ? initrdSize : mapSize;
+ targetSize = std::max(targetSize, double(st.st_size));
+ }
+ }
+ closedir(boot);
+ return initrdSize ? BootSize + BootCount * (initrdSize + mapSize) * 1.1 : 0;
+ }
+ return 0;
+}
+ /*}}}*/