diff options
| author | Julian Andres Klode <julian.klode@canonical.com> | 2025-02-03 13:07:37 +0100 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2025-02-03 12:40:37 +0000 |
| commit | c303750ecb89b7210fe998515432e358b3cc0cff (patch) | |
| tree | 52ad7bcd10f160a0724307d67ed888d1c80ebbed /apt-pkg/depcache.cc | |
| parent | 4137efbb2ec78bd3c8b8263ff20134d7fdc6f75b (diff) | |
Correctly calculate kernel size in /boot
Change the code to get the size from the existing vmlinuz,
rather than using the package size, which only worked in
Ubuntu, and possibly not on all kernel packages either.
Refactor the code a bit to avoid the nested if as well,
and use off_t to measure and sum the sizes before switching
to floating point.
Closes: #1085184
Diffstat (limited to 'apt-pkg/depcache.cc')
| -rw-r--r-- | apt-pkg/depcache.cc | 57 |
1 files changed, 25 insertions, 32 deletions
diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index fcc974ae3..c8999093b 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -2640,7 +2640,6 @@ bool pkgDepCache::PhasingApplied(pkgCache::PkgIterator Pkg) const // DepCache::BootSize /*{{{*/ double 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}) * 1.1 * BootCount; } /*}}}*/ |
