1 |
commit: 08894d7dedab849f27145f2f3d3fe5dee6796d21 |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Jun 23 07:13:35 2021 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Jun 23 07:13:35 2021 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=08894d7d |
7 |
|
8 |
quse: make return code reflect whether a match was made |
9 |
|
10 |
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> |
11 |
|
12 |
quse.c | 33 ++++++++++++++++++++++----------- |
13 |
1 file changed, 22 insertions(+), 11 deletions(-) |
14 |
|
15 |
diff --git a/quse.c b/quse.c |
16 |
index 5105638..400339a 100644 |
17 |
--- a/quse.c |
18 |
+++ b/quse.c |
19 |
@@ -400,23 +400,26 @@ quse_search_profiles_desc( |
20 |
return ret; |
21 |
} |
22 |
|
23 |
-static void |
24 |
+static bool |
25 |
quse_describe_flag(const char *root, const char *overlay, |
26 |
struct quse_state *state) |
27 |
{ |
28 |
char buf[_Q_PATH_MAX]; |
29 |
int portdirfd; |
30 |
+ bool ret = false; |
31 |
|
32 |
snprintf(buf, sizeof(buf), "%s/%s", root, overlay); |
33 |
portdirfd = open(buf, O_RDONLY|O_CLOEXEC|O_PATH); |
34 |
if (portdirfd == -1) |
35 |
- return; |
36 |
+ return false; |
37 |
|
38 |
- quse_search_use_desc(portdirfd, state); |
39 |
- quse_search_use_local_desc(portdirfd, state); |
40 |
- quse_search_profiles_desc(portdirfd, state); |
41 |
+ ret |= quse_search_use_desc(portdirfd, state); |
42 |
+ ret |= quse_search_use_local_desc(portdirfd, state); |
43 |
+ ret |= quse_search_profiles_desc(portdirfd, state); |
44 |
|
45 |
close(portdirfd); |
46 |
+ |
47 |
+ return ret; |
48 |
} |
49 |
|
50 |
static int |
51 |
@@ -437,6 +440,7 @@ quse_results_cb(tree_pkg_ctx *pkg_ctx, void *priv) |
52 |
int maxlen; |
53 |
int cnt; |
54 |
int portdirfd = -1; /* pacify compiler */ |
55 |
+ int ret = 0; |
56 |
|
57 |
if (state->match || state->do_describe) { |
58 |
atom = tree_get_atom(pkg_ctx, false); |
59 |
@@ -538,6 +542,7 @@ quse_results_cb(tree_pkg_ctx *pkg_ctx, void *priv) |
60 |
} |
61 |
|
62 |
if (match) { |
63 |
+ ret++; |
64 |
atom = tree_get_atom(pkg_ctx, state->need_full_atom); |
65 |
if (quiet) { |
66 |
printf("%s\n", atom_format(state->fmt, atom)); |
67 |
@@ -648,12 +653,13 @@ quse_results_cb(tree_pkg_ctx *pkg_ctx, void *priv) |
68 |
if (state->do_describe && !state->do_licence) |
69 |
close(portdirfd); |
70 |
|
71 |
- return EXIT_SUCCESS; |
72 |
+ return ret; |
73 |
} |
74 |
|
75 |
int quse_main(int argc, char **argv) |
76 |
{ |
77 |
int i; |
78 |
+ int ret; |
79 |
size_t n; |
80 |
const char *overlay; |
81 |
char *match = NULL; |
82 |
@@ -719,6 +725,7 @@ int quse_main(int argc, char **argv) |
83 |
state.fmt = "%[CATEGORY]%[PN]"; |
84 |
} |
85 |
|
86 |
+ ret = EXIT_FAILURE; |
87 |
if (state.do_describe && state.match == NULL) { |
88 |
array_for_each(overlays, n, overlay) { |
89 |
tree_ctx *t = NULL; |
90 |
@@ -726,7 +733,8 @@ int quse_main(int argc, char **argv) |
91 |
t = tree_open(portroot, overlay); /* used for repo */ |
92 |
if (t != NULL) |
93 |
state.repo = t->repo; |
94 |
- quse_describe_flag(portroot, overlay, &state); |
95 |
+ if (quse_describe_flag(portroot, overlay, &state)) |
96 |
+ ret = EXIT_SUCCESS; |
97 |
if (t != NULL) |
98 |
tree_close(t); |
99 |
} |
100 |
@@ -735,7 +743,9 @@ int quse_main(int argc, char **argv) |
101 |
if (t != NULL) { |
102 |
state.overlay = NULL; |
103 |
state.repo = NULL; |
104 |
- tree_foreach_pkg_sorted(t, quse_results_cb, &state, state.match); |
105 |
+ if (tree_foreach_pkg_sorted(t, quse_results_cb, |
106 |
+ &state, state.match) > 0) |
107 |
+ ret = EXIT_SUCCESS; |
108 |
tree_close(t); |
109 |
} |
110 |
} else { |
111 |
@@ -744,8 +754,9 @@ int quse_main(int argc, char **argv) |
112 |
state.overlay = overlay; |
113 |
if (t != NULL) { |
114 |
state.repo = state.need_full_atom ? t->repo : NULL; |
115 |
- tree_foreach_pkg_sorted(t, quse_results_cb, |
116 |
- &state, state.match); |
117 |
+ if (tree_foreach_pkg_sorted(t, quse_results_cb, |
118 |
+ &state, state.match) > 0) |
119 |
+ ret = EXIT_SUCCESS; |
120 |
tree_close(t); |
121 |
} |
122 |
} |
123 |
@@ -760,5 +771,5 @@ int quse_main(int argc, char **argv) |
124 |
if (state.match != NULL) |
125 |
atom_implode(state.match); |
126 |
|
127 |
- return EXIT_SUCCESS; |
128 |
+ return ret; |
129 |
} |