1 |
commit: b61ddadded74e0e7d088999a627dd35ed2ebb92a |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Fri May 10 07:20:12 2019 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri May 10 07:20:12 2019 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=b61ddadd |
7 |
|
8 |
qfile: simply by using tree_get_atom and atom_format |
9 |
|
10 |
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> |
11 |
|
12 |
qfile.c | 75 +++++++++++++++++++++++++---------------------------------------- |
13 |
1 file changed, 29 insertions(+), 46 deletions(-) |
14 |
|
15 |
diff --git a/qfile.c b/qfile.c |
16 |
index c451ae4..116c7c4 100644 |
17 |
--- a/qfile.c |
18 |
+++ b/qfile.c |
19 |
@@ -78,11 +78,9 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv) |
20 |
{ |
21 |
struct qfile_opt_state *state = priv; |
22 |
const char *catname = pkg_ctx->cat_ctx->name; |
23 |
- const char *pkgname = pkg_ctx->name; |
24 |
qfile_args_t *args = &state->args; |
25 |
FILE *fp; |
26 |
const char *base; |
27 |
- char pkg[_Q_PATH_MAX]; |
28 |
depend_atom *atom = NULL; |
29 |
int i; |
30 |
bool path_ok; |
31 |
@@ -93,8 +91,6 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv) |
32 |
short *non_orphans = args->non_orphans; |
33 |
int found = 0; |
34 |
|
35 |
- snprintf(pkg, sizeof(pkg), "%s/%s", catname, pkgname); |
36 |
- |
37 |
/* If exclude_pkg is not NULL, check it. We are looking for files |
38 |
* collisions, and must exclude one package. |
39 |
*/ |
40 |
@@ -103,21 +99,15 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv) |
41 |
if (state->exclude_atom->CATEGORY && |
42 |
strcmp(state->exclude_atom->CATEGORY, catname)) |
43 |
goto dont_skip_pkg; |
44 |
- atom = atom_explode(pkg); |
45 |
- if (state->exclude_atom->PVR) { |
46 |
- /* see if PVR is exact match */ |
47 |
- if (strcmp(state->exclude_atom->PVR, atom->PVR)) |
48 |
- goto dont_skip_pkg; |
49 |
- } else { |
50 |
- /* see if PN is exact match */ |
51 |
- if (strcmp(state->exclude_atom->PN, atom->PN)) |
52 |
- goto dont_skip_pkg; |
53 |
- } |
54 |
+ atom = tree_get_atom(pkg_ctx, false); |
55 |
+ if (atom_compare(state->exclude_atom, atom) != EQUAL) |
56 |
+ goto dont_skip_pkg; |
57 |
+ /* "(CAT/)?(PN|PF)" matches, and no SLOT specified */ |
58 |
if (state->exclude_slot == NULL) |
59 |
- goto qlist_done; /* "(CAT/)?(PN|PF)" matches, and no SLOT specified */ |
60 |
- tree_pkg_vdb_eat(pkg_ctx, "SLOT", &state->buf, &state->buflen); |
61 |
- rmspace(state->buf); |
62 |
- if (strcmp(state->exclude_slot, state->buf) == 0) |
63 |
+ goto qlist_done; |
64 |
+ /* retrieve atom, this time with SLOT */ |
65 |
+ atom = tree_get_atom(pkg_ctx, true); |
66 |
+ if (strcmp(state->exclude_slot, atom->SLOT) == 0) |
67 |
goto qlist_done; /* "(CAT/)?(PN|PF):SLOT" matches */ |
68 |
} |
69 |
dont_skip_pkg: /* End of the package exclusion tests. */ |
70 |
@@ -134,11 +124,7 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv) |
71 |
if (!e) |
72 |
continue; |
73 |
|
74 |
- /* basename(3) possibly modifies e->name (if it has trailing |
75 |
- * slashes) but this is not likely since it comes from VDB which |
76 |
- * has normalised everything, so effectively e->name isn't |
77 |
- * touched, however, it /can/ return a pointer to a private |
78 |
- * allocation */ |
79 |
+ /* note: this is our own basename which doesn't modify its input */ |
80 |
base = basename(e->name); |
81 |
if (base < e->name || base > (e->name + strlen(e->name))) |
82 |
continue; |
83 |
@@ -163,8 +149,8 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv) |
84 |
path_ok = false; |
85 |
|
86 |
if (dir_names[i] && |
87 |
- strncmp(e->name, dir_names[i], dirname_len) == 0 && |
88 |
- dir_names[i][dirname_len] == '\0') |
89 |
+ strncmp(e->name, dir_names[i], dirname_len) == 0 && |
90 |
+ dir_names[i][dirname_len] == '\0') |
91 |
{ |
92 |
/* dir_name == dirname(CONTENTS) */ |
93 |
path_ok = true; |
94 |
@@ -185,8 +171,10 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv) |
95 |
_rpath = rpath + real_root_len; |
96 |
if (realpath(fullpath, rpath) == NULL) { |
97 |
if (verbose) { |
98 |
+ atom = tree_get_atom(pkg_ctx, false); |
99 |
warnp("Could not read real path of \"%s\" (from %s)", |
100 |
- fullpath, pkg); |
101 |
+ fullpath, |
102 |
+ atom_format("%[CATEGORY]%[PF]", atom, false)); |
103 |
warn("We'll never know whether \"%s\" was a result " |
104 |
"for your query...", e->name); |
105 |
} |
106 |
@@ -215,26 +203,24 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv) |
107 |
continue; |
108 |
|
109 |
if (non_orphans == NULL) { |
110 |
- char slot[126]; |
111 |
+ const char *fmt; |
112 |
+ |
113 |
+ atom = tree_get_atom(pkg_ctx, true); |
114 |
|
115 |
- if (!atom) { |
116 |
- if ((atom = atom_explode(pkg)) == NULL) { |
117 |
- warn("invalid atom %s", pkg); |
118 |
- continue; |
119 |
+ if (state->slotted) { |
120 |
+ if (verbose) { |
121 |
+ fmt = "%[CATEGORY]%[PF]%[SLOT]"; |
122 |
+ } else { |
123 |
+ fmt = "%[CATEGORY]%[PN]%[SLOT]"; |
124 |
+ } |
125 |
+ } else { |
126 |
+ if (verbose) { |
127 |
+ fmt = "%[CATEGORY]%[PF]"; |
128 |
+ } else { |
129 |
+ fmt = "%[CATEGORY]%[PN]"; |
130 |
} |
131 |
} |
132 |
- if (state->slotted) { |
133 |
- /* XXX: This assumes the buf is big enough. */ |
134 |
- char *slot_hack = slot + 1; |
135 |
- size_t slot_len = sizeof(slot) - 1; |
136 |
- tree_pkg_vdb_eat(pkg_ctx, "SLOT", &slot_hack, &slot_len); |
137 |
- rmspace(slot_hack); |
138 |
- slot[0] = ':'; |
139 |
- } else |
140 |
- slot[0] = '\0'; |
141 |
- printf("%s%s/%s%s%s%s", BOLD, atom->CATEGORY, BLUE, |
142 |
- (verbose ? pkg_ctx->name : atom->PN), |
143 |
- slot, NORM); |
144 |
+ printf("%s", atom_format(fmt, atom, false)); |
145 |
if (quiet) |
146 |
puts(""); |
147 |
else |
148 |
@@ -248,9 +234,6 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv) |
149 |
fclose(fp); |
150 |
|
151 |
qlist_done: |
152 |
- if (atom) |
153 |
- atom_implode(atom); |
154 |
- |
155 |
return found; |
156 |
} |