1 |
commit: c59331531a36c9d3a9e56aca35e5a71760c73c93 |
2 |
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu Nov 26 10:08:35 2015 +0000 |
4 |
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Nov 26 10:08:35 2015 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=c5933153 |
7 |
|
8 |
quse: walk all available overlays when describing flags |
9 |
|
10 |
The main logic still needs updating, but that relies on the |
11 |
cache file being overlay aware (which it isn't currently). |
12 |
|
13 |
URL: https://bugs.gentoo.org/553260 |
14 |
|
15 |
quse.c | 42 +++++++++++++++++++++++++++++------------- |
16 |
tests/init.sh | 13 +++++++++++++ |
17 |
tests/quse/dotest | 6 +++--- |
18 |
3 files changed, 45 insertions(+), 16 deletions(-) |
19 |
|
20 |
diff --git a/quse.c b/quse.c |
21 |
index 5ef88da..ab257bf 100644 |
22 |
--- a/quse.c |
23 |
+++ b/quse.c |
24 |
@@ -78,8 +78,8 @@ print_highlighted_use_flags(char *string, int ind, int argc, char **argv) |
25 |
} |
26 |
} |
27 |
|
28 |
-static int |
29 |
-quse_describe_flag(unsigned int ind, unsigned int argc, char **argv) |
30 |
+static void |
31 |
+quse_describe_flag(const char *overlay, unsigned int ind, unsigned int argc, char **argv) |
32 |
{ |
33 |
#define NUM_SEARCH_FILES ARRAY_SIZE(search_files) |
34 |
size_t buflen; |
35 |
@@ -88,15 +88,16 @@ quse_describe_flag(unsigned int ind, unsigned int argc, char **argv) |
36 |
size_t s; |
37 |
const char * const search_files[] = { "use.desc", "use.local.desc", "arch.list", }; |
38 |
FILE *fp[NUM_SEARCH_FILES]; |
39 |
+ int dfd, fd; |
40 |
DIR *d; |
41 |
struct dirent *de; |
42 |
|
43 |
/* pick 1000 arbitrarily long enough for all files under desc/ */ |
44 |
- buflen = strlen(portdir) + 1000; |
45 |
+ buflen = strlen(overlay) + 1000; |
46 |
buf = xmalloc(buflen); |
47 |
|
48 |
for (i = 0; i < NUM_SEARCH_FILES; ++i) { |
49 |
- snprintf(buf, buflen, "%s/profiles/%s", portdir, search_files[i]); |
50 |
+ snprintf(buf, buflen, "%s/profiles/%s", overlay, search_files[i]); |
51 |
fp[i] = fopen(buf, "r"); |
52 |
if (verbose && fp[i] == NULL) |
53 |
warnp("skipping %s", buf); |
54 |
@@ -156,12 +157,18 @@ quse_describe_flag(unsigned int ind, unsigned int argc, char **argv) |
55 |
fclose(fp[f]); |
56 |
|
57 |
/* now scan the desc dir */ |
58 |
- snprintf(buf, buflen, "%s/profiles/desc/", portdir); |
59 |
- if ((d = opendir(buf)) == NULL) { |
60 |
+ snprintf(buf, buflen, "%s/profiles/desc/", overlay); |
61 |
+ dfd = open(buf, O_RDONLY|O_CLOEXEC); |
62 |
+ if (dfd == -1) { |
63 |
if (verbose) |
64 |
warnp("skipping %s", buf); |
65 |
goto done; |
66 |
} |
67 |
+ d = fdopendir(dfd); |
68 |
+ if (!d) { |
69 |
+ close(dfd); |
70 |
+ goto done; |
71 |
+ } |
72 |
|
73 |
while ((de = readdir(d)) != NULL) { |
74 |
s = strlen(de->d_name); |
75 |
@@ -171,10 +178,15 @@ quse_describe_flag(unsigned int ind, unsigned int argc, char **argv) |
76 |
if (strcmp(p, ".desc")) |
77 |
continue; |
78 |
|
79 |
- snprintf(buf, buflen, "%s/profiles/desc/%s", portdir, de->d_name); |
80 |
- if ((fp[0] = fopen(buf, "r")) == NULL) { |
81 |
+ fd = openat(dfd, de->d_name, O_RDONLY|O_CLOEXEC); |
82 |
+ if (fd == -1) { |
83 |
if (verbose) |
84 |
- warnp("skipping %s", buf); |
85 |
+ warnp("skipping %s/profiles/desc/%s", overlay, de->d_name); |
86 |
+ continue; |
87 |
+ } |
88 |
+ fp[0] = fdopen(fd, "r"); |
89 |
+ if (!fp[0]) { |
90 |
+ close(fd); |
91 |
continue; |
92 |
} |
93 |
|
94 |
@@ -211,7 +223,6 @@ quse_describe_flag(unsigned int ind, unsigned int argc, char **argv) |
95 |
|
96 |
done: |
97 |
free(buf); |
98 |
- return 0; |
99 |
} |
100 |
|
101 |
int quse_main(int argc, char **argv) |
102 |
@@ -251,8 +262,13 @@ int quse_main(int argc, char **argv) |
103 |
if (argc == optind && !quse_all && idx >= 0) |
104 |
quse_usage(EXIT_FAILURE); |
105 |
|
106 |
- if (idx == -1) |
107 |
- return quse_describe_flag(optind, argc, argv); |
108 |
+ if (idx == -1) { |
109 |
+ size_t n; |
110 |
+ const char *overlay; |
111 |
+ array_for_each(overlays, n, overlay) |
112 |
+ quse_describe_flag(overlay, optind, argc, argv); |
113 |
+ return 0; |
114 |
+ } |
115 |
|
116 |
if (quse_all) optind = argc; |
117 |
cache_file = initialize_ebuild_flat(); |
118 |
@@ -406,7 +422,7 @@ int quse_main(int argc, char **argv) |
119 |
char **ARGV; |
120 |
int ARGC; |
121 |
makeargv(&buf0[search_len + 1], &ARGC, &ARGV); |
122 |
- quse_describe_flag(1, ARGC, ARGV); |
123 |
+ quse_describe_flag(portdir, 1, ARGC, ARGV); |
124 |
freeargv(ARGC, ARGV); |
125 |
} |
126 |
} |
127 |
|
128 |
diff --git a/tests/init.sh b/tests/init.sh |
129 |
index 11fd379..a17821d 100644 |
130 |
--- a/tests/init.sh |
131 |
+++ b/tests/init.sh |
132 |
@@ -96,3 +96,16 @@ treedir() { |
133 |
ls -R "${d}" |
134 |
fi |
135 |
} |
136 |
+ |
137 |
+mkportdir() { |
138 |
+ export PORTDIR=$1 |
139 |
+ |
140 |
+ export PORTAGE_CONFIGROOT=${PWD} |
141 |
+ mkdir -p etc/portage/ |
142 |
+ cat <<-EOF >etc/portage/repos.conf |
143 |
+ [DEFAULT] |
144 |
+ main-repo = utils-test |
145 |
+ [utils-test] |
146 |
+ location = ${PORTDIR} |
147 |
+ EOF |
148 |
+} |
149 |
|
150 |
diff --git a/tests/quse/dotest b/tests/quse/dotest |
151 |
index da7d95e..0dadd8f 100755 |
152 |
--- a/tests/quse/dotest |
153 |
+++ b/tests/quse/dotest |
154 |
@@ -4,10 +4,10 @@ |
155 |
|
156 |
set -e |
157 |
|
158 |
-export PORTDIR=${as}/portdir |
159 |
- |
160 |
mktmpdir |
161 |
|
162 |
+mkportdir "${as}/portdir" |
163 |
+ |
164 |
d=${PORTDIR}/profiles |
165 |
entries() { |
166 |
sed -e 's:#.*::' -e '/^$/d' "$1" |
167 |
@@ -80,7 +80,7 @@ diff -u ${as}/list01.good x |
168 |
rm x |
169 |
tpass "multi file match" |
170 |
|
171 |
-trimtmpdir |
172 |
+cleantmpdir |
173 |
|
174 |
###### faster test needed.######## |
175 |
end |