- goto out;
-
- DEBUG("Allocating security data");
- sd = CALLOC(1, sizeof(struct wim_security_data));
- if (!sd) {
- ret = WIMLIB_ERR_NOMEM;
- goto out_destroy_capture_config;
- }
- sd->total_length = 8;
- sd->refcnt = 1;
-
- DEBUG("Using %zu capture sources", num_sources);
- canonicalize_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;
- }
-
- DEBUG("Building dentry tree.");
- if (num_sources == 0) {
- root_dentry = new_filler_directory("");
- if (!root_dentry) {
- ret = WIMLIB_ERR_NOMEM;
- goto out_free_security_data;
- }
- } else {
- size_t i;
-
- #ifdef __WIN32__
- win32_acquire_capture_privileges();
- #endif
-
- root_dentry = NULL;
- i = 0;
- do {
- int flags;
- union wimlib_progress_info progress;
-
- DEBUG("Building dentry tree for source %zu of %zu "
- "(\"%s\" => \"%s\")", 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);
- }
- ret = capture_config_set_prefix(&config,
- sources[i].fs_source_path);
- if (ret)
- goto out_free_dentry_tree;
- 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,
- w->lookup_table, sd,
- &config,
- flags,
- progress_func, extra_arg);
- if (ret) {
- ERROR("Failed to build dentry tree for `%s'",
- 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);
- } while (++i != num_sources);
- }
-
- DEBUG("Calculating full paths of dentries.");
- ret = for_dentry_in_tree(root_dentry, calculate_dentry_full_path, NULL);
- if (ret != 0)
- goto out_free_dentry_tree;
-
- ret = add_new_dentry_tree(w, root_dentry, sd);
- if (ret != 0)
- goto out_free_dentry_tree;
-
- imd = &w->image_metadata[w->hdr.image_count - 1];