summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apt-pkg/depcache.cc59
-rw-r--r--apt-pkg/depcache.h2
-rw-r--r--apt-private/private-install.cc4
3 files changed, 29 insertions, 36 deletions
diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc
index fcc974ae3..ef93a54bb 100644
--- a/apt-pkg/depcache.cc
+++ b/apt-pkg/depcache.cc
@@ -2638,9 +2638,8 @@ bool pkgDepCache::PhasingApplied(pkgCache::PkgIterator Pkg) const
/*}}}*/
// DepCache::BootSize /*{{{*/
-double pkgDepCache::BootSize(bool initrdOnly)
+unsigned long long pkgDepCache::BootSize(bool initrdOnly)
{
- double BootSize = 0;
int BootCount = 0;
auto VirtualKernelPkg = FindPkg("$kernel", "any");
if (VirtualKernelPkg.end())
@@ -2650,44 +2649,38 @@ double pkgDepCache::BootSize(bool initrdOnly)
{
auto Pkg = Prv.OwnerPkg();
if ((*this)[Pkg].NewInstall())
- BootSize += (*this)[Pkg].InstallVer->InstalledSize, BootCount++;
+ 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;
+ if (not boot)
+ return 0;
- auto path = _config->FindDir("Dir::Boot") + ent->d_name;
+ enum
+ {
+ VMLINUZ,
+ INITRD,
+ MAP,
+ MAX_ARTEFACT,
+ } type;
+ off_t sizes[MAX_ARTEFACT]{};
+ while (struct dirent *ent = readdir(boot))
+ {
+ if (APT::String::Startswith(ent->d_name, "initrd.img-"))
+ type = INITRD;
+ else if (APT::String::Startswith(ent->d_name, "System.map-"))
+ type = MAP;
+ else if (not initrdOnly && APT::String::Startswith(ent->d_name, "vmlinuz-"))
+ type = VMLINUZ;
+ else
+ continue;
- 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;
+ if (struct stat st; fstatat(dirfd(boot), ent->d_name, &st, 0) == 0)
+ sizes[type] = std::max(sizes[type], st.st_size);
}
- return 0;
+ closedir(boot);
+ return std::accumulate(sizes, sizes + MAX_ARTEFACT, off_t{0}) * BootCount * 110 / 100;
}
/*}}}*/
diff --git a/apt-pkg/depcache.h b/apt-pkg/depcache.h
index 49ef4f441..8d50d6fc6 100644
--- a/apt-pkg/depcache.h
+++ b/apt-pkg/depcache.h
@@ -491,7 +491,7 @@ class APT_PUBLIC pkgDepCache : protected pkgCache::Namespace
bool CheckConsistency(char const *const msgtag = "");
#ifdef APT_COMPILING_APT
- double BootSize(bool initrdOnly);
+ unsigned long long BootSize(bool initrdOnly);
#endif
protected:
// methods call by IsInstallOk
diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc
index 3f05cf9fb..208a27749 100644
--- a/apt-private/private-install.cc
+++ b/apt-private/private-install.cc
@@ -348,8 +348,8 @@ bool InstallPackages(CacheFile &Cache, APT::PackageVector &HeldBackPackages, boo
if (statvfs(_config->FindDir("Dir::Usr").c_str(), &st) == 0)
{
struct statvfs st_boot;
- double BootSize = 0;
- double InitrdSize = 0;
+ unsigned long long BootSize = 0;
+ unsigned long long InitrdSize = 0;
if (statvfs(_config->FindDir("Dir::Boot").c_str(), &st_boot) == 0 && st_boot.f_fsid != st.f_fsid)
BootSize = Cache->BootSize(false);
else