From f7e5ed3c8dffcdfc2c55c63f2e3cbcb390bbf013 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sat, 13 Apr 2024 20:27:48 +0200 Subject: Show space estimate for /boot, if separate; or estimate initrd for /usr Calculate an estimate of 110% of the biggest initrd + system.map as the additional space a kernel needs in /boot. If /boot is a different file system than /usr, print the size of the kernels + the additional space they will need separately; otherwise include it in our /usr figure. --- apt-pkg/depcache.cc | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ apt-pkg/depcache.h | 4 +++- apt-pkg/init.cc | 2 ++ 3 files changed, 61 insertions(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index e3e8d627c..76a5c09ba 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -42,6 +42,7 @@ #include #include #include +#include #include @@ -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; +} + /*}}}*/ diff --git a/apt-pkg/depcache.h b/apt-pkg/depcache.h index 5dd022b56..23047b97a 100644 --- a/apt-pkg/depcache.h +++ b/apt-pkg/depcache.h @@ -490,7 +490,9 @@ class APT_PUBLIC pkgDepCache : protected pkgCache::Namespace virtual ~pkgDepCache(); bool CheckConsistency(char const *const msgtag = ""); - +#ifdef APT_COMPILING_APT + double BootSize(bool initrdOnly); +#endif protected: // methods call by IsInstallOk bool IsInstallOkMultiArchSameVersionSynced(PkgIterator const &Pkg, diff --git a/apt-pkg/init.cc b/apt-pkg/init.cc index 75935404f..487f94f20 100644 --- a/apt-pkg/init.cc +++ b/apt-pkg/init.cc @@ -147,6 +147,8 @@ bool pkgInitConfig(Configuration &Cnf) // Configuration Cnf.CndSet("Dir::Etc", &CONF_DIR[1]); + Cnf.CndSet("Dir::Boot", "boot"); + Cnf.CndSet("Dir::Usr", "usr"); Cnf.CndSet("Dir::Etc::sourcelist","sources.list"); Cnf.CndSet("Dir::Etc::sourceparts","sources.list.d"); Cnf.CndSet("Dir::Etc::main","apt.conf"); -- cgit v1.2.3-70-g09d2 From ac8fe4b030754584cda9cb1707fc3d9f0d792366 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sat, 13 Apr 2024 23:59:41 +0200 Subject: apt: Use unicode install progress bar on UTF-8 locales This produces a much more appealing progress bar and it can even show parts of the progress being done. --- apt-pkg/install-progress.cc | 12 +++++++++++- test/libapt/install_progress_test.cc | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/install-progress.cc b/apt-pkg/install-progress.cc index 2b0dc21ea..fe3324426 100644 --- a/apt-pkg/install-progress.cc +++ b/apt-pkg/install-progress.cc @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -344,14 +345,23 @@ void PackageManagerFancy::Stop() std::string PackageManagerFancy::GetTextProgressStr(float Percent, int OutputSize) { + bool Unicode = strcmp(nl_langinfo(CODESET), "UTF-8") == 0; std::string output; if (unlikely(OutputSize < 3)) return output; int const BarSize = OutputSize - 2; // bar without the leading "[" and trailing "]" int const BarDone = std::max(0, std::min(BarSize, static_cast(std::floor(Percent * BarSize)))); + double dummy; + double const BarDoneFractional = std::modf(Percent * BarSize, &dummy); + const char *const BarDoneFractionalChar = (const char *[]){ + " ", "▏", "▎", "▍", "▌", "▋", "▊", "▉"}[static_cast(std::floor(BarDoneFractional * 8))]; output.append("["); - std::fill_n(std::fill_n(std::back_inserter(output), BarDone, '#'), BarSize - BarDone, '.'); + for (int i = 0; i < BarDone; i++) + output.append(Unicode ? "█" : "#"); + if (BarDone + 1 <= BarSize) + output.append(Unicode ? BarDoneFractionalChar : "."); + std::fill_n(std::back_inserter(output), BarSize - BarDone - 1, Unicode ? ' ' : '.'); output.append("]"); return output; } diff --git a/test/libapt/install_progress_test.cc b/test/libapt/install_progress_test.cc index 68101af9b..7015c619c 100644 --- a/test/libapt/install_progress_test.cc +++ b/test/libapt/install_progress_test.cc @@ -2,6 +2,7 @@ #include +#include #include #include @@ -10,6 +11,7 @@ TEST(InstallProgressTest, FancyGetTextProgressStr) { APT::Progress::PackageManagerFancy p; + char *originalLocale = setlocale(LC_ALL, "C"); EXPECT_EQ(60u, p.GetTextProgressStr(0.5, 60).size()); EXPECT_EQ("[#.]", p.GetTextProgressStr(0.5, 4)); EXPECT_EQ("[..........]", p.GetTextProgressStr(0.0, 12)); @@ -22,4 +24,22 @@ TEST(InstallProgressTest, FancyGetTextProgressStr) // deal with incorrect inputs gracefully (or should we die instead?) EXPECT_EQ("[..........]", p.GetTextProgressStr(-1.0, 12)); EXPECT_EQ("[##########]", p.GetTextProgressStr(2.0, 12)); + + setlocale(LC_ALL, "C.UTF-8"); + + EXPECT_EQ("[█ ]", p.GetTextProgressStr(0.5, 4)); + EXPECT_EQ("[ ]", p.GetTextProgressStr(0.0, 12)); + EXPECT_EQ("[█ ]", p.GetTextProgressStr(0.1, 12)); + EXPECT_EQ("[████ ]", p.GetTextProgressStr(0.4, 12)); + EXPECT_EQ("[████▉ ]", p.GetTextProgressStr(0.4999, 12)); + EXPECT_EQ("[█████ ]", p.GetTextProgressStr(0.5000, 12)); + EXPECT_EQ("[█████ ]", p.GetTextProgressStr(0.5001, 12)); + EXPECT_EQ("[█████████ ]", p.GetTextProgressStr(0.9001, 12)); + EXPECT_EQ("[██████████]", p.GetTextProgressStr(1.0, 12)); + + // deal with incorrect inputs gracefully (or should we die instead?) + EXPECT_EQ("[ ]", p.GetTextProgressStr(-1.0, 12)); + EXPECT_EQ("[██████████]", p.GetTextProgressStr(2.0, 12)); + + setlocale(LC_ALL, originalLocale); } -- cgit v1.2.3-70-g09d2