1 |
commit: 737cbc7da8473b7f2cd98b18201bf438c7e6c8c7 |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue Apr 30 07:52:27 2019 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Apr 30 07:52:27 2019 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=737cbc7d |
7 |
|
8 |
libq/cache: fix some issues (likely bugs #684252 and #684476) |
9 |
|
10 |
cache_next_pkg: fix package traversal and cat_ctx shoveling |
11 |
cache_read_file_ebuild: fix key parsing (not to loop forever) |
12 |
cache_pkg_read: open correct file for ebuild case |
13 |
|
14 |
Bug: https://bugs.gentoo.org/684252 |
15 |
Bug: https://bugs.gentoo.org/684476 |
16 |
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> |
17 |
|
18 |
libq/cache.c | 37 ++++++++++++++++++++++++++++--------- |
19 |
1 file changed, 28 insertions(+), 9 deletions(-) |
20 |
|
21 |
diff --git a/libq/cache.c b/libq/cache.c |
22 |
index efc47bc..504b6d3 100644 |
23 |
--- a/libq/cache.c |
24 |
+++ b/libq/cache.c |
25 |
@@ -144,14 +144,17 @@ cache_next_pkg(cache_cat_ctx *cat_ctx) |
26 |
q_vdb_ctx *pkgdir = ctx->ebuilddir_ctx; |
27 |
|
28 |
if (pkgdir == NULL) |
29 |
- pkgdir = ctx->ebuilddir_ctx = xzalloc(sizeof(q_vdb_ctx)); |
30 |
+ pkgdir = ctx->ebuilddir_ctx = xmalloc(sizeof(q_vdb_ctx)); |
31 |
+ memset(ctx->ebuilddir_ctx, '\0', sizeof(*ctx->ebuilddir_ctx)); |
32 |
|
33 |
if ((ctx->ebuilddir_pkg_ctx = q_vdb_next_pkg(cat_ctx)) == NULL) |
34 |
return NULL; |
35 |
|
36 |
pkgdir->portroot_fd = -1; |
37 |
pkgdir->vdb_fd = cat_ctx->fd; |
38 |
- pkgdir->dir = NULL; |
39 |
+ pkgdir->do_sort = ctx->do_sort; |
40 |
+ pkgdir->repo = ctx->repo; |
41 |
+ pkgdir->cachetype = ctx->cachetype; |
42 |
|
43 |
ctx->ebuilddir_cat_ctx = |
44 |
q_vdb_open_cat(pkgdir, ctx->ebuilddir_pkg_ctx->name); |
45 |
@@ -159,6 +162,7 @@ cache_next_pkg(cache_cat_ctx *cat_ctx) |
46 |
|
47 |
ret = q_vdb_next_pkg(ctx->ebuilddir_cat_ctx); |
48 |
if (ret == NULL) { |
49 |
+ q_vdb_close_cat(ctx->ebuilddir_cat_ctx); |
50 |
ctx->ebuilddir_pkg_ctx = NULL; |
51 |
} else { |
52 |
if ((p = strstr(ret->name, ".ebuild")) == NULL) { |
53 |
@@ -166,7 +170,7 @@ cache_next_pkg(cache_cat_ctx *cat_ctx) |
54 |
ret = NULL; |
55 |
} else { |
56 |
/* "zap" the pkg such that it looks like CAT/P */ |
57 |
- ret->cat_ctx = cat_ctx; |
58 |
+ ret->cat_ctx->name = cat_ctx->name; |
59 |
*p = '\0'; |
60 |
} |
61 |
} |
62 |
@@ -366,6 +370,7 @@ cache_read_file_ebuild(cache_pkg_ctx *pkg_ctx) |
63 |
char *q; |
64 |
char *r; |
65 |
char **key; |
66 |
+ bool findnl; |
67 |
|
68 |
if ((f = fdopen(pkg_ctx->fd, "r")) == NULL) |
69 |
goto err; |
70 |
@@ -382,8 +387,6 @@ cache_read_file_ebuild(cache_pkg_ctx *pkg_ctx) |
71 |
|
72 |
p = ret->_data; |
73 |
do { |
74 |
- if ((p = strchr(p, '\n')) == NULL) |
75 |
- break; |
76 |
q = p; |
77 |
while (*p >= 'A' && *p <= 'Z') |
78 |
p++; |
79 |
@@ -411,11 +414,12 @@ cache_read_file_ebuild(cache_pkg_ctx *pkg_ctx) |
80 |
#undef match_key |
81 |
} |
82 |
|
83 |
+ findnl = true; |
84 |
if (key != NULL) { |
85 |
q = p; |
86 |
if (*q == '"' || *q == '\'') { |
87 |
/* find matching quote */ |
88 |
- q = ++p; |
89 |
+ q = p; |
90 |
do { |
91 |
while (*p != '\0' && *p != *q) |
92 |
p++; |
93 |
@@ -428,14 +432,20 @@ cache_read_file_ebuild(cache_pkg_ctx *pkg_ctx) |
94 |
} |
95 |
break; |
96 |
} while (1); |
97 |
+ q++; |
98 |
} else { |
99 |
/* find first whitespace */ |
100 |
while (!isspace((int)*p)) |
101 |
p++; |
102 |
+ if (*p == '\n') |
103 |
+ findnl = false; |
104 |
} |
105 |
- *p = '\0'; |
106 |
+ *p++ = '\0'; |
107 |
*key = q; |
108 |
} |
109 |
+ |
110 |
+ if (findnl && (p = strchr(p, '\n')) != NULL) |
111 |
+ p++; |
112 |
} while (p != NULL); |
113 |
|
114 |
fclose(f); |
115 |
@@ -458,8 +468,17 @@ cache_pkg_read(cache_pkg_ctx *pkg_ctx) |
116 |
cache_ctx *ctx = (cache_ctx *)(pkg_ctx->cat_ctx->ctx); |
117 |
|
118 |
if (pkg_ctx->fd == -1) { |
119 |
- pkg_ctx->fd = openat(pkg_ctx->cat_ctx->fd, pkg_ctx->name, |
120 |
- O_RDONLY|O_CLOEXEC); |
121 |
+ if (ctx->cachetype != CACHE_EBUILD) { |
122 |
+ pkg_ctx->fd = openat(pkg_ctx->cat_ctx->fd, pkg_ctx->name, |
123 |
+ O_RDONLY|O_CLOEXEC); |
124 |
+ } else { |
125 |
+ char *p = (char *)pkg_ctx->name; |
126 |
+ p += strlen(p); |
127 |
+ *p = '.'; |
128 |
+ pkg_ctx->fd = openat(pkg_ctx->cat_ctx->fd, pkg_ctx->name, |
129 |
+ O_RDONLY|O_CLOEXEC); |
130 |
+ *p = '\0'; |
131 |
+ } |
132 |
if (pkg_ctx->fd == -1) |
133 |
return NULL; |
134 |
} |