Subject: bin/15683: Printing large sizes makes for poor usability
To: None <gnats-bugs@gnats.netbsd.org>
From: None <franklin@elfie.org>
List: netbsd-bugs
Date: 02/20/2002 12:25:09
>Number:         15683
>Category:       bin
>Synopsis:       Printing large sizes makes for poor usability
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Wed Feb 20 09:26:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     John Franklin
>Release:        NetBSD 1.5ZA
>Organization:
	
>Environment:
	
	
System: NetBSD deathmitten 1.5ZA NetBSD 1.5ZA (DM.MP) #1: Wed Feb 13 11:07:06 EST 2002 franklin@deathmitten:/usr/src/sys/arch/i386-MP/compile/DM.MP i386
Architecture: i386
Machine: i386
>Description:
	
	When the pkg_add program is unable to extract the files for 
installation because of a shortage of disk space it notifies the user 
with a message like this:

pkg_add: can't find enough temporary space to extract the files, please set your
PKG_TMPDIR environment variable to a location with at least 323394184 bytes
free

It's difficult to tell how many digits are in the byte count without 
locale-based separators or a magnatude suffix (K, M, G, T, etc.)  Instead 
it should say 323,394,184 bytes (or the proper locale equivalent) or 
divide it down and say 308.41M.  The latter makes more sense.  After 
all, do we really care exactly how many bytes we need?  Would we choose 
a different partition if it were 323,394,185 bytes?

>How-To-Repeat:
	
	set yoor PKG_TMPDIR to a directory on a partition with less that 300M.
	pkg_add openoffice-641.tgz 

>Fix:
	
This problem can't possibly be limited to pkg_add, and a more general 
solution should be implemented.  Perhaps a function in libc 
(const char* humanize(int64_t x), maybe?) or a macro would suffice.

For the time being, this patch improves the pkg programs:

===================================================================
RCS file: /cvsroot/basesrc/usr.sbin/pkg_install/lib/pen.c,v
retrieving revision 1.19
diff -u -r1.19 pen.c
--- pen.c       2001/01/05 03:27:28     1.19
+++ pen.c       2002/02/20 16:55:43
@@ -100,11 +100,30 @@
        else if (stat("/usr/tmp", &sb) != FAIL && min_free("/usr/tmp") >= sz)
                strcpy(pen, "/usr/tmp/instmp.XXXXXX");
        else {
+               float size;
+               char suffix;
+
                cleanup(0);
-               errx(2,
+               if (sz > 1<<30) {
+                       size = (float)sz / (1<<30);
+                       suffix = 'G';
+               }       else if (sz > 1<<20) {
+                       size = (float)sz / (1<<20);
+                       suffix = 'M';
+               }       else if (sz > 1<<10) {
+                       size = (float)sz / (1<<10);
+                       suffix = 'K';
+               } else {
+                       errx(2,
                    "can't find enough temporary space to extract the files, please set your\n"
                    "PKG_TMPDIR environment variable to a location with at least %lu bytes\n"
                    "free", (u_long) sz);
+                               return NULL;
+               }
+               errx(2,
+                   "can't find enough temporary space to extract the files, please set your\n"
+                   "PKG_TMPDIR environment variable to a location with at least %0.2f%c free",
+                               size, suffix);
                return NULL;
        }
        return pen;

>Release-Note:
>Audit-Trail:
>Unformatted: