Gentoo Archives: gentoo-commits

From: "Mike Frysinger (vapier)" <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-projects commit in portage-utils: .depend TODO main.c qmerge.c
Date: Wed, 23 Feb 2011 08:59:55
Message-Id: 20110223085945.4A9FC2004F@flycatcher.gentoo.org
1 vapier 11/02/23 08:59:45
2
3 Modified: .depend TODO main.c qmerge.c
4 Log:
5 replace `rm -rf` shells with an internal rm_rf(), and add support for running pkg_{pre,post}inst ourselves
6
7 Revision Changes Path
8 1.40 portage-utils/.depend
9
10 file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/.depend?rev=1.40&view=markup
11 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/.depend?rev=1.40&content-type=text/plain
12 diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/.depend?r1=1.39&r2=1.40
13
14 Index: .depend
15 ===================================================================
16 RCS file: /var/cvsroot/gentoo-projects/portage-utils/.depend,v
17 retrieving revision 1.39
18 retrieving revision 1.40
19 diff -u -r1.39 -r1.40
20 --- .depend 19 Jul 2010 00:25:13 -0000 1.39
21 +++ .depend 23 Feb 2011 08:59:45 -0000 1.40
22 @@ -2,8 +2,8 @@
23 libq/colors.c libq/xmalloc.c libq/xstrdup.c libq/xasprintf.c \
24 libq/hash_fd.c libq/md5_sha1_sum.c libq/human_readable.c libq/rmspace.c \
25 libq/which.c libq/compat.c libq/safe_io.c libq/xchdir.c libq/xgetcwd.c \
26 - libq/xreadlink.c libq/xsystem.c libq/atom_explode.c libq/atom_compare.c \
27 - libq/basename.c libq/vdb_get_next_dir.c libq/virtuals.c applets.h \
28 - include_applets.h q.c qcheck.c qdepends.c qfile.c qlist.c qlop.c \
29 - qsearch.c qsize.c qtbz2.c quse.c qxpak.c qpkg.c qgrep.c qatom.c qmerge.c \
30 - qcache.c qglsa.c
31 + libq/xmkdir.c libq/xreadlink.c libq/xsystem.c libq/atom_explode.c \
32 + libq/atom_compare.c libq/basename.c libq/vdb_get_next_dir.c \
33 + libq/virtuals.c applets.h include_applets.h q.c qcheck.c qdepends.c \
34 + qfile.c qlist.c qlop.c qsearch.c qsize.c qtbz2.c quse.c qxpak.c qpkg.c \
35 + qgrep.c qatom.c qmerge.c qcache.c qglsa.c
36
37
38
39 1.5 portage-utils/TODO
40
41 file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/TODO?rev=1.5&view=markup
42 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/TODO?rev=1.5&content-type=text/plain
43 diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/TODO?r1=1.4&r2=1.5
44
45 Index: TODO
46 ===================================================================
47 RCS file: /var/cvsroot/gentoo-projects/portage-utils/TODO,v
48 retrieving revision 1.4
49 retrieving revision 1.5
50 diff -u -r1.4 -r1.5
51 --- TODO 17 Jan 2008 06:35:07 -0000 1.4
52 +++ TODO 23 Feb 2011 08:59:45 -0000 1.5
53 @@ -11,6 +11,7 @@
54
55 - qmerge: dep resolver needs spanktastic love.
56 - qmerge: needs safe deleting.
57 +- qmerge: handle compressed Packages file
58
59 - atoms:
60 - only 32bit values are supported for revision (-r#)
61
62
63
64 1.184 portage-utils/main.c
65
66 file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/main.c?rev=1.184&view=markup
67 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/main.c?rev=1.184&content-type=text/plain
68 diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/main.c?r1=1.183&r2=1.184
69
70 Index: main.c
71 ===================================================================
72 RCS file: /var/cvsroot/gentoo-projects/portage-utils/main.c,v
73 retrieving revision 1.183
74 retrieving revision 1.184
75 diff -u -r1.183 -r1.184
76 --- main.c 21 Feb 2011 21:52:55 -0000 1.183
77 +++ main.c 23 Feb 2011 08:59:45 -0000 1.184
78 @@ -1,7 +1,7 @@
79 /*
80 * Copyright 2005-2008 Gentoo Foundation
81 * Distributed under the terms of the GNU General Public License v2
82 - * $Header: /var/cvsroot/gentoo-projects/portage-utils/main.c,v 1.183 2011/02/21 21:52:55 vapier Exp $
83 + * $Header: /var/cvsroot/gentoo-projects/portage-utils/main.c,v 1.184 2011/02/23 08:59:45 vapier Exp $
84 *
85 * Copyright 2005-2008 Ned Ludd - <solar@g.o>
86 * Copyright 2005-2008 Mike Frysinger - <vapier@g.o>
87 @@ -173,36 +173,47 @@
88 exit(EXIT_SUCCESS);
89 }
90
91 -static char eat_file(const char *file, char *buf, const size_t bufsize)
92 +static char eat_file_fd(int fd, char *buf, const size_t bufsize)
93 {
94 - int fd;
95 struct stat s;
96 - char ret = 0;
97 -
98 - if ((fd = open(file, O_RDONLY)) == -1)
99 - return ret;
100
101 buf[0] = '\0';
102 if (fstat(fd, &s) != 0)
103 - goto close_and_ret;
104 + return 0;
105 if (s.st_size) {
106 if (bufsize < (size_t)s.st_size)
107 - goto close_and_ret;
108 + return 0;
109 if (read(fd, buf, s.st_size) != (ssize_t)s.st_size)
110 - goto close_and_ret;
111 + return 0;
112 buf[s.st_size] = '\0';
113 } else {
114 if (read(fd, buf, bufsize) == 0)
115 - goto close_and_ret;
116 + return 0;
117 buf[bufsize - 1] = '\0';
118 }
119
120 - ret = 1;
121 -close_and_ret:
122 + return 1;
123 +}
124 +
125 +static char eat_file_at(int dfd, const char *file, char *buf, const size_t bufsize)
126 +{
127 + int fd;
128 + char ret;
129 +
130 + if ((fd = openat(dfd, file, O_RDONLY)) == -1)
131 + return 0;
132 +
133 + ret = eat_file_fd(fd, buf, bufsize);
134 +
135 close(fd);
136 return ret;
137 }
138
139 +static char eat_file(const char *file, char *buf, const size_t bufsize)
140 +{
141 + return eat_file_at(AT_FDCWD, file, buf, bufsize);
142 +}
143 +
144 #if !(_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700)
145 static ssize_t getline(char **line, size_t *len, FILE *fp)
146 {
147
148
149
150 1.102 portage-utils/qmerge.c
151
152 file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qmerge.c?rev=1.102&view=markup
153 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qmerge.c?rev=1.102&content-type=text/plain
154 diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qmerge.c?r1=1.101&r2=1.102
155
156 Index: qmerge.c
157 ===================================================================
158 RCS file: /var/cvsroot/gentoo-projects/portage-utils/qmerge.c,v
159 retrieving revision 1.101
160 retrieving revision 1.102
161 diff -u -r1.101 -r1.102
162 --- qmerge.c 22 Feb 2011 06:10:16 -0000 1.101
163 +++ qmerge.c 23 Feb 2011 08:59:45 -0000 1.102
164 @@ -1,7 +1,7 @@
165 /*
166 * Copyright 2005-2010 Gentoo Foundation
167 * Distributed under the terms of the GNU General Public License v2
168 - * $Header: /var/cvsroot/gentoo-projects/portage-utils/qmerge.c,v 1.101 2011/02/22 06:10:16 vapier Exp $
169 + * $Header: /var/cvsroot/gentoo-projects/portage-utils/qmerge.c,v 1.102 2011/02/23 08:59:45 vapier Exp $
170 *
171 * Copyright 2005-2010 Ned Ludd - <solar@g.o>
172 * Copyright 2005-2010 Mike Frysinger - <vapier@g.o>
173 @@ -55,7 +55,7 @@
174 COMMON_OPTS_HELP
175 };
176
177 -static const char qmerge_rcsid[] = "$Id: qmerge.c,v 1.101 2011/02/22 06:10:16 vapier Exp $";
178 +static const char qmerge_rcsid[] = "$Id: qmerge.c,v 1.102 2011/02/23 08:59:45 vapier Exp $";
179 #define qmerge_usage(ret) usage(ret, QMERGE_FLAGS, qmerge_long_opts, qmerge_opts_help, lookup_applet_idx("qmerge"))
180
181 char search_pkgs = 0;
182 @@ -112,22 +112,6 @@
183
184 struct pkg_t *grab_binpkg_info(const char *);
185
186 -static int mkdirhier(char *dname, mode_t mode)
187 -{
188 - char buf[BUFSIZ];
189 - int i;
190 - strncpy(buf, dname, sizeof(buf));
191 - for (i = 0; i < strlen(buf); i++) {
192 - if (buf[i] == '/') {
193 - buf[i] = 0;
194 - if (*buf)
195 - mkdir(buf, mode);
196 - buf[i] = '/';
197 - }
198 - }
199 - return mkdir(dname, mode);
200 -}
201 -
202 static int q_unlink_q(char *path, const char *func, int line)
203 {
204 if ((strcmp(path, "/bin/sh") == 0) || (strcmp(path, BUSYBOX) == 0)) {
205 @@ -284,22 +268,20 @@
206 return 0;
207 }
208
209 -void crossmount_rm(char *, const size_t size, const char *, const struct stat);
210 -void crossmount_rm(char *buf, const size_t size, const char *fname, const struct stat st)
211 +static void crossmount_rm(const char *fname, const struct stat st)
212 {
213 struct stat lst;
214
215 assert(pretend == 0);
216
217 - if (lstat(buf, &lst) == -1)
218 + if (lstat(fname, &lst) == -1)
219 return;
220 if (lst.st_dev != st.st_dev) {
221 - warn("skipping crossmount install masking: %s", buf);
222 + warn("skipping crossmount install masking: %s", fname);
223 return;
224 }
225 - qprintf("%s<<<%s %s\n", YELLOW, NORM, buf);
226 - snprintf(buf, size, BUSYBOX " rm -rf ./%s", fname);
227 - xsystem(buf);
228 + qprintf("%s<<<%s %s\n", YELLOW, NORM, fname);
229 + rm_rf(fname);
230 }
231
232 void install_mask_pwd(int argc, char **argv, const struct stat st);
233 @@ -324,13 +306,13 @@
234 for (g = 0; g < globbuf.gl_pathc; g++) {
235 strncpy(buf, globbuf.gl_pathv[g], sizeof(buf));
236 /* qprintf("globbed: %s\n", globbuf.gl_pathv[g]); */
237 - crossmount_rm(buf, sizeof(buf), globbuf.gl_pathv[g], st);
238 + crossmount_rm(globbuf.gl_pathv[g], st);
239 }
240 globfree(&globbuf);
241 }
242 continue;
243 }
244 - crossmount_rm(buf, sizeof(buf), iargv[i], st);
245 + crossmount_rm(iargv[i], st);
246 }
247 }
248
249 @@ -408,41 +390,41 @@
250 return c;
251 }
252
253 -static int has_postinst(char *vdbroot)
254 +static void pkg_run_func(const char *vdb_path, const char *phases, const char *func)
255 {
256 - FILE *fp;
257 - int ret;
258 - char buf[1024];
259 - snprintf(buf, sizeof(buf), "%s/%s", vdbroot, "DEFINED_PHASES");
260 - if ((fp = fopen(buf, "r")) == NULL)
261 - return 1;
262 - if (fgets(buf, sizeof(buf), fp))
263 - ret = (strstr(buf, "postinst") == NULL) ? 0 : 2;
264 - else
265 - ret = 0;
266 - fclose(fp);
267 - return ret;
268 -}
269 + char *script;
270 +
271 + /* This assumes no func is a substring of another func.
272 + * Today, that assumption is valid for all funcs ...
273 + * The phases are the func with the "pkg_" chopped off. */
274 + if (strstr(phases, func + 4) == NULL)
275 + return;
276
277 -#define pkg_run_func(func, setup) \
278 - do { \
279 - qprintf(">>> %s\n", func); \
280 - xsystembash( \
281 - "debug-print() { :; }; " \
282 - "debug-print-function() { :; }; " \
283 - "debug-print-section() { :; }; " \
284 - func "() { :; }; " \
285 - setup \
286 - ". ./environment && " \
287 - func \
288 - ); \
289 - } while (0)
290 + qprintf(">>> %s\n", func);
291 +
292 + xasprintf(&script,
293 + /* Provide funcs required by the PMS */
294 + "debug-print() { :; }\n"
295 + "debug-print-function() { :; }\n"
296 + "debug-print-section() { :; }\n"
297 + "use() { useq \"$@\"; }\n"
298 + "useq() { hasq $1 $USE; }\n"
299 + "has() { hasq \"$@\"; }\n"
300 + "hasq() { local h=$1; shift; case \" $* \" in *\" $h \"*) return 0;; *) return 1;; esac; }\n"
301 + /* Unpack the env if need be */
302 + "[ -e '%1$s/environment' ] || { bzip2 -dc '%1$s/environment.bz2' > '%1$s/environment' || exit 1; }\n"
303 + /* Load the env and run the func */
304 + ". %1$s/environment && %2$s",
305 + vdb_path, func);
306 + xsystembash(script);
307 + free(script);
308 +}
309
310 /* oh shit getting into pkg mgt here. FIXME: write a real dep resolver. */
311 void pkg_merge(int level, depend_atom *atom, struct pkg_t *pkg)
312 {
313 FILE *fp, *contents;
314 - char buf[1024];
315 + char buf[1024], phases[128];
316 char tarball[255];
317 char *p;
318 int i;
319 @@ -567,7 +549,8 @@
320 /* mkdir(pkg->PF, 0710); */
321 xchdir(pkg->PF);
322
323 - xsystem(BUSYBOX " rm -rf ./*"); /* this line does funny things to nano's highlighting. */
324 + /* Doesn't actually remove $PWD, just everything under it */
325 + rm_rf(".");
326
327 /* split the tbz and xpak data */
328 snprintf(tarball, sizeof(tarball), "%s.tbz2", pkg->PF);
329 @@ -640,17 +623,21 @@
330 freeargv(ARGC, ARGV);
331 ARGC = 0; ARGV = NULL;
332 }
333 +
334 xchdir("image");
335
336 + eat_file("../vdb/DEFINED_PHASES", phases, sizeof(phases));
337 + pkg_run_func("../vdb", phases, "pkg_preinst");
338 +
339 if (stat("./", &st) == -1)
340 err("Cant stat pwd");
341
342 makeargv(install_mask, &iargc, &iargv);
343 install_mask_pwd(iargc, iargv, st);
344
345 - if ((strstr(features, "noinfo")) != NULL) if (access("./usr/share/info", R_OK) == 0) xsystem(BUSYBOX " rm -rf ./usr/share/info");
346 - if ((strstr(features, "noman")) != NULL) if (access("./usr/share/man", R_OK) == 0) xsystem(BUSYBOX " rm -rf ./usr/share/man");
347 - if ((strstr(features, "nodoc")) != NULL) if (access("./usr/share/doc", R_OK) == 0) xsystem(BUSYBOX " rm -rf ./usr/share/doc");
348 + if (strstr(features, "noinfo")) rm_rf("./usr/share/info");
349 + if (strstr(features, "noman" )) rm_rf("./usr/share/man");
350 + if (strstr(features, "nodoc" )) rm_rf("./usr/share/doc");
351
352 /* we dont care about the return code */
353 rmdir("./usr/share");
354 @@ -802,38 +789,31 @@
355 xchdir(port_tmpdir);
356 xchdir(pkg->PF);
357
358 + /* run postinst */
359 + pkg_run_func("./vdb", phases, "pkg_postinst");
360 +
361 snprintf(buf, sizeof(buf), "%s/var/db/pkg/%s/", portroot, pkg->CATEGORY);
362 if (access(buf, R_OK|W_OK|X_OK) != 0)
363 - mkdirhier(buf, 0755);
364 + mkdir_p(buf, 0755);
365 strncat(buf, pkg->PF, sizeof(buf)-strlen(buf)-1);
366
367 /* FIXME */ /* move unmerging to around here ? */
368 /* not perfect when a version is already installed */
369 if (access(buf, X_OK) == 0) {
370 - char buf2[sizeof(buf)] = "";
371 /* we need to compare CONTENTS in it and remove any file not provided by our CONTENTS */
372 - snprintf(buf2, sizeof(buf2), BUSYBOX " rm -rf %s", buf);
373 - xsystem(buf2);
374 + rm_rf(buf);
375 }
376 if ((fp = fopen("vdb/COUNTER", "w")) != NULL) {
377 fputs("0", fp);
378 fclose(fp);
379 }
380 + /* move the local vdb copy to the final place */
381 interactive_rename("vdb", buf, pkg);
382
383 - /* run postinst on non embedded systems */
384 - if ((which("ebuild") != NULL) && has_postinst(buf)) {
385 - char *tbuf;
386 - xasprintf(&tbuf, "ebuild %s/%s.ebuild postinst", buf, basename(buf));
387 - xsystem(tbuf);
388 - free(tbuf);
389 - }
390 -
391 snprintf(buf, sizeof(buf), BUSYBOX " %s.tar.bz2", pkg->PF);
392 unlink_q(buf);
393 xchdir(port_tmpdir);
394 - snprintf(buf, sizeof(buf), "rm -rf %s", pkg->PF);
395 - xsystem(buf);
396 + rm_rf(pkg->PF);
397
398 snprintf(buf, sizeof(buf), "%s/%s.tbz2", pkgdir, pkg->PF);
399 unlink(buf);
400 @@ -842,7 +822,7 @@
401 int pkg_unmerge(const char *cat, const char *pkgname)
402 {
403 size_t buflen;
404 - char *buf, *vdb_path;
405 + char *buf, *vdb_path, phases[128];
406 FILE *fp;
407 int ret, fd, vdb_fd;
408 int cp_argc, cpm_argc;
409 @@ -875,8 +855,8 @@
410
411 /* First execute the pkg_prerm step */
412 if (!pretend) {
413 - xchdir(vdb_path);
414 - pkg_run_func("pkg_prerm", "bzip2 -dc environment.bz2 > environment && ");
415 + eat_file_at(vdb_fd, "DEFINED_PHASES", phases, sizeof(phases));
416 + pkg_run_func(vdb_path, phases, "pkg_prerm");
417 }
418
419 /* Now start removing all the installed files */
420 @@ -981,29 +961,22 @@
421 freeargv(cp_argc, cp_argv);
422 freeargv(cpm_argc, cpm_argv);
423
424 - /* Then execute the pkg_postrm step */
425 - if (!pretend)
426 - pkg_run_func("pkg_postrm", "");
427 -
428 if (!pretend) {
429 - /* Finally delete the vdb entry */
430 - DIR *dir;
431 - struct dirent *de;
432 + char *dir;
433
434 - dir = fdopendir(vdb_fd);
435 - if (!dir)
436 - goto done;
437 + /* Then execute the pkg_postrm step */
438 + pkg_run_func(vdb_path, phases, "pkg_postrm");
439
440 - while ((de = readdir(dir)) != NULL)
441 - unlinkat(vdb_fd, de->d_name, 0);
442 -
443 - closedir(dir);
444 - vdb_fd = -1;
445 + /* Finally delete the vdb entry */
446 + rm_rf(vdb_path);
447
448 + /* And prune any empty vdb dirs */
449 + dir = strrchr(vdb_path, '/');
450 + *dir = '\0';
451 + rmdir(vdb_path);
452 + dir = strrchr(vdb_path, '/');
453 + *dir = '\0';
454 rmdir(vdb_path);
455 -
456 - /* XXX: Really only needed because we shell out to qlist and such ... */
457 - xchdir("/");
458 }
459
460 ret = 0;