From 0f4dfa202e77c5c40511edb365881f3d68aeada6 Mon Sep 17 00:00:00 2001 From: Maxim Sobolev Date: Fri, 7 Jul 2000 13:06:32 +0000 Subject: [PATCH] New option "-s" to query size of the installed package(s). PR: 19445 Submitted by: sobomax Reviewed by: knu Approved by: silence --- usr.sbin/pkg_install/info/info.h | 2 + usr.sbin/pkg_install/info/main.c | 6 ++- usr.sbin/pkg_install/info/perform.c | 2 + usr.sbin/pkg_install/info/pkg_info.1 | 4 +- usr.sbin/pkg_install/info/show.c | 57 ++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 2 deletions(-) diff --git a/usr.sbin/pkg_install/info/info.h b/usr.sbin/pkg_install/info/info.h index 7830cf6ce23..d90ba220352 100644 --- a/usr.sbin/pkg_install/info/info.h +++ b/usr.sbin/pkg_install/info/info.h @@ -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_file(char *, char *); 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 */ diff --git a/usr.sbin/pkg_install/info/main.c b/usr.sbin/pkg_install/info/main.c index 8d1b451deec..9329bbe8bae 100644 --- a/usr.sbin/pkg_install/info/main.c +++ b/usr.sbin/pkg_install/info/main.c @@ -28,7 +28,7 @@ static const char rcsid[] = "$FreeBSD$"; #endif -static char Options[] = "acdDe:fhiIkl:LmpqrRt:v"; +static char Options[] = "acdDe:fhiIkl:LmpqrRst:v"; int Flags = 0; Boolean AllInstalled = FALSE; @@ -112,6 +112,10 @@ main(int argc, char **argv) Flags |= SHOW_MTREE; break; + case 's': + Flags |= SHOW_SIZE; + break; + case 'l': InfoPrefix = optarg; break; diff --git a/usr.sbin/pkg_install/info/perform.c b/usr.sbin/pkg_install/info/perform.c index f89e031a857..cbcb3d95b45 100644 --- a/usr.sbin/pkg_install/info/perform.c +++ b/usr.sbin/pkg_install/info/perform.c @@ -201,6 +201,8 @@ pkg_do(char *pkg) 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); } diff --git a/usr.sbin/pkg_install/info/pkg_info.1 b/usr.sbin/pkg_install/info/pkg_info.1 index dc91012fb2e..88273285399 100644 --- a/usr.sbin/pkg_install/info/pkg_info.1 +++ b/usr.sbin/pkg_install/info/pkg_info.1 @@ -25,7 +25,7 @@ .Nd a utility for displaying information on software packages .Sh SYNOPSIS .Nm pkg_info -.Op Fl cdDfikrRpLqImv +.Op Fl cdDfikrRpLsqImv .Op Fl e Ar package .Op Fl l Ar prefix .Op Fl t Ar template @@ -86,6 +86,8 @@ Show the mtree file (if any) for each package. 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 diff --git a/usr.sbin/pkg_install/info/show.c b/usr.sbin/pkg_install/info/show.c index a4e62662212..6d638c6a2c4 100644 --- a/usr.sbin/pkg_install/info/show.c +++ b/usr.sbin/pkg_install/info/show.c @@ -27,6 +27,9 @@ static const char rcsid[] = #include "info.h" #include +#include +#include +#include void show_file(char *title, char *fname) @@ -195,7 +198,61 @@ show_files(char *title, Package *plist) 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); + 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); + } + } + ign = FALSE; + break; + + case PLIST_CWD: + dir = p->name; + break; + + case PLIST_IGNORE: + ign = TRUE; + break; + + /* Silence GCC in the -Wall mode */ + default: + break; + } + } + if (!Quiet) + printf("%lu\t(%s)\n", howmany(size, blksize), descr); + else + printf("%lu\n", size); +} -- 2.45.2