[Reproducible-commits] [dpkg] 45/63: dpkg: Remove FIND usage, use treewalk instead
Jérémy Bobbio
lunar at moszumanska.debian.org
Fri Mar 4 17:44:45 UTC 2016
This is an automated email from the git hooks/post-receive script.
lunar pushed a commit to branch pu/buildinfo
in repository dpkg.
commit 067ebda9af9b8df3d9c267ccc00ddb82a2bb0a97
Author: Guillem Jover <guillem at debian.org>
Date: Fri Feb 26 10:52:57 2016 +0100
dpkg: Remove FIND usage, use treewalk instead
---
debian/changelog | 1 +
lib/dpkg/dpkg.h | 3 ---
src/archives.c | 66 +++++++++++++++++++-------------------------------------
src/help.c | 2 +-
4 files changed, 24 insertions(+), 48 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index a6d4c91..546cff5 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -41,6 +41,7 @@ dpkg (1.18.5) UNRELEASED; urgency=medium
- Use it to build the .deb data member in dpkg-deb.
- Use it to build the .deb control member in dpkg-deb.
Closes: #719845
+ - Use it with dpkg --recursive option.
* Portability:
- Move DPKG_ADMINDIR environment variable name out from update-alternatives
code, to make life easier for non-dpkg-based systems.
diff --git a/lib/dpkg/dpkg.h b/lib/dpkg/dpkg.h
index 8aae4cf..769a302 100644
--- a/lib/dpkg/dpkg.h
+++ b/lib/dpkg/dpkg.h
@@ -108,11 +108,8 @@ DPKG_BEGIN_DECLS
#define RM "rm"
#define CAT "cat"
-#define FIND "find"
#define DIFF "diff"
-#define FIND_EXPRSTARTCHARS "-(),!"
-
#include <dpkg/progname.h>
#include <dpkg/ehandle.h>
#include <dpkg/report.h>
diff --git a/src/archives.c b/src/archives.c
index aa5f691..ae7fa30 100644
--- a/src/archives.c
+++ b/src/archives.c
@@ -52,6 +52,7 @@
#include <dpkg/subproc.h>
#include <dpkg/command.h>
#include <dpkg/file.h>
+#include <dpkg/treewalk.h>
#include <dpkg/tarfn.h>
#include <dpkg/options.h>
#include <dpkg/triglib.h>
@@ -1457,64 +1458,41 @@ archivefiles(const char *const *argv)
log_message("startup archives %s", cipaction->olong);
if (f_recursive) {
- int pi[2], nfiles, c, rc;
- pid_t pid;
- FILE *pf;
- static struct varbuf findoutput;
- const char **arglist;
- char *p;
+ const char **arglist = NULL;
+ const char *const *ap;
+ int nfiles = 0;
if (!*argv)
badusage(_("--%s --recursive needs at least one path argument"),cipaction->olong);
- m_pipe(pi);
- pid = subproc_fork();
- if (pid == 0) {
- struct command cmd;
- const char *const *ap;
+ for (ap = argv; *ap; ap++) {
+ struct treeroot *tree;
+ struct treenode *node;
- m_dup2(pi[1],1); close(pi[0]); close(pi[1]);
+ tree = treewalk_open((const char *)*ap, TREEWALK_FOLLOW_LINKS, NULL);
- command_init(&cmd, FIND, _("find for dpkg --recursive"));
- command_add_args(&cmd, FIND, "-L", NULL);
+ while ((node = treewalk_next(tree))) {
+ const char *nodename;
- for (ap = argv; *ap; ap++) {
- if (strchr(FIND_EXPRSTARTCHARS,(*ap)[0])) {
- command_add_arg(&cmd, str_fmt("./%s", *ap));
- } else {
- command_add_arg(&cmd, (const char *)*ap);
- }
- }
+ if (!S_ISREG(treenode_get_mode(node)))
+ continue;
- command_add_args(&cmd, "-name", "*.deb", "-type", "f", "-print0", NULL);
+ /* Check if it looks like a .deb file. */
+ nodename = treenode_get_pathname(node);
+ if (strcmp(nodename + strlen(nodename) - 4, ".deb") != 0)
+ continue;
- command_exec(&cmd);
- }
- close(pi[1]);
-
- nfiles= 0;
- pf= fdopen(pi[0],"r"); if (!pf) ohshite(_("failed to fdopen find's pipe"));
- varbuf_reset(&findoutput);
- while ((c= fgetc(pf)) != EOF) {
- varbuf_add_char(&findoutput, c);
- if (!c) nfiles++;
+ arglist = m_realloc(arglist, sizeof(char *) * (nfiles + 1));
+ arglist[nfiles++] = strdup(nodename);
+ }
+
+ treewalk_close(tree);
}
- if (ferror(pf)) ohshite(_("error reading find's pipe"));
- if (fclose(pf)) ohshite(_("error closing find's pipe"));
- rc = subproc_reap(pid, "find", SUBPROC_RETERROR);
- if (rc != 0)
- ohshit(_("find for --recursive returned unhandled error %i"), rc);
if (!nfiles)
ohshit(_("searched, but found no packages (files matching *.deb)"));
- arglist= m_malloc(sizeof(char*)*(nfiles+1));
- p = findoutput.buf;
- for (i = 0; i < nfiles; i++) {
- arglist[i] = p;
- while (*p++ != '\0') ;
- }
- arglist[i] = NULL;
+ arglist[nfiles] = NULL;
argp= arglist;
} else {
if (!*argv) badusage(_("--%s needs at least one package archive file argument"),
diff --git a/src/help.c b/src/help.c
index 670985b..a03c257 100644
--- a/src/help.c
+++ b/src/help.c
@@ -85,7 +85,7 @@ void checkpath(void) {
DEFAULTSHELL,
RM,
TAR,
- FIND,
+ DIFF,
BACKEND,
/* Mac OS X uses dyld (Mach-O) instead of ld.so (ELF), and does not have
* an ldconfig. */
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git
More information about the Reproducible-commits
mailing list