X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fadd_image.c;h=082c5023ae8bc5a5259a174a36cc231432ef6946;hb=c92b18f7074e6d632c555bed5897c5723abde720;hp=085fd044e386d1626bc2e9f649da704ee799ce2c;hpb=40beb80283a2df7af88c8359ca41adb814585e9a;p=wimlib diff --git a/src/add_image.c b/src/add_image.c index 085fd044..082c5023 100644 --- a/src/add_image.c +++ b/src/add_image.c @@ -53,7 +53,7 @@ * @sd: The security data for the image. */ int add_new_dentry_tree(WIMStruct *w, struct dentry *root_dentry, - struct wim_security_data *sd) + struct wim_security_data *sd) { struct lookup_table_entry *metadata_lte; struct image_metadata *imd; @@ -87,18 +87,12 @@ int add_new_dentry_tree(WIMStruct *w, struct dentry *root_dentry, new_imd->root_dentry = root_dentry; new_imd->metadata_lte = metadata_lte; new_imd->security_data = sd; - new_imd->modified = true; + new_imd->modified = 1; FREE(w->image_metadata); - w->image_metadata = imd; + w->image_metadata = imd; w->hdr.image_count++; - - /* Change the current image to the new one. There should not be any - * ways for this to fail, since the image is valid and the dentry tree - * is already in memory. */ - ret = select_wim_image(w, w->hdr.image_count); - wimlib_assert(ret == 0); - return ret; + return 0; err_free_imd: FREE(imd); err: @@ -193,9 +187,20 @@ static int build_dentry_tree(struct dentry **root_ret, } if ((add_image_flags & WIMLIB_ADD_IMAGE_FLAG_ROOT) && - !S_ISDIR(root_stbuf.st_mode)) { - ERROR("`%s' is not a directory", root_disk_path); - return WIMLIB_ERR_NOTDIR; + !S_ISDIR(root_stbuf.st_mode)) + { + /* Do a dereference-stat in case the root is a symbolic link. + * This case is allowed, provided that the symbolic link points + * to a directory. */ + ret = stat(root_disk_path, &root_stbuf); + if (ret != 0) { + ERROR_WITH_ERRNO("Failed to stat `%s'", root_disk_path); + return WIMLIB_ERR_STAT; + } + if (!S_ISDIR(root_stbuf.st_mode)) { + ERROR("`%s' is not a directory", root_disk_path); + return WIMLIB_ERR_NOTDIR; + } } if (!S_ISREG(root_stbuf.st_mode) && !S_ISDIR(root_stbuf.st_mode) && !S_ISLNK(root_stbuf.st_mode)) { @@ -231,7 +236,7 @@ static int build_dentry_tree(struct dentry **root_ret, ((u64)root_stbuf.st_dev << ((sizeof(ino_t) * 8) & 63)); add_image_flags &= ~WIMLIB_ADD_IMAGE_FLAG_ROOT; - inode->resolved = true; + inode->resolved = 1; if (S_ISREG(root_stbuf.st_mode)) { /* Archiving a regular file */ @@ -629,7 +634,6 @@ WIMLIBAPI int wimlib_add_image(WIMStruct *w, const char *source, struct dentry *root_dentry = NULL; struct wim_security_data *sd; struct capture_config config; - struct inode_table inode_tab; struct hlist_head inode_list; int ret; @@ -726,21 +730,14 @@ WIMLIBAPI int wimlib_add_image(WIMStruct *w, const char *source, if (ret != 0) goto out_free_dentry_tree; - DEBUG("Inserting dentries into inode table"); - ret = init_inode_table(&inode_tab, 9001); - if (ret != 0) - goto out_destroy_imd; - - for_dentry_in_tree(root_dentry, inode_table_insert, &inode_tab); - DEBUG("Cleaning up the hard link groups"); - ret = fix_inodes(&inode_tab, &inode_list); - destroy_inode_table(&inode_tab); + ret = dentry_tree_fix_inodes(root_dentry, &inode_list); if (ret != 0) goto out_destroy_imd; DEBUG("Assigning hard link group IDs"); assign_inode_numbers(&inode_list); + w->image_metadata[w->hdr.image_count - 1].inode_list = inode_list; ret = xml_add_image(w, name); if (ret != 0)