static int init_wimlib_dentry(struct wimlib_dir_entry *wdentry, struct wim_dentry *dentry, WIMStruct *wim, int flags) { int ret; size_t dummy; const struct wim_inode *inode = dentry->d_inode; const struct wim_inode_stream *strm; struct wimlib_unix_data unix_data; const void *object_id; u32 object_id_len; ret = utf16le_get_tstr(dentry->d_name, dentry->d_name_nbytes, &wdentry->filename, &dummy); if (ret) return ret; ret = utf16le_get_tstr(dentry->d_short_name, dentry->d_short_name_nbytes, &wdentry->dos_name, &dummy); if (ret) return ret; ret = calculate_dentry_full_path(dentry); if (ret) return ret; wdentry->full_path = dentry->d_full_path; for (struct wim_dentry *d = dentry; !dentry_is_root(d); d = d->d_parent) wdentry->depth++; if (inode_has_security_descriptor(inode)) { struct wim_security_data *sd; sd = wim_get_current_security_data(wim); wdentry->security_descriptor = sd->descriptors[inode->i_security_id]; wdentry->security_descriptor_size = sd->sizes[inode->i_security_id]; } wdentry->reparse_tag = inode->i_reparse_tag; wdentry->num_links = inode->i_nlink; wdentry->attributes = inode->i_attributes; wdentry->hard_link_group_id = inode->i_ino; wdentry->creation_time = wim_timestamp_to_timespec(inode->i_creation_time); wdentry->last_write_time = wim_timestamp_to_timespec(inode->i_last_write_time); wdentry->last_access_time = wim_timestamp_to_timespec(inode->i_last_access_time); if (inode_get_unix_data(inode, &unix_data)) { wdentry->unix_uid = unix_data.uid; wdentry->unix_gid = unix_data.gid; wdentry->unix_mode = unix_data.mode; wdentry->unix_rdev = unix_data.rdev; } object_id = inode_get_object_id(inode, &object_id_len); if (unlikely(object_id != NULL)) { memcpy(&wdentry->object_id, object_id, min(object_id_len, sizeof(wdentry->object_id))); } strm = inode_get_unnamed_stream(inode, get_default_stream_type(inode)); if (strm) { ret = stream_to_wimlib_stream_entry(inode, strm, &wdentry->streams[0], wim->blob_table, flags); if (ret) return ret; } for (unsigned i = 0; i < inode->i_num_streams; i++) { strm = &inode->i_streams[i]; if (!stream_is_named_data_stream(strm)) continue; wdentry->num_named_streams++; ret = stream_to_wimlib_stream_entry(inode, strm, &wdentry->streams[ wdentry->num_named_streams], wim->blob_table, flags); if (ret) return ret; } return 0; }
static int handle_conflict(struct wim_dentry *branch, struct wim_dentry *existing, struct update_command_journal *j, int add_flags, wimlib_progress_func_t progfunc, void *progctx) { bool branch_is_dir = dentry_is_directory(branch); bool existing_is_dir = dentry_is_directory(existing); if (branch_is_dir != existing_is_dir) { if (existing_is_dir) { ERROR("\"%"TS"\" is a directory!\n" " Specify the path at which " "to place the file inside this directory.", dentry_full_path(existing)); return WIMLIB_ERR_IS_DIRECTORY; } else { ERROR("Can't place directory at \"%"TS"\" because " "a nondirectory file already exists there!", dentry_full_path(existing)); return WIMLIB_ERR_NOTDIR; } } if (branch_is_dir) { /* Directory overlay */ while (dentry_has_children(branch)) { struct wim_dentry *new_child; struct wim_dentry *existing_child; int ret; new_child = dentry_any_child(branch); existing_child = get_dentry_child_with_utf16le_name(existing, new_child->file_name, new_child->file_name_nbytes, WIMLIB_CASE_PLATFORM_DEFAULT); unlink_dentry(new_child); if (existing_child) { ret = handle_conflict(new_child, existing_child, j, add_flags, progfunc, progctx); } else { ret = journaled_link(j, new_child, existing); } if (ret) { dentry_add_child(branch, new_child); return ret; } } free_dentry_tree(branch, j->lookup_table); return 0; } else if (add_flags & WIMLIB_ADD_FLAG_NO_REPLACE) { /* Can't replace nondirectory file */ ERROR("Refusing to overwrite nondirectory file \"%"TS"\"", dentry_full_path(existing)); return WIMLIB_ERR_INVALID_OVERLAY; } else { /* Replace nondirectory file */ struct wim_dentry *parent; int ret; parent = existing->d_parent; ret = calculate_dentry_full_path(existing); if (ret) return ret; if (add_flags & WIMLIB_ADD_FLAG_VERBOSE) { union wimlib_progress_info info; info.replace.path_in_wim = existing->_full_path; ret = call_progress(progfunc, WIMLIB_PROGRESS_MSG_REPLACE_FILE_IN_WIM, &info, progctx); if (ret) return ret; } ret = journaled_unlink(j, existing); if (ret) return ret; return journaled_link(j, branch, parent); } }