1 |
commit: 7a9bfc5db85d0dab0dbce60f05903b7c4e227192 |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun Jun 28 15:56:44 2020 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Jun 28 15:56:44 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=7a9bfc5d |
7 |
|
8 |
qpkg: use tree_pkg_meta_get instead of direct VDB read |
9 |
|
10 |
qpkg failed to create packages from a different ROOT because the |
11 |
CONTENTS from vdb was read without ROOT support. Avoid this by using |
12 |
tree-based functions that properly use ROOT. |
13 |
|
14 |
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> |
15 |
|
16 |
qpkg.c | 47 ++++++++++++++++++----------------------------- |
17 |
1 file changed, 18 insertions(+), 29 deletions(-) |
18 |
|
19 |
diff --git a/qpkg.c b/qpkg.c |
20 |
index 41ac0f5..8faa6ea 100644 |
21 |
--- a/qpkg.c |
22 |
+++ b/qpkg.c |
23 |
@@ -167,19 +167,23 @@ check_pkg_install_mask(char *name) |
24 |
} |
25 |
|
26 |
static int |
27 |
-qpkg_make(depend_atom *atom) |
28 |
+qpkg_make(tree_pkg_ctx *pkg) |
29 |
{ |
30 |
- FILE *fp, *out; |
31 |
+ FILE *out; |
32 |
+ FILE *fp; |
33 |
char tmpdir[BUFSIZE]; |
34 |
char filelist[BUFSIZE + 32]; |
35 |
char tbz2[BUFSIZE + 32]; |
36 |
size_t buflen; |
37 |
size_t xpaksize; |
38 |
+ char *line; |
39 |
+ char *savep; |
40 |
char *buf; |
41 |
int i; |
42 |
char *xpak_argv[2]; |
43 |
struct stat st; |
44 |
mode_t mask; |
45 |
+ depend_atom *atom = tree_get_atom(pkg, false); |
46 |
|
47 |
if (pretend) { |
48 |
printf(" %s-%s %s:\n", |
49 |
@@ -190,40 +194,34 @@ qpkg_make(depend_atom *atom) |
50 |
buflen = _Q_PATH_MAX; |
51 |
buf = xmalloc(buflen); |
52 |
|
53 |
- snprintf(buf, buflen, "%s/%s/%s/CONTENTS", |
54 |
- portvdb, atom->CATEGORY, atom->PF); |
55 |
- if ((fp = fopen(buf, "r")) == NULL) { |
56 |
- free(buf); |
57 |
+ line = tree_pkg_meta_get(pkg, CONTENTS); |
58 |
+ if (line == NULL) |
59 |
return -1; |
60 |
- } |
61 |
|
62 |
snprintf(tmpdir, sizeof(tmpdir), "%s/qpkg.XXXXXX", qpkg_bindir); |
63 |
mask = umask(0077); |
64 |
i = mkstemp(tmpdir); |
65 |
umask(mask); |
66 |
if (i == -1) { |
67 |
- fclose(fp); |
68 |
free(buf); |
69 |
return -2; |
70 |
} |
71 |
close(i); |
72 |
unlink(tmpdir); |
73 |
if (mkdir(tmpdir, 0750)) { |
74 |
- fclose(fp); |
75 |
free(buf); |
76 |
return -3; |
77 |
} |
78 |
|
79 |
snprintf(filelist, sizeof(filelist), "%s/filelist", tmpdir); |
80 |
if ((out = fopen(filelist, "w")) == NULL) { |
81 |
- fclose(fp); |
82 |
free(buf); |
83 |
return -4; |
84 |
} |
85 |
|
86 |
- while (getline(&buf, &buflen, fp) != -1) { |
87 |
+ for (; (line = strtok_r(line, "\n", &savep)) != NULL; line = NULL) { |
88 |
contents_entry *e; |
89 |
- e = contents_parse_line(buf); |
90 |
+ e = contents_parse_line(line); |
91 |
if (!e || e->type == CONTENTS_DIR) |
92 |
continue; |
93 |
if (check_pkg_install_mask(e->name) != 0) |
94 |
@@ -240,7 +238,6 @@ qpkg_make(depend_atom *atom) |
95 |
} |
96 |
|
97 |
fclose(out); |
98 |
- fclose(fp); |
99 |
|
100 |
printf(" %s-%s %s: ", GREEN, NORM, |
101 |
atom_format("%[CATEGORY]%[PF]", atom)); |
102 |
@@ -271,8 +268,8 @@ qpkg_make(depend_atom *atom) |
103 |
} |
104 |
xpaksize = st.st_size; |
105 |
|
106 |
- snprintf(buf, buflen, "%s/%s/%s", |
107 |
- portvdb, atom->CATEGORY, atom->PF); |
108 |
+ snprintf(buf, buflen, "%s%s/%s/%s", |
109 |
+ portroot, portvdb, atom->CATEGORY, atom->PF); |
110 |
xpak_argv[0] = buf; |
111 |
xpak_argv[1] = NULL; |
112 |
xpak_create(AT_FDCWD, tbz2, 1, xpak_argv, 1, verbose); |
113 |
@@ -333,7 +330,7 @@ qpkg_cb(tree_pkg_ctx *pkg, void *priv) |
114 |
{ |
115 |
size_t *pkgs_made = priv; |
116 |
|
117 |
- if (qpkg_make(tree_get_atom(pkg, false)) == 0) |
118 |
+ if (qpkg_make(pkg) == 0) |
119 |
(*pkgs_made)++; |
120 |
|
121 |
return 0; |
122 |
@@ -395,6 +392,10 @@ int qpkg_main(int argc, char **argv) |
123 |
* to tar when we create the binary package. */ |
124 |
xchdir(portroot); |
125 |
|
126 |
+ ctx = tree_open_vdb(portroot, portvdb); |
127 |
+ if (!ctx) |
128 |
+ return EXIT_FAILURE; |
129 |
+ |
130 |
/* first process any arguments which point to /var/db/pkg, an |
131 |
* undocumented method to allow easily tab-completing into vdb as |
132 |
* arguments, the trailing / needs to be present for this (as tab |
133 |
@@ -419,15 +420,7 @@ int qpkg_main(int argc, char **argv) |
134 |
|
135 |
if (strncmp(portvdb, path, s) == 0) { |
136 |
path += s + 1 /* also eat / after portvdb */; |
137 |
- |
138 |
- atom = atom_explode(path); |
139 |
- if (atom) { |
140 |
- if (!qpkg_make(atom)) |
141 |
- pkgs_made++; |
142 |
- atom_implode(atom); |
143 |
- } else |
144 |
- warn("could not explode '%s'", path); |
145 |
- argv[i] = NULL; |
146 |
+ argv[i] = path; |
147 |
} else { |
148 |
argv[i][asize - 1] = '/'; /* restore, it may be a cat match */ |
149 |
} |
150 |
@@ -435,10 +428,6 @@ int qpkg_main(int argc, char **argv) |
151 |
} |
152 |
|
153 |
/* now try to run through vdb and locate matches for user inputs */ |
154 |
- ctx = tree_open_vdb(portroot, portvdb); |
155 |
- if (!ctx) |
156 |
- return EXIT_FAILURE; |
157 |
- |
158 |
for (i = optind; i < argc; ++i) { |
159 |
if (argv[i] == NULL) |
160 |
continue; |