Skip to content

Commit

Permalink
Fix importing archives that were exported
Browse files Browse the repository at this point in the history
  • Loading branch information
tbodt committed Jun 19, 2020
1 parent 48d3ef0 commit b4c5ba8
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions fs/fakefsify.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,29 @@ bool fakefs_import(const char *archive_path, const char *fs, struct fakefsify_er

int fd = -1;
if (archive_entry_filetype(entry) != AE_IFDIR) {
// mkdir -p
char *entry_path_copy = strdup(entry_path);
char *slash = entry_path_copy;
while ((slash = strchr(slash + 1, '/')) != NULL) {
*slash = '\0';
int err = mkdirat(root_fd, fix_path(entry_path_copy), 0777);
*slash = '/';
if (err < 0) {
if (errno == EEXIST) continue;
POSIX_ERR();
}
printf("created %s\n", entry_path_copy);
}
free(entry_path_copy);

fd = openat(root_fd, fix_path(entry_path), O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (fd < 0)
if (fd < 0) {
if (errno == EISDIR) continue; // assuming it's case insensitivity
POSIX_ERR();
}
}
switch (archive_entry_filetype(entry)) {
case AE_IFDIR:
if (strcmp(entry_path, "") == 0)
break; // root has already been created
err = mkdirat(root_fd, fix_path(entry_path), 0777);
if (err < 0 && errno != EEXIST)
POSIX_ERR();
Expand Down

0 comments on commit b4c5ba8

Please sign in to comment.