Only create and remove parents that are missing or empty.
lib/backup-files.c | 28 ++++++++++------------------
1 files changed, 10 insertions(+), 18 deletions(-)
Index: quilt-HEAD/lib/backup-files.c
===================================================================
--- quilt-HEAD.orig/lib/backup-files.c
+++ quilt-HEAD/lib/backup-files.c
@@ -94,43 +94,35 @@ void
create_parents(const char *filename)
{
struct stat st;
+ int rv = -1;
char *fn = malloc_nofail(strlen(filename) + 1), *f;
strcpy(fn, filename);
f = strchr(fn, '/');
- if (f != NULL) {
- *f = '\0';
- if (stat(f, &st) != 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, '/');
}
free(fn);
}
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(filename) == -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