Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 8 May 2000 14:02:33 +0300 (EEST)
From:      "Maxim Sobolev" <sobomax@altavista.net>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/18445: [PATCH] Additional feature for pkg_info to quiery size of installed package
Message-ID:  <200005081102.OAA96090@vega.vega.com>

next in thread | raw e-mail | index | archive | help

>Number:         18445
>Category:       bin
>Synopsis:       [PATCH] Additional feature for pkg_info to quiery size of installed package
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon May 08 04:30:01 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Maxim Sobolev
>Release:        FreeBSD 3.4-STABLE i386
>Organization:
Vega International Capital
>Environment:

	

>Description:

Additional feature for pkg_info to quiery size of installed package.

I have really missed this feature since my first encounter with FreeBSD ;).

>How-To-Repeat:

	

>Fix:

===================================================================
RCS file: pkg_install/info/RCS/info.h,v
retrieving revision 1.1
diff -du -r1.1 pkg_install/info/info.h
--- pkg_install/info/info.h	2000/05/07 08:37:46	1.1
+++ pkg_install/info/info.h	2000/05/08 08:59:21
@@ -43,6 +43,7 @@
 #define SHOW_DISPLAY	0x0200
 #define SHOW_REQBY	0x0400
 #define SHOW_MTREE	0x0800
+#define SHOW_SIZE	0x1000
 
 extern int Flags;
 extern Boolean AllInstalled;
@@ -55,5 +56,6 @@
 extern void	show_plist(char *, Package *, plist_t);
 extern void	show_files(char *, Package *);
 extern void	show_index(char *, char *);
+extern void	show_size(char *, Package *);
 
 #endif	/* _INST_INFO_H_INCLUDE */
===================================================================
RCS file: pkg_install/info/RCS/main.c,v
retrieving revision 1.1
diff -du -r1.1 pkg_install/info/main.c
--- pkg_install/info/main.c	2000/05/07 08:37:46	1.1
+++ pkg_install/info/main.c	2000/05/07 09:07:35
@@ -28,7 +28,7 @@
   "$FreeBSD: src/usr.sbin/pkg_install/info/main.c,v 1.22 2000/01/18 01:45:54 dan Exp $";
 #endif
 
-static char Options[] = "acdDe:fhiIkl:LmpqrRt:v";
+static char Options[] = "acdDe:fhiIkl:LsmpqrRt:v";
 
 int	Flags		= 0;
 Boolean AllInstalled	= FALSE;
@@ -111,6 +111,10 @@
 	case 'm':
 	    Flags |= SHOW_MTREE;
 	    break;
+
+        case 's':
+            Flags |= SHOW_SIZE;
+            break;
 
 	case 'l':
 	    InfoPrefix = optarg;
===================================================================
RCS file: pkg_install/info/RCS/perform.c,v
retrieving revision 1.1
diff -du -r1.1 pkg_install/info/perform.c
--- pkg_install/info/perform.c	2000/05/07 08:37:46	1.1
+++ pkg_install/info/perform.c	2000/05/07 10:36:51
@@ -201,6 +201,8 @@
 	    show_plist("Prefix(s):\n", &plist, PLIST_CWD);
 	if (Flags & SHOW_FILES)
 	    show_files("Files:\n", &plist);
+	if ((Flags & SHOW_SIZE) && installed)
+	    show_size("Package Size:\n", &plist);
 	if (!Quiet)
 	    puts(InfoPrefix);
     }
===================================================================
RCS file: pkg_install/info/RCS/pkg_info.1,v
retrieving revision 1.1
diff -du -r1.1 pkg_install/info/pkg_info.1
--- pkg_install/info/pkg_info.1	2000/05/07 08:37:46	1.1
+++ pkg_install/info/pkg_info.1	2000/05/07 10:58:58
@@ -86,6 +86,8 @@
 Show the files within each package.  This is different from just
 viewing the packing list, since full pathnames for everything
 are generated.
+.It Fl s
+Show the total size occuped by files installed within each package.
 .It Fl e Ar pkg-name
 If the package identified by
 .Ar pkg-name
===================================================================
RCS file: pkg_install/info/RCS/show.c,v
retrieving revision 1.1
diff -du -r1.1 pkg_install/info/show.c
--- pkg_install/info/show.c	2000/05/07 08:37:46	1.1
+++ pkg_install/info/show.c	2000/05/07 13:58:38
@@ -27,6 +27,9 @@
 #include "info.h"
 
 #include <err.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 
 void
 show_file(char *title, char *fname)
@@ -195,7 +198,63 @@
 	case PLIST_IGNORE:
 	    ign = TRUE;
 	    break;
+
+        /* Silence GCC in the -Wall mode */
+        default:
+            break;
 	}
 	p = p->next;
     }
+}
+
+/* Calculate and show size of all installed package files (except ignored ones) */
+void
+show_size(char *title, Package *plist)
+{
+    PackingList p;
+    Boolean ign = FALSE;
+    char *dir = ".";
+    struct stat sb;
+    char tmp[FILENAME_MAX];
+    unsigned long size = 0;
+    long blksize;
+    int headerlen;
+    char *descr;
+
+    descr = getbsize(&headerlen, &blksize);
+    if (!Quiet)
+	printf("%s%s", InfoPrefix, title);
+    p = plist->head;
+    while (p) {
+	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)sb.st_size/blksize, tmp);
+                }
+            }
+	    ign = FALSE;
+	    break;
+
+	case PLIST_CWD:
+	    dir = p->name;
+	    break;
+
+	case PLIST_IGNORE:
+	    ign = TRUE;
+	    break;
+
+        /* Silence GCC in the -Wall mode */            
+        default:
+            break;
+	}
+	p = p->next;
+    }
+    if (!Quiet)
+        printf("%lu (%s)\n", size/blksize, descr);
+    else
+        printf("%lu\n", size);
 }


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


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




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