mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-12-04 01:38:57 +00:00
New option "-s" to query size of the installed package(s).
PR: 19445 Submitted by: sobomax Reviewed by: knu Approved by: silence
This commit is contained in:
parent
7e154dad2e
commit
0f4dfa202e
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=62775
@ -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 */
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user