Only create and remove parents that are missing or empty.
lib/backup-files.c | 31 ++++++++++++++-----------------
1 files changed, 14 insertions(+), 17 deletions(-)
Index: quilt-HEAD/lib/backup-files.c
===================================================================
--- quilt-HEAD.orig/lib/backup-files.c
+++ quilt-HEAD/lib/backup-files.c
@@ -76,6 +76,7 @@ void
create_parents(const char *filename)
{
struct stat st;
+ int rv = -1;
char *fn = alloca(strlen(filename) + 1), *f;
strcpy(fn, filename);
@@ -83,35 +84,31 @@ create_parents(const char *filename)
if (f == NULL)
return;
+
*f = '\0';
- if (stat(f, &st) != 0) {
- while (f != NULL) {
- *f = '\0';
+
+ while (f != NULL) {
+ *f = '\0';
+ if (!rv || (rv = stat(f, &st)) != 0) {
mkdir(fn, 0777);
- *f = '/';
- f = strchr(f+1, '/');
}
- } else {
*f = '/';
+ f = strchr(f+1, '/');
}
}
void
-remove_parents(char *filename)
+remove_parents(const char *filename)
{
- char *f, *g = NULL;
+ char *fn = strdup(filename), *f;
- f = strrchr(filename, '/');
- while ((f = strrchr(filename, '/')) != NULL) {
- if (g != NULL)
- *g = '/';
- g = f;
- *f= '\0';
+ while ((f = strrchr(fn, '/')) != NULL) {
+ *f = '\0';
- rmdir(filename);
+ if (rmdir(fn) == -1)
+ return;
}
- if (g != NULL)
- *g = '/';
+ rmdir(fn);
}
static int
]
--
Gary V. Vaughan ())_. [EMAIL PROTECTED],gnu.org}
Research Scientist ( '/ http://tkd.kicks-ass.net
GNU Hacker / )= http://www.gnu.org/software/libtool
Technical Author `(_~)_ http://sources.redhat.com/autobook
_______________________________________________
Quilt-dev mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/quilt-dev