[pacman-dev] [PATCH v3] pacman -Si/-Qi: Autodetect best fitting file size unit

Florian Pritz bluewind at xinu.at
Sat Oct 19 05:47:11 EDT 2013


I've tracked this back to e223366 and it looks like this just forces KiB
because back then humanize_size didn't exist, but the size was just
divided by 1024 to keep it somewhat readable. When humanize_size got
introduced in 3c8a448 this was just carried over.

The unit detected for "Download Size" is reused for "Installed Size" to
make it easier to read.

Signed-off-by: Florian Pritz <bluewind at xinu.at>
---

v3:
- Autodetect size for "Installed" if it's the only one (-Qi doesn't display Download/Compressed)
- fix test suite

 src/pacman/package.c          | 7 +++++--
 test/pacman/tests/query006.py | 2 +-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/pacman/package.c b/src/pacman/package.c
index eab2873..9572615 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -165,16 +165,19 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra)
 	deplist_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg), cols);
 	deplist_display(_("Replaces       :"), alpm_pkg_get_replaces(pkg), cols);
 
-	size = humanize_size(alpm_pkg_get_size(pkg), 'K', 2, &label);
+	size = humanize_size(alpm_pkg_get_size(pkg), '\0', 2, &label);
 	if(from == ALPM_PKG_FROM_SYNCDB) {
 		printf("%s%s%s %6.2f %s\n", config->colstr.title, _("Download Size  :"),
 			config->colstr.nocolor, size, label);
 	} else if(from == ALPM_PKG_FROM_FILE) {
 		printf("%s%s%s %6.2f %s\n", config->colstr.title, _("Compressed Size:"),
 			config->colstr.nocolor, size, label);
+	} else {
+		// autodetect size for "Installed Size"
+		label = "\0";
 	}
 
-	size = humanize_size(alpm_pkg_get_isize(pkg), 'K', 2, &label);
+	size = humanize_size(alpm_pkg_get_isize(pkg), label[0], 2, &label);
 	printf("%s%s%s %6.2f %s\n", config->colstr.title, _("Installed Size :"),
 			config->colstr.nocolor, size, label);
 
diff --git a/test/pacman/tests/query006.py b/test/pacman/tests/query006.py
index 0f6f762..5defd87 100644
--- a/test/pacman/tests/query006.py
+++ b/test/pacman/tests/query006.py
@@ -20,7 +20,7 @@
 self.addrule("PACMAN_RETCODE=0")
 self.addrule("PACMAN_OUTPUT=^Name.*%s" % p.name)
 self.addrule("PACMAN_OUTPUT=^Description.*%s" % p.desc)
-self.addrule("PACMAN_OUTPUT=^Installed Size.*9765625.00 KiB")
+self.addrule("PACMAN_OUTPUT=^Installed Size.*9.31 GiB")
 self.addrule("PACMAN_OUTPUT=^Build Date.* 2065")
 self.addrule("PACMAN_OUTPUT=^Install Date.* 2286")
 
-- 
1.8.4


More information about the pacman-dev mailing list