quilt-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Quilt-dev] [patch 7/8]


From: gary
Subject: [Quilt-dev] [patch 7/8]
Date: Tue, 13 Sep 2005 22:25:53 +0100

Although Mac OS X 10.4 (I'm running 10.4.2) has nftw and ftw compatibility
functions, and code that uses them seems to build and link properly: the
resulting calls do nothing, which breaks `quilt pop' at least.

This patch reimplements the file tree walk using the fts api <fts.h>,
which is fully supported.

 lib/backup-files.c |   59 +++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 44 insertions(+), 15 deletions(-)

Index: quilt-HEAD/lib/backup-files.c
===================================================================
--- quilt-HEAD.orig/lib/backup-files.c
+++ quilt-HEAD/lib/backup-files.c
@@ -1,7 +1,7 @@
 /*
   File: backup-files.c
 
-  Copyright (C) 2003 Andreas Gruenbacher <address@hidden>
+  Copyright (C) 2003, 2005 Andreas Gruenbacher <address@hidden>
   SuSE Labs, SuSE Linux AG
 
   This program is free software; you can redistribute it and/or
@@ -37,7 +37,7 @@
 #include <errno.h>
 #include <string.h>
 #include <alloca.h>
-#include <ftw.h>
+#include <fts.h>
 
 const char *progname;
 
@@ -107,7 +107,7 @@ remove_parents(char *filename)
                        *g = '/';
                g = f;
                *f= '\0';
-               
+
                rmdir(filename);
        }
        if (g != NULL)
@@ -184,7 +184,7 @@ ensure_nolinks(const char *filename)
                from_fd = open(filename, O_RDONLY);
                if (from_fd == -1)
                        goto fail;
-               
+
                /* Temp file name is "path/to/.file.XXXXXX" */
                strcpy(tmpname, filename);
                strcat(tmpname, ".XXXXXX");
@@ -195,7 +195,7 @@ ensure_nolinks(const char *filename)
                        c++;
                memmove(c + 1, c, strlen(c) + 1);
                *c = '.';
-               
+
                to_fd = mkstemp(tmpname);
                if (to_fd == -1)
                        goto fail;
@@ -312,17 +312,22 @@ process_file(const char *file)
 }
 
 int
-walk(const char *path, const struct stat *stat, int flag, struct FTW *ftw)
+ftswalk(const char *path)
 {
+       struct stat st;
        size_t prefix_len=strlen(opt_prefix), suffix_len=strlen(opt_suffix);
        size_t len = strlen(path);
        char *p;
 
-       if (flag == FTW_DNR) {
+       if (stat(path, &st) != 0) {
+               /* Ignore non-existing files. */
+               return 0;
+       }
+       if (S_ISDIR(st.st_mode) && (access(path, R_OK|X_OK) != 0)) {
                perror(path);
                return 1;
        }
-       if (!S_ISREG(stat->st_mode))
+       if (!S_ISREG(st.st_mode))
                return 0;
        if (strncmp(opt_prefix, path, prefix_len))
                return 0;  /* prefix does not match */
@@ -332,6 +337,7 @@ walk(const char *path, const struct stat
        p = alloca(len - prefix_len - suffix_len + 1);
        memcpy(p, path + prefix_len, len - prefix_len - suffix_len);
        p[len - prefix_len - suffix_len] = '\0';
+
        return process_file(p);
 }
 
@@ -339,7 +345,7 @@ int
 main(int argc, char *argv[])
 {
        int opt, status=0;
-       
+
        progname = argv[0];
 
        while ((opt = getopt(argc, argv, "brxB:z:f:shLt")) != -1) {
@@ -359,7 +365,7 @@ main(int argc, char *argv[])
                        case 'B':
                                opt_prefix = optarg;
                                break;
-                               
+
                        case 'f':
                                opt_file = optarg;
                                break;
@@ -413,7 +419,7 @@ main(int argc, char *argv[])
                                *(l-1) = '\0';
                        if (*line == '\0')
                                continue;
-                               
+
                        if ((status = process_file(line)) != 0)
                                return status;
                }
@@ -424,13 +430,36 @@ main(int argc, char *argv[])
        }
        for (; optind < argc; optind++) {
                if (strcmp(argv[optind], "-") == 0) {
-                       char *dir = strdup(opt_prefix), *d = strrchr(dir, '/');
+                       FTS *fts;
+                       FTSENT *entry;
+                       char *dir[2], *d;
+
+                       dir[0] = strdup(opt_prefix);
+                       dir[1] = 0;
+                       d = strrchr(dir[0], '/');
                        if (d)
-                               *(d+1) = '\0';
+                               *d = '\0';
                        else
                                d = ".";
-                       status = nftw(dir, walk, 0, 0);
-                       free(dir);
+
+                       fts = fts_open(dir, FTS_PHYSICAL|FTS_NOCHDIR, 0);
+
+                       free(dir[0]);
+
+                       if (!fts) {
+                               perror(dir[0]);
+                               return 1;
+                       }
+
+                       while ((entry = fts_read(fts)) != 0) {
+                               if (ftswalk(entry->fts_path) != 0) {
+                                       status = 1;
+                                       break;
+                               }
+                       }
+                       if (fts_close(fts) != 0)
+                               status = 1;
+
                } else
                        status = process_file(argv[optind]);
                if (status)

--
Gary V. Vaughan      ())_.  address@hidden,gnu.org}
Research Scientist   ( '/   http://tkd.kicks-ass.net
GNU Hacker           / )=   http://www.gnu.org/software/libtool
Technical Author   `(_~)_   http://sources.redhat.com/autobook




reply via email to

[Prev in Thread] Current Thread [Next in Thread]