1 |
commit: dcec34fcf04c0399efc466adf770d60dc145129f |
2 |
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Feb 22 17:49:25 2016 +0000 |
4 |
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Feb 22 17:49:25 2016 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=dcec34fc |
7 |
|
8 |
qsize: change interface to operate on atoms |
9 |
|
10 |
We also drop the --all flag as it's now the default behavior. |
11 |
If no atoms are specified, we just check everything. |
12 |
|
13 |
man/qsize.1 | 5 +---- |
14 |
qsize.c | 49 ++++++++++++++++++++++++++++++++----------------- |
15 |
2 files changed, 33 insertions(+), 21 deletions(-) |
16 |
|
17 |
diff --git a/man/qsize.1 b/man/qsize.1 |
18 |
index ca6a352..af32869 100644 |
19 |
--- a/man/qsize.1 |
20 |
+++ b/man/qsize.1 |
21 |
@@ -1,4 +1,4 @@ |
22 |
-.TH qsize "1" "Mar 2014" "Gentoo Foundation" "qsize" |
23 |
+.TH qsize "1" "Feb 2016" "Gentoo Foundation" "qsize" |
24 |
.SH NAME |
25 |
qsize \- calculate size usage |
26 |
.SH SYNOPSIS |
27 |
@@ -11,9 +11,6 @@ qsize \- calculate size usage |
28 |
\fB\-f\fR, \fB\-\-filesystem\fR |
29 |
Show size used on disk |
30 |
.TP |
31 |
-\fB\-a\fR, \fB\-\-all\fR |
32 |
-Size all installed packages |
33 |
-.TP |
34 |
\fB\-s\fR, \fB\-\-sum\fR |
35 |
Include a summary |
36 |
.TP |
37 |
|
38 |
diff --git a/qsize.c b/qsize.c |
39 |
index 3a11842..7a40141 100644 |
40 |
--- a/qsize.c |
41 |
+++ b/qsize.c |
42 |
@@ -8,10 +8,9 @@ |
43 |
|
44 |
#ifdef APPLET_qsize |
45 |
|
46 |
-#define QSIZE_FLAGS "fasSmkbi:" COMMON_FLAGS |
47 |
+#define QSIZE_FLAGS "fsSmkbi:" COMMON_FLAGS |
48 |
static struct option const qsize_long_opts[] = { |
49 |
{"filesystem", no_argument, NULL, 'f'}, |
50 |
- {"all", no_argument, NULL, 'a'}, |
51 |
{"sum", no_argument, NULL, 's'}, |
52 |
{"sum-only", no_argument, NULL, 'S'}, |
53 |
{"megabytes", no_argument, NULL, 'm'}, |
54 |
@@ -22,7 +21,6 @@ static struct option const qsize_long_opts[] = { |
55 |
}; |
56 |
static const char * const qsize_opts_help[] = { |
57 |
"Show size used on disk", |
58 |
- "Size all installed packages", |
59 |
"Include a summary", |
60 |
"Show just the summary", |
61 |
"Display size in megabytes", |
62 |
@@ -39,7 +37,6 @@ int qsize_main(int argc, char **argv) |
63 |
q_vdb_cat_ctx *cat_ctx; |
64 |
q_vdb_pkg_ctx *pkg_ctx; |
65 |
size_t i; |
66 |
- char search_all = 0; |
67 |
struct stat st; |
68 |
char fs_size = 0, summary = 0, summary_only = 0; |
69 |
size_t num_all_files, num_all_nonfiles, num_all_ignored; |
70 |
@@ -50,13 +47,14 @@ int qsize_main(int argc, char **argv) |
71 |
size_t buflen; |
72 |
char *buf; |
73 |
char filename[_Q_PATH_MAX], *filename_root; |
74 |
+ depend_atom *atom; |
75 |
+ DECLARE_ARRAY(atoms); |
76 |
DECLARE_ARRAY(ignore_regexp); |
77 |
|
78 |
while ((i = GETOPT_LONG(QSIZE, qsize, "")) != -1) { |
79 |
switch (i) { |
80 |
COMMON_GETOPTS_CASES(qsize) |
81 |
case 'f': fs_size = 1; break; |
82 |
- case 'a': search_all = 1; break; |
83 |
case 's': summary = 1; break; |
84 |
case 'S': summary = summary_only = 1; break; |
85 |
case 'm': disp_units = MEGABYTE; str_disp_units = "MiB"; break; |
86 |
@@ -70,8 +68,16 @@ int qsize_main(int argc, char **argv) |
87 |
} |
88 |
} |
89 |
} |
90 |
- if ((argc == optind) && !search_all) |
91 |
- qsize_usage(EXIT_FAILURE); |
92 |
+ |
93 |
+ argc -= optind; |
94 |
+ argv += optind; |
95 |
+ for (i = 0; i < argc; ++i) { |
96 |
+ atom = atom_explode(argv[i]); |
97 |
+ if (!atom) |
98 |
+ warn("invalid atom: %s", argv[i]); |
99 |
+ else |
100 |
+ xarraypush_ptr(atoms, atom); |
101 |
+ } |
102 |
|
103 |
num_all_bytes = num_all_files = num_all_nonfiles = num_all_ignored = 0; |
104 |
|
105 |
@@ -91,18 +97,24 @@ int qsize_main(int argc, char **argv) |
106 |
while ((pkg_ctx = q_vdb_next_pkg(cat_ctx))) { |
107 |
const char *pkgname = pkg_ctx->name; |
108 |
FILE *fp; |
109 |
+ bool showit = false; |
110 |
+ |
111 |
/* see if this cat/pkg is requested */ |
112 |
- if (!search_all) { |
113 |
- for (i = optind; i < argc; ++i) { |
114 |
- snprintf(buf, buflen, "%s/%s", catname, pkgname); |
115 |
- if (rematch(argv[i], buf, REG_EXTENDED) == 0) |
116 |
+ if (array_cnt(atoms)) { |
117 |
+ depend_atom *qatom; |
118 |
+ |
119 |
+ snprintf(buf, buflen, "%s/%s", catname, pkgname); |
120 |
+ qatom = atom_explode(buf); |
121 |
+ array_for_each(atoms, i, atom) |
122 |
+ if (atom_compare(atom, qatom) == EQUAL) { |
123 |
+ showit = true; |
124 |
break; |
125 |
- if (rematch(argv[i], pkgname, REG_EXTENDED) == 0) |
126 |
- break; |
127 |
- } |
128 |
- if (i == argc) |
129 |
- goto next_pkg; |
130 |
- } |
131 |
+ } |
132 |
+ atom_implode(qatom); |
133 |
+ } else |
134 |
+ showit = true; |
135 |
+ if (!showit) |
136 |
+ goto next_pkg; |
137 |
|
138 |
if ((fp = q_vdb_pkg_fopenat_ro(pkg_ctx, "CONTENTS")) == NULL) |
139 |
goto next_pkg; |
140 |
@@ -178,6 +190,9 @@ int qsize_main(int argc, char **argv) |
141 |
decimal_point, |
142 |
(unsigned long)(((num_all_bytes%MEGABYTE)*1000)/MEGABYTE)); |
143 |
} |
144 |
+ array_for_each(atoms, i, atom) |
145 |
+ atom_implode(atom); |
146 |
+ xarrayfree_int(atoms); |
147 |
xarrayfree(ignore_regexp); |
148 |
return EXIT_SUCCESS; |
149 |
} |