Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 25 Jun 2008 13:17:39 GMT
From:      Anders Nore <andenore@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 144093 for review
Message-ID:  <200806251317.m5PDHdwP099430@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=144093

Change 144093 by andenore@andenore_laptop on 2008/06/25 13:16:58

	pkg_info -s option prints human readable output

Affected files ...

.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/CHANGES#3 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/pkg_info.1#2 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/show.c#4 edit

Differences ...

==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/CHANGES#3 (text+ko) ====

@@ -10,6 +10,8 @@
 	- Profiling showed that the default behavior for pkg_info was to read plist
 	  everytime even though not needed. Added check for this and speed improved
 	  significantly.
+	- Uses human readable output for -s (size option) I'm not sure if this breaks
+	  things, but it looks Ok. (The old output is available via the -b option)
 
 Add:
 	- Indexes information to dbcache according to the add

==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/pkg_info.1#2 (text+ko) ====

@@ -15,7 +15,7 @@
 .\"
 .\"
 .\"     @(#)pkg_info.1
-.\" $FreeBSD: src/usr.sbin/pkg_install/info/pkg_info.1,v 1.62 2007/12/09 11:01:58 krion Exp $
+.\" $FreeBSD: src/usr.sbin/pkg_install/info/pkg_info.1,v 1.60 2007/03/04 13:30:02 ru Exp $
 .\"
 .Dd January 9, 2006
 .Dt PKG_INFO 1
@@ -72,11 +72,7 @@
 .It Fl b
 Use the
 .Ev BLOCKSIZE
-environment variable for output even when the
-.Fl q
-or
-.Fl Q
-flag is present.
+environment variable for size output.
 .It Fl v
 Turn on verbose output.
 .It Fl p

==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/show.c#4 (text+ko) ====

@@ -29,6 +29,19 @@
 #include <sys/stat.h>
 #include <md5.h>
 
+char sizeTable[][4] = { "B", "kB", "MB", "GB", "TB" };
+
+unsigned int
+human_readable(unsigned int size, int *index)
+{
+	if (size >= 1024) {
+		*index = *index + 1;
+		return human_readable(size/1024, index);
+	}
+
+	return size;
+}
+
 void
 show_file(const char *title, const char *fname)
 {
@@ -250,67 +263,74 @@
 }
 
 /* Calculate and show size of all installed package files (except ignored ones) 
- * TODO: Make size easier to read (It should be unnecessary to set BLOCKSIZE in
- *       environment). If the files are static in size, maybe it could be cached
- *       instead of calculated every time. Could also be made default to show.
- * 	
  */
 void
 show_size(const char *title, Package *plist)
 {
-    PackingList p;
-    Boolean ign = FALSE;
-    const char *dir = ".";
-    struct stat sb;
-    char tmp[FILENAME_MAX];
-    unsigned long size = 0;
-    long blksize;
-    int headerlen;
-    char *descr;
-    char *prefix = NULL;
+	PackingList p;
+	Boolean ign = FALSE;
+	const char *dir = ".";
+	struct stat sb;
+	char tmp[FILENAME_MAX];
+	unsigned long size = 0;
+	long blksize;
+	int headerlen;
+	char *descr;
+	char *prefix = NULL;
+
+	descr = getbsize(&headerlen, &blksize);
+	if (!Quiet)
+		printf("%s%s", InfoPrefix, title);
 
-    descr = getbsize(&headerlen, &blksize);
-    if (!Quiet)
-	printf("%s%s", InfoPrefix, title);
-    for (p = plist->head; p != NULL; p = p->next) {
+	for (p = plist->head; p != NULL; p = p->next) {
 	switch (p->type) {
 	case PLIST_FILE:
-	    if (!ign) {
-		snprintf(tmp, FILENAME_MAX, "%s/%s", dir, p->name);
-		if (!lstat(tmp, &sb)) {
-		    size += sb.st_size;
-		    if (Verbose)
-			printf("%lu\t%s\n", (unsigned long) howmany(sb.st_size, blksize), tmp);
+		if (!ign) {
+			snprintf(tmp, FILENAME_MAX, "%s/%s", dir, p->name);
+			if (!lstat(tmp, &sb)) {
+				size += sb.st_size;
+
+				if (Verbose)
+					printf("%lu\t%s\n", 
+							(unsigned long) howmany(sb.st_size, blksize), tmp);
+			}
 		}
-	    }
-	    ign = FALSE;
-	    break;
+		ign = FALSE;
+		break;
 
 	case PLIST_CWD:
-	    if (!prefix)
-		prefix = p->name;
-	    if (p->name == NULL)
-		dir = prefix;
-	    else
-		dir = p->name;
-	    break;
+		if (!prefix)
+			prefix = p->name;
+
+		if (p->name == NULL)
+			dir = prefix;
+		else
+			dir = p->name;
+		break;
 
 	case PLIST_IGNORE:
-	    ign = TRUE;
-	    break;
+		ign = TRUE;
+		break;
 
 	/* Silence GCC in the -Wall mode */	    
 	default:
-	    break;
+		break;
+	}
 	}
-    }
-    if (!Quiet)
-	printf("%lu\t(%s)\n", howmany(size, blksize), descr);
-    else
-	if (UseBlkSz)
-		printf("%lu\n", howmany(size, blksize));
-	else
-		printf("%lu\n", size);
+	
+	if (!Quiet) {
+ 		if (UseBlkSz)
+			printf("%lu\t(%s)\n", howmany(size, blksize), descr);
+		else {
+			int index = 0;
+			printf("%lu ", human_readable(size, &index));
+			printf("%s\n", &sizeTable[index]);
+		}
+	} else
+		if (UseBlkSz)
+			printf("%lu\n", howmany(size, blksize));
+		else
+			printf("%lu\n", size);
 }
 
 /* Show files that don't match the recorded checksum */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200806251317.m5PDHdwP099430>