diff options
author | kientzle <kientzle@FreeBSD.org> | 2004-04-20 20:21:36 +0000 |
---|---|---|
committer | kientzle <kientzle@FreeBSD.org> | 2004-04-20 20:21:36 +0000 |
commit | c9ba6f5197c2c774e9ad3483f84fbc50ea4f4ba9 (patch) | |
tree | 88bb6cac0889fae4d8b8e5ab4914f181b5c4c15d /lib/libarchive/archive_write_set_format_shar.c | |
parent | b0a5c34c3e52dae78a382311f6bf284aac0a0c95 (diff) | |
download | FreeBSD-src-c9ba6f5197c2c774e9ad3483f84fbc50ea4f4ba9.zip FreeBSD-src-c9ba6f5197c2c774e9ad3483f84fbc50ea4f4ba9.tar.gz |
Yucky bug: Don't emit 'mkdir' commands for regular files in shar archives.
While I'm here, add some logic to avoid "mkdir ."
Reported by: Juergen Lock
Diffstat (limited to 'lib/libarchive/archive_write_set_format_shar.c')
-rw-r--r-- | lib/libarchive/archive_write_set_format_shar.c | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/lib/libarchive/archive_write_set_format_shar.c b/lib/libarchive/archive_write_set_format_shar.c index f063e21..135beca 100644 --- a/lib/libarchive/archive_write_set_format_shar.c +++ b/lib/libarchive/archive_write_set_format_shar.c @@ -166,6 +166,11 @@ archive_write_shar_header(struct archive *a, struct archive_entry *entry) /* Only regular files have non-zero size. */ break; case S_IFDIR: + archive_entry_set_size(entry, 0); + /* Don't bother trying to recreate '.' */ + if (strcmp(name, ".") == 0 || strcmp(name, "./") == 0) + return (ARCHIVE_OK); + break; case S_IFIFO: case S_IFCHR: case S_IFBLK: @@ -189,23 +194,30 @@ archive_write_shar_header(struct archive *a, struct archive_entry *entry) /* Try to create the dir. */ p = strdup(name); pp = strrchr(p, '/'); - if (pp != NULL) + /* If there is a / character, try to create the dir. */ + if (pp != NULL) { *pp = '\0'; - if (shar->last_dir == NULL) { - shar_printf(a, "mkdir -p %s > /dev/null 2>&1\n", p); - shar->last_dir = p; - } else if (strcmp(p, shar->last_dir) == 0) { - /* We've already created this exact dir. */ - free(p); - } else if (strlen(p) < strlen(shar->last_dir) && - strncmp(p, shar->last_dir, strlen(p)) == 0) { - /* We've already created a subdir. */ - free(p); - } else { - shar_printf(a, "mkdir -p %s > /dev/null 2>&1\n", p); - free(shar->last_dir); - shar->last_dir = p; + /* Try to avoid a lot of redundant mkdir commands. */ + if (strcmp(p, ".") == 0) { + /* Don't try to "mkdir ." */ + } else if (shar->last_dir == NULL) { + shar_printf(a, + "mkdir -p %s > /dev/null 2>&1\n", p); + shar->last_dir = p; + } else if (strcmp(p, shar->last_dir) == 0) { + /* We've already created this exact dir. */ + free(p); + } else if (strlen(p) < strlen(shar->last_dir) && + strncmp(p, shar->last_dir, strlen(p)) == 0) { + /* We've already created a subdir. */ + free(p); + } else { + shar_printf(a, + "mkdir -p %s > /dev/null 2>&1\n", p); + free(shar->last_dir); + shar->last_dir = p; + } } } |