summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorsobomax <sobomax@FreeBSD.org>2000-07-07 13:06:32 +0000
committersobomax <sobomax@FreeBSD.org>2000-07-07 13:06:32 +0000
commit30c9e3b784694031bf161baa87b1d79e24a009e3 (patch)
treea6b762aace5d250333bd3379d574900d50de041d /usr.sbin
parent1fcab4244d72f94a49fd8023d9fc08a69976dd2f (diff)
downloadFreeBSD-src-30c9e3b784694031bf161baa87b1d79e24a009e3.zip
FreeBSD-src-30c9e3b784694031bf161baa87b1d79e24a009e3.tar.gz
New option "-s" to query size of the installed package(s).
PR: 19445 Submitted by: sobomax Reviewed by: knu Approved by: silence
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/pkg_install/info/info.h2
-rw-r--r--usr.sbin/pkg_install/info/main.c6
-rw-r--r--usr.sbin/pkg_install/info/perform.c2
-rw-r--r--usr.sbin/pkg_install/info/pkg_info.14
-rw-r--r--usr.sbin/pkg_install/info/show.c57
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 7830cf6..d90ba22 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 8d1b451..9329bbe 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 f89e031..cbcb3d9 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 dc91012..8827328 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 a4e6266..6d638c6 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 <err.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
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);
+}
OpenPOWER on IntegriCloud