Gentoo Archives: gentoo-commits

From: Mike Frysinger <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage-utils:master commit in: man/, /, tests/qcheck/
Date: Mon, 22 Feb 2016 20:37:25
Message-Id: 1456160728.5331295005f585ec0ae1aea4dcfc4d10bc521a19.vapier@gentoo
1 commit: 5331295005f585ec0ae1aea4dcfc4d10bc521a19
2 Author: Mike Frysinger <vapier <AT> gentoo <DOT> org>
3 AuthorDate: Mon Feb 22 17:05:28 2016 +0000
4 Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org>
5 CommitDate: Mon Feb 22 17:05:28 2016 +0000
6 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=53312950
7
8 qcheck: change interface to operate on atoms
9
10 This drops the --exact flag as it's now redundant -- we always do
11 exact matching on the provided atoms.
12
13 We also drop the --all flag as it's now the default behavior. If
14 no atoms are specified, we just check everything.
15
16 man/qcheck.1 | 10 ++-----
17 qcheck.c | 85 ++++++++++++++++++++++-------------------------------
18 tests/qcheck/dotest | 10 +++----
19 3 files changed, 42 insertions(+), 63 deletions(-)
20
21 diff --git a/man/qcheck.1 b/man/qcheck.1
22 index 3633311..b686662 100644
23 --- a/man/qcheck.1
24 +++ b/man/qcheck.1
25 @@ -1,4 +1,4 @@
26 -.TH qcheck "1" "Mar 2014" "Gentoo Foundation" "qcheck"
27 +.TH qcheck "1" "Feb 2016" "Gentoo Foundation" "qcheck"
28 .SH NAME
29 qcheck \- verify integrity of installed packages
30 .SH SYNOPSIS
31 @@ -8,12 +8,6 @@ qcheck \- verify integrity of installed packages
32
33 .SH OPTIONS
34 .TP
35 -\fB\-a\fR, \fB\-\-all\fR
36 -List all packages
37 -.TP
38 -\fB\-e\fR, \fB\-\-exact\fR
39 -Exact match (only CAT/PN or PN without PV)
40 -.TP
41 \fB\-s\fR \fI<arg>\fR, \fB\-\-skip\fR \fI<arg>\fR
42 Ignore files matching the regular expression <arg>
43 .TP
44 @@ -32,7 +26,7 @@ Ignore differing/unknown file chksums
45 \fB\-T\fR, \fB\-\-nomtime\fR
46 Ignore differing file mtimes
47 .TP
48 -\fB\-\-skip\-protected\fR
49 +\fB\-P\fR, \fB\-\-skip\-protected\fR
50 Ignore files in CONFIG_PROTECT-ed paths
51 .TP
52 \fB\-p\fR, \fB\-\-prelink\fR
53
54 diff --git a/qcheck.c b/qcheck.c
55 index 3718f94..7f8031e 100644
56 --- a/qcheck.c
57 +++ b/qcheck.c
58 @@ -8,10 +8,8 @@
59
60 #ifdef APPLET_qcheck
61
62 -#define QCHECK_FLAGS "aes:uABHTPp" COMMON_FLAGS
63 +#define QCHECK_FLAGS "s:uABHTPp" COMMON_FLAGS
64 static struct option const qcheck_long_opts[] = {
65 - {"all", no_argument, NULL, 'a'},
66 - {"exact", no_argument, NULL, 'e'},
67 {"skip", a_argument, NULL, 's'},
68 {"update", no_argument, NULL, 'u'},
69 {"noafk", no_argument, NULL, 'A'},
70 @@ -23,8 +21,6 @@ static struct option const qcheck_long_opts[] = {
71 COMMON_LONG_OPTS
72 };
73 static const char * const qcheck_opts_help[] = {
74 - "List all packages",
75 - "Exact match (only CAT/PN or PN without PV)",
76 "Ignore files matching the regular expression <arg>",
77 "Update missing files, chksum and mtimes for packages",
78 "Ignore missing files",
79 @@ -40,18 +36,15 @@ static const char * const qcheck_opts_help[] = {
80 #define qcprintf(fmt, args...) do { if (!state->bad_only) printf(_(fmt), ## args); } while (0)
81
82 struct qcheck_opt_state {
83 - int argc;
84 - char **argv;
85 + array_t *atoms;
86 array_t *regex_arr;
87 bool bad_only;
88 - bool search_all;
89 bool qc_update;
90 bool chk_afk;
91 bool chk_hash;
92 bool chk_mtime;
93 bool chk_config_protect;
94 bool undo_prelink;
95 - bool exact;
96 };
97
98 static int qcheck_process_contents(q_vdb_pkg_ctx *pkg_ctx, struct qcheck_opt_state *state)
99 @@ -317,70 +310,51 @@ _q_static int qcheck_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
100 struct qcheck_opt_state *state = priv;
101 const char *catname = pkg_ctx->cat_ctx->name;
102 const char *pkgname = pkg_ctx->name;
103 + bool showit = false;
104
105 /* see if this cat/pkg is requested */
106 - if (!state->search_all) {
107 - char *buf = NULL;
108 - int i;
109 + if (array_cnt(state->atoms)) {
110 + char *buf;
111 + size_t i;
112 + depend_atom *qatom, *atom;
113
114 - for (i = optind; i < state->argc; ++i) {
115 - free(buf);
116 - xasprintf(&buf, "%s/%s", catname, pkgname);
117 - if (!state->exact) {
118 - if (rematch(state->argv[i], buf, REG_EXTENDED) == 0)
119 - break;
120 - if (rematch(state->argv[i], pkgname, REG_EXTENDED) == 0)
121 - break;
122 - } else {
123 - depend_atom *atom;
124 - char swap[_Q_PATH_MAX];
125 - if ((atom = atom_explode(buf)) == NULL) {
126 - warn("invalid atom %s", buf);
127 - continue;
128 - }
129 - snprintf(swap, sizeof(swap), "%s/%s", atom->CATEGORY, atom->PN);
130 - atom_implode(atom);
131 - if (strcmp(state->argv[i], swap) == 0 ||
132 - strcmp(state->argv[i], buf) == 0)
133 - break;
134 - if (strcmp(state->argv[i], strstr(swap, "/") + 1) == 0 ||
135 - strcmp(state->argv[i], strstr(buf, "/") + 1) == 0)
136 - break;
137 + xasprintf(&buf, "%s/%s", catname, pkgname);
138 + qatom = atom_explode(buf);
139 + array_for_each(state->atoms, i, atom)
140 + if (atom_compare(atom, qatom) == EQUAL) {
141 + showit = true;
142 + break;
143 }
144 - }
145 + atom_implode(qatom);
146 free(buf);
147 + } else
148 + showit = true;
149
150 - if (i == state->argc)
151 - return 0;
152 - }
153 -
154 - return qcheck_process_contents(pkg_ctx, priv);
155 + return showit ? qcheck_process_contents(pkg_ctx, priv) : 0;
156 }
157
158 int qcheck_main(int argc, char **argv)
159 {
160 - int i, ret;
161 + size_t i;
162 + int ret;
163 DECLARE_ARRAY(regex_arr);
164 + depend_atom *atom;
165 + DECLARE_ARRAY(atoms);
166 struct qcheck_opt_state state = {
167 - .argc = argc,
168 - .argv = argv,
169 + .atoms = atoms,
170 .regex_arr = regex_arr,
171 .bad_only = false,
172 - .search_all = false,
173 .qc_update = false,
174 .chk_afk = true,
175 .chk_hash = true,
176 .chk_mtime = true,
177 .chk_config_protect = true,
178 .undo_prelink = false,
179 - .exact = false,
180 };
181
182 while ((i = GETOPT_LONG(QCHECK, qcheck, "")) != -1) {
183 switch (i) {
184 COMMON_GETOPTS_CASES(qcheck)
185 - case 'a': state.search_all = true; break;
186 - case 'e': state.exact = true; break;
187 case 's': {
188 regex_t regex;
189 xregcomp(&regex, optarg, REG_EXTENDED|REG_NOSUB);
190 @@ -396,11 +370,22 @@ int qcheck_main(int argc, char **argv)
191 case 'p': state.undo_prelink = prelink_available(); break;
192 }
193 }
194 - if ((argc == optind) && !state.search_all)
195 - qcheck_usage(EXIT_FAILURE);
196 +
197 + argc -= optind;
198 + argv += optind;
199 + for (i = 0; i < argc; ++i) {
200 + atom = atom_explode(argv[i]);
201 + if (!atom)
202 + warn("invalid atom: %s", argv[i]);
203 + else
204 + xarraypush_ptr(atoms, atom);
205 + }
206
207 ret = q_vdb_foreach_pkg_sorted(qcheck_cb, &state);
208 xarrayfree(regex_arr);
209 + array_for_each(atoms, i, atom)
210 + atom_implode(atom);
211 + xarrayfree_int(atoms);
212 return ret;
213 }
214
215
216 diff --git a/tests/qcheck/dotest b/tests/qcheck/dotest
217 index a0e91fa..d7c337b 100755
218 --- a/tests/qcheck/dotest
219 +++ b/tests/qcheck/dotest
220 @@ -35,19 +35,19 @@ test 01 1 "qcheck a-b/pkg"
221 test 02 1 "qcheck a-b/pkg -s ^/missing-dir/.*"
222
223 # bad-only check
224 -test 03 1 "qcheck -Ba"
225 +test 03 1 "qcheck -B"
226
227 # hash mismatch ignore check
228 -test 04 1 "qcheck -Ha"
229 +test 04 1 "qcheck -H"
230
231 # mtime mismatch ignore check
232 -test 05 1 "qcheck -Ta"
233 +test 05 1 "qcheck -T"
234
235 # missing ignore check
236 -test 06 1 "qcheck -Aa"
237 +test 06 1 "qcheck -A"
238
239 # hash+mtime+missing mismatch ignore check
240 -test 07 0 "qcheck -AHTa"
241 +test 07 0 "qcheck -AHT"
242
243 # verbose check
244 test 08 1 "qcheck -v a-b/pkg"