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
This commit is contained in:
parent
b0a5c34c3e
commit
c9ba6f5197
@ -166,6 +166,11 @@ archive_write_shar_header(struct archive *a, struct archive_entry *entry)
|
|||||||
/* Only regular files have non-zero size. */
|
/* Only regular files have non-zero size. */
|
||||||
break;
|
break;
|
||||||
case S_IFDIR:
|
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_IFIFO:
|
||||||
case S_IFCHR:
|
case S_IFCHR:
|
||||||
case S_IFBLK:
|
case S_IFBLK:
|
||||||
@ -189,23 +194,30 @@ archive_write_shar_header(struct archive *a, struct archive_entry *entry)
|
|||||||
/* Try to create the dir. */
|
/* Try to create the dir. */
|
||||||
p = strdup(name);
|
p = strdup(name);
|
||||||
pp = strrchr(p, '/');
|
pp = strrchr(p, '/');
|
||||||
if (pp != NULL)
|
/* If there is a / character, try to create the dir. */
|
||||||
|
if (pp != NULL) {
|
||||||
*pp = '\0';
|
*pp = '\0';
|
||||||
|
|
||||||
if (shar->last_dir == NULL) {
|
/* Try to avoid a lot of redundant mkdir commands. */
|
||||||
shar_printf(a, "mkdir -p %s > /dev/null 2>&1\n", p);
|
if (strcmp(p, ".") == 0) {
|
||||||
shar->last_dir = p;
|
/* Don't try to "mkdir ." */
|
||||||
} else if (strcmp(p, shar->last_dir) == 0) {
|
} else if (shar->last_dir == NULL) {
|
||||||
/* We've already created this exact dir. */
|
shar_printf(a,
|
||||||
free(p);
|
"mkdir -p %s > /dev/null 2>&1\n", p);
|
||||||
} else if (strlen(p) < strlen(shar->last_dir) &&
|
shar->last_dir = p;
|
||||||
strncmp(p, shar->last_dir, strlen(p)) == 0) {
|
} else if (strcmp(p, shar->last_dir) == 0) {
|
||||||
/* We've already created a subdir. */
|
/* We've already created this exact dir. */
|
||||||
free(p);
|
free(p);
|
||||||
} else {
|
} else if (strlen(p) < strlen(shar->last_dir) &&
|
||||||
shar_printf(a, "mkdir -p %s > /dev/null 2>&1\n", p);
|
strncmp(p, shar->last_dir, strlen(p)) == 0) {
|
||||||
free(shar->last_dir);
|
/* We've already created a subdir. */
|
||||||
shar->last_dir = p;
|
free(p);
|
||||||
|
} else {
|
||||||
|
shar_printf(a,
|
||||||
|
"mkdir -p %s > /dev/null 2>&1\n", p);
|
||||||
|
free(shar->last_dir);
|
||||||
|
shar->last_dir = p;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user