X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Fadd_image.c;h=7a0ef113edc1078bf456bad5fb4f93ec9424738f;hp=e3f022adde848a860859418385c4a3aad18444e6;hb=d8d2377861cec72d3dd51910a417926e37b7f3b4;hpb=7ce0d372fae285051cbc9740c9fa316d22465d9d diff --git a/src/add_image.c b/src/add_image.c index e3f022ad..7a0ef113 100644 --- a/src/add_image.c +++ b/src/add_image.c @@ -59,8 +59,8 @@ add_new_dentry_tree(WIMStruct *w, struct wim_dentry *root_dentry, struct wim_security_data *sd) { struct wim_image_metadata *new_imd; - int ret; struct wim_lookup_table_entry *metadata_lte; + int ret; metadata_lte = new_lookup_table_entry(); if (!metadata_lte) @@ -141,7 +141,7 @@ unix_capture_directory(struct wim_dentry *dir_dentry, { DIR *dir; - struct dirent entry, *result; + struct dirent *entry; struct wim_dentry *child; int ret; @@ -154,26 +154,26 @@ unix_capture_directory(struct wim_dentry *dir_dentry, } /* Recurse on directory contents */ - while (1) { + for (;;) { errno = 0; - ret = readdir_r(dir, &entry, &result); - if (ret != 0) { - ret = WIMLIB_ERR_READ; - ERROR_WITH_ERRNO("Error reading the " - "directory `%s'", - path); + entry = readdir(dir); + if (!entry) { + if (errno) { + ret = WIMLIB_ERR_READ; + ERROR_WITH_ERRNO("Error reading the " + "directory `%s'", path); + } break; } - if (result == NULL) - break; - if (result->d_name[0] == '.' && (result->d_name[1] == '\0' - || (result->d_name[1] == '.' && result->d_name[2] == '\0'))) + + if (entry->d_name[0] == '.' && (entry->d_name[1] == '\0' + || (entry->d_name[1] == '.' && entry->d_name[2] == '\0'))) continue; - size_t name_len = strlen(result->d_name); + size_t name_len = strlen(entry->d_name); path[path_len] = '/'; - memcpy(&path[path_len + 1], result->d_name, name_len + 1); + memcpy(&path[path_len + 1], entry->d_name, name_len + 1); ret = unix_build_dentry_tree_recursive(&child, path, path_len + 1 + name_len, @@ -837,6 +837,9 @@ wimlib_add_image_multisource(WIMStruct *w, struct list_head unhashed_streams; int ret; struct sd_set sd_set; +#ifdef WITH_NTFS_3G + struct _ntfs_volume *ntfs_vol = NULL; +#endif if (add_image_flags & WIMLIB_ADD_IMAGE_FLAG_NTFS) { #ifdef WITH_NTFS_3G @@ -850,7 +853,7 @@ wimlib_add_image_multisource(WIMStruct *w, return WIMLIB_ERR_INVALID_PARAM; } capture_tree = build_dentry_tree_ntfs; - extra_arg = &w->ntfs_vol; + extra_arg = &ntfs_vol; #else ERROR("wimlib was compiled without support for NTFS-3g, so\n" " cannot capture a WIM image directly from a NTFS volume!"); @@ -991,12 +994,21 @@ wimlib_add_image_multisource(WIMStruct *w, } ret = add_new_dentry_tree(w, root_dentry, sd); - if (ret) + + if (ret) { +#ifdef WITH_NTFS_3G + if (ntfs_vol) + do_ntfs_umount(ntfs_vol); +#endif goto out_free_dentry_tree; + } imd = w->image_metadata[w->hdr.image_count - 1]; - INIT_LIST_HEAD(&imd->unhashed_streams); - list_splice(&unhashed_streams, &imd->unhashed_streams); + list_transfer(&unhashed_streams, &imd->unhashed_streams); + +#ifdef WITH_NTFS_3G + imd->ntfs_vol = ntfs_vol; +#endif DEBUG("Assigning hard link group IDs"); inode_table_prepare_inode_list(&inode_table, &imd->inode_list);