* modified if successful. Set to NULL if the file or directory was
* excluded from capture.
*
- * @root_disk_path: The path to the root of the directory tree on disk (UTF-8).
+ * @root_disk_path: The path to the root of the directory tree on disk.
*
* @lookup_table: The lookup table for the WIM file. For each file added to the
* dentry tree being built, an entry is added to the lookup table,
goto out;
}
- root = new_dentry_with_timeless_inode(path_basename(root_disk_path));
- if (!root) {
- if (errno == EILSEQ)
- ret = WIMLIB_ERR_INVALID_UTF8_STRING;
- else if (errno == ENOMEM)
- ret = WIMLIB_ERR_NOMEM;
- else
- ret = WIMLIB_ERR_ICONV_NOT_AVAILABLE;
+ ret = new_dentry_with_timeless_inode(path_basename(root_disk_path),
+ &root);
+ if (ret)
goto out;
- }
inode = root->d_inode;
static int
pattern_list_add_pattern(struct pattern_list *list, const mbchar *pattern)
{
- const char **pats;
+ const mbchar **pats;
if (list->num_pats >= list->num_allocated_pats) {
pats = REALLOC(list->pats,
sizeof(list->pats[0]) * (list->num_allocated_pats + 8));
const struct pattern_list *list)
{
for (size_t i = 0; i < list->num_pats; i++) {
- const char *pat = list->pats[i];
- const char *string;
+ const mbchar *pat = list->pats[i];
+ const mbchar *string;
if (pat[0] == '/')
/* Absolute path from root of capture */
string = path;
/* Creates a new directory to place in the WIM image. This is to create parent
* directories that are not part of any target as needed. */
-static struct wim_dentry *
-new_filler_directory(const mbchar *name)
+static int
+new_filler_directory(const mbchar *name, struct wim_dentry **dentry_ret)
{
+ int ret;
struct wim_dentry *dentry;
+
DEBUG("Creating filler directory \"%s\"", name);
- dentry = new_dentry_with_inode(name);
- if (dentry) {
+ ret = new_dentry_with_inode(name, &dentry);
+ if (ret == 0) {
/* Leave the inode number as 0 for now. The final inode number
* will be assigned later by assign_inode_numbers(). */
dentry->d_inode->i_resolved = 1;
dentry->d_inode->i_attributes = FILE_ATTRIBUTE_DIRECTORY;
+ *dentry_ret = dentry;
}
- return dentry;
+ return ret;
}
/* Transfers the children of @branch to @target. It is an error if @target is
attach_branch(struct wim_dentry **root_p, struct wim_dentry *branch,
mbchar *target_path)
{
- char *slash;
+ mbchar *slash;
struct wim_dentry *dentry, *parent, *target;
+ int ret;
DEBUG("Attaching branch \"%W\" => \"%s\"",
branch->file_name, target_path);
/* Adding a non-root branch. Create root if it hasn't been created
* already. */
if (!*root_p) {
- *root_p = new_filler_directory("");
- if (!*root_p)
- return WIMLIB_ERR_NOMEM;
+ ret = new_filler_directory("", root_p);
+ if (ret)
+ return ret;
}
/* Walk the path to the branch, creating filler directories as needed.
*slash = '\0';
dentry = get_dentry_child_with_name(parent, target_path);
if (!dentry) {
- dentry = new_filler_directory(target_path);
- if (!dentry)
- return WIMLIB_ERR_NOMEM;
+ ret = new_filler_directory(target_path, &dentry);
+ if (ret)
+ return ret;
dentry_add_child(parent, dentry);
}
parent = dentry;
/* If the target path already existed, overlay the branch onto it.
* Otherwise, set the branch as the target path. */
- target = get_dentry_child_with_utf16le_name(parent, branch->file_name);
+ target = get_dentry_child_with_utf16le_name(parent, branch->file_name,
+ branch->file_name_nbytes);
if (target) {
return do_overlay(target, branch);
} else {
}
if (wimlib_image_name_in_use(w, name)) {
- ERROR("There is already an image named \"%s\" in `%s'",
- name, w->filename);
+ ERROR("There is already an image named \"%U\" in the WIM!",
+ name);
return WIMLIB_ERR_IMAGE_NAME_COLLISION;
}
}
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;
+ root_dentry = NULL;
+
+ 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 "
+ "(\"%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);
}
- } else {
- size_t i;
-
- #ifdef __WIN32__
- win32_acquire_capture_privileges();
- #endif
+ 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;
- 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);
+ ret = attach_branch(&root_dentry, branch,
+ sources[i].wim_target_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);
+ goto out_free_branch;
+ }
+ if (progress_func)
+ progress_func(WIMLIB_PROGRESS_MSG_SCAN_END, &progress);
+ }
+
+ if (root_dentry == NULL) {
+ ret = new_filler_directory("" , &root_dentry);
+ if (ret)
+ goto out_free_dentry_tree;
}
DEBUG("Calculating full paths of dentries.");
out_destroy_capture_config:
destroy_capture_config(&config);
out:
-#ifdef __WIN32__
- win32_release_capture_privileges();
-#endif
return ret;
}
if (!source || !*source)
return WIMLIB_ERR_INVALID_PARAM;
- char *fs_source_path = STRDUP(source);
+ mbchar *fs_source_path = STRDUP(source);
int ret;
struct wimlib_capture_source capture_src = {
.fs_source_path = fs_source_path,