- DEBUG("Using %zu capture sources", num_sources);
- canonicalize_sources_and_targets(sources, num_sources);
- sort_sources(sources, num_sources);
- ret = check_sorted_sources(sources, num_sources, add_image_flags);
- if (ret) {
- ret = WIMLIB_ERR_INVALID_PARAM;
- goto out_free_security_data;
- }
-
- INIT_LIST_HEAD(&unhashed_streams);
- w->lookup_table->unhashed_streams = &unhashed_streams;
- root_dentry = NULL;
-
- params.lookup_table = w->lookup_table;
- params.inode_table = &inode_table;
- params.sd_set = &sd_set;
- params.config = config;
- params.add_image_flags = add_image_flags;
- params.progress_func = progress_func;
- params.extra_arg = extra_arg;
- for (size_t i = 0; i < num_sources; i++) {
- int flags;
- union wimlib_progress_info progress;
-
- DEBUG("Building dentry tree for source %zu of %zu "
- "(\"%"TS"\" => \"%"TS"\")", i + 1, num_sources,
- sources[i].fs_source_path,
- sources[i].wim_target_path);
- if (progress_func) {
- memset(&progress, 0, sizeof(progress));
- progress.scan.source = sources[i].fs_source_path;
- progress.scan.wim_target_path = sources[i].wim_target_path;
- progress_func(WIMLIB_PROGRESS_MSG_SCAN_BEGIN, &progress);
- }
- config->_prefix = sources[i].fs_source_path;
- config->_prefix_num_tchars = tstrlen(sources[i].fs_source_path);
- flags = add_image_flags | WIMLIB_ADD_IMAGE_FLAG_SOURCE;
- if (!*sources[i].wim_target_path)
- flags |= WIMLIB_ADD_IMAGE_FLAG_ROOT;
- ret = (*capture_tree)(&branch, sources[i].fs_source_path,
- ¶ms);
- if (ret) {
- ERROR("Failed to build dentry tree for `%"TS"'",
- sources[i].fs_source_path);
- goto out_free_dentry_tree;
- }
- if (branch) {
- /* Use the target name, not the source name, for
- * the root of each branch from a capture
- * source. (This will also set the root dentry
- * of the entire image to be unnamed.) */
- ret = set_dentry_name(branch,
- path_basename(sources[i].wim_target_path));
- if (ret)
- goto out_free_branch;
-
- ret = attach_branch(&root_dentry, branch,
- sources[i].wim_target_path);
- if (ret)
- goto out_free_branch;
- }
- if (progress_func)
- progress_func(WIMLIB_PROGRESS_MSG_SCAN_END, &progress);
- }
-
- if (root_dentry == NULL) {
- ret = new_filler_directory(T(""), &root_dentry);
- if (ret)
- goto out_free_dentry_tree;
- }
-
- ret = add_new_dentry_tree(w, root_dentry, sd);
-
- 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];
- 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);
-
- ret = xml_add_image(w, name);
- if (ret)
- goto out_put_imd;
-
- if (add_image_flags & WIMLIB_ADD_IMAGE_FLAG_BOOT)
- wimlib_set_boot_idx(w, w->hdr.image_count);
-
- if (add_image_flags & WIMLIB_ADD_IMAGE_FLAG_RPFIX)
- w->hdr.flags |= WIM_HDR_FLAG_RP_FIX;