diff options
Diffstat (limited to 'mkfs')
-rw-r--r-- | mkfs/dirscan.c | 37 | ||||
-rw-r--r-- | mkfs/mkfs.c | 34 |
2 files changed, 28 insertions, 43 deletions
diff --git a/mkfs/dirscan.c b/mkfs/dirscan.c index c0572f5..6cb2295 100644 --- a/mkfs/dirscan.c +++ b/mkfs/dirscan.c @@ -6,39 +6,6 @@ */ #include "mkfs.h" -static char *get_file_path(tree_node_t *n, const char *name) -{ - char *ptr, *new; - int ret; - - if (n->parent == NULL) { - ptr = strdup(name); - if (ptr == NULL) - goto fail; - return ptr; - } - - ptr = fstree_get_path(n); - if (ptr == NULL) - goto fail; - - ret = canonicalize_name(ptr); - assert(ret == 0); - - new = realloc(ptr, strlen(ptr) + strlen(name) + 2); - if (new == NULL) - goto fail; - - ptr = new; - strcat(ptr, "/"); - strcat(ptr, name); - return ptr; -fail: - perror("getting absolute file path"); - free(ptr); - return NULL; -} - #ifdef HAVE_SYS_XATTR_H static int populate_xattr(sqfs_xattr_writer_t *xwr, tree_node_t *node) { @@ -163,10 +130,6 @@ static int populate_dir(fstree_t *fs, tree_node_t *root, dev_t devstart, goto fail_rdlink; extra[sb.st_size] = '\0'; - } else if (S_ISREG(sb.st_mode)) { - extra = get_file_path(root, ent->d_name); - if (extra == NULL) - goto fail; } if (!(flags & DIR_SCAN_KEEP_TIME)) diff --git a/mkfs/mkfs.c b/mkfs/mkfs.c index 2e89813..7484618 100644 --- a/mkfs/mkfs.c +++ b/mkfs/mkfs.c @@ -46,6 +46,9 @@ static int pack_files(sqfs_data_writer_t *data, fstree_t *fs, size_t max_blk_count; sqfs_u64 filesize; sqfs_file_t *file; + tree_node_t *node; + const char *path; + char *node_path; file_info_t *fi; int ret; @@ -53,13 +56,31 @@ static int pack_files(sqfs_data_writer_t *data, fstree_t *fs, return -1; for (fi = fs->files; fi != NULL; fi = fi->next) { + if (fi->input_file == NULL) { + node = container_of(fi, tree_node_t, data.file); + + node_path = fstree_get_path(node); + if (node_path == NULL) { + perror("reconstructing file path"); + return -1; + } + + ret = canonicalize_name(node_path); + assert(ret == 0); + + path = node_path; + } else { + node_path = NULL; + path = fi->input_file; + } + if (!opt->cfg.quiet) - printf("packing %s\n", fi->input_file); + printf("packing %s\n", path); - file = sqfs_open_file(fi->input_file, - SQFS_FILE_OPEN_READ_ONLY); + file = sqfs_open_file(path, SQFS_FILE_OPEN_READ_ONLY); if (file == NULL) { - perror(fi->input_file); + perror(path); + free(node_path); return -1; } @@ -74,6 +95,7 @@ static int pack_files(sqfs_data_writer_t *data, fstree_t *fs, if (inode == NULL) { perror("creating file inode"); file->destroy(file); + free(node_path); return -1; } @@ -84,9 +106,9 @@ static int pack_files(sqfs_data_writer_t *data, fstree_t *fs, fi->user_ptr = inode; - ret = write_data_from_file(fi->input_file, data, - inode, file, 0); + ret = write_data_from_file(path, data, inode, file, 0); file->destroy(file); + free(node_path); if (ret) return -1; |