# include "wimlib/ntfs_3g.h" /* for do_ntfs_umount() */
#endif
#include "wimlib/paths.h"
+#include "wimlib/progress.h"
#include "wimlib/xml.h"
#include <errno.h>
{
if (parent) {
/* Unlink @subject from its @parent. */
- wimlib_assert(subject->parent == parent);
+ wimlib_assert(subject->d_parent == parent);
unlink_dentry(subject);
} else {
/* Unset @subject as the root of the image. */
*root_p = NULL;
}
- subject->parent = subject;
+ subject->d_parent = subject;
}
static void
if (dentry_is_root(subject))
parent = NULL;
else
- parent = subject->parent;
+ parent = subject->d_parent;
prim.type = UNLINK_DENTRY;
prim.link.subject = subject;
prim.name.subject = dentry;
prim.name.old_name = dentry->file_name;
ret = record_update_primitive(j, prim);
- if (ret)
+ if (ret) {
+ FREE(new_name);
return ret;
+ }
dentry->file_name = new_name;
dentry->file_name_nbytes = new_name_nbytes;
static int
handle_conflict(struct wim_dentry *branch, struct wim_dentry *existing,
struct update_command_journal *j,
- int add_flags, wimlib_progress_func_t progress_func)
+ 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);
unlink_dentry(new_child);
if (existing_child) {
ret = handle_conflict(new_child, existing_child,
- j, add_flags, progress_func);
+ j, add_flags,
+ progfunc, progctx);
} else {
ret = journaled_link(j, new_child, existing);
}
struct wim_dentry *parent;
int ret;
- parent = existing->parent;
+ parent = existing->d_parent;
ret = calculate_dentry_full_path(existing);
if (ret)
return ret;
- ret = journaled_unlink(j, existing);
- if (ret)
- return ret;
-
- ret = journaled_link(j, branch, parent);
- if (ret)
- return ret;
-
- if (progress_func && (add_flags & WIMLIB_ADD_FLAG_VERBOSE)) {
+ if (add_flags & WIMLIB_ADD_FLAG_VERBOSE) {
union wimlib_progress_info info;
info.replace.path_in_wim = existing->_full_path;
- progress_func(WIMLIB_PROGRESS_MSG_REPLACE_FILE_IN_WIM, &info);
+ ret = call_progress(progfunc,
+ WIMLIB_PROGRESS_MSG_REPLACE_FILE_IN_WIM,
+ &info, progctx);
+ if (ret)
+ return ret;
}
- return 0;
+
+ ret = journaled_unlink(j, existing);
+ if (ret)
+ return ret;
+
+ return journaled_link(j, branch, parent);
}
}
static int
do_attach_branch(struct wim_dentry *branch, const utf16lechar *target,
struct update_command_journal *j,
- int add_flags, wimlib_progress_func_t progress_func)
+ int add_flags, wimlib_progress_func_t progfunc, void *progctx)
{
struct wim_dentry *parent;
struct wim_dentry *existing;
/* Last component */
if (existing) {
- return handle_conflict(branch, existing, j,
- add_flags, progress_func);
+ return handle_conflict(branch, existing, j, add_flags,
+ progfunc, progctx);
} else {
return journaled_link(j, branch, parent);
}
*/
static int
attach_branch(struct wim_dentry *branch, const tchar *target_tstr,
- struct update_command_journal *j,
- int add_flags, wimlib_progress_func_t progress_func)
+ struct update_command_journal *j, int add_flags,
+ wimlib_progress_func_t progfunc, void *progctx)
{
int ret;
const utf16lechar *target;
if (ret)
goto out_free_target;
- ret = do_attach_branch(branch, target, j, add_flags, progress_func);
+ ret = do_attach_branch(branch, target, j, add_flags, progfunc, progctx);
if (ret)
goto out_free_target;
/* branch was successfully committed to the journal */
const struct wimlib_update_command *add_cmd,
struct wim_inode_table *inode_table,
struct wim_sd_set *sd_set,
- struct list_head *unhashed_streams,
- wimlib_progress_func_t progress_func)
+ struct list_head *unhashed_streams)
{
int ret;
int add_flags;
params.add_flags = add_flags;
params.extra_arg = extra_arg;
- params.progress_func = progress_func;
+ params.progfunc = wim->progfunc;
+ params.progctx = wim->progctx;
params.progress.scan.source = fs_source_path;
params.progress.scan.wim_target_path = wim_target_path;
- if (progress_func)
- progress_func(WIMLIB_PROGRESS_MSG_SCAN_BEGIN, ¶ms.progress);
+ ret = call_progress(params.progfunc, WIMLIB_PROGRESS_MSG_SCAN_BEGIN,
+ ¶ms.progress, params.progctx);
+ if (ret)
+ goto out_destroy_config;
if (WIMLIB_IS_WIM_ROOT_PATH(wim_target_path))
params.add_flags |= WIMLIB_ADD_FLAG_ROOT;
if (ret)
goto out_destroy_config;
- if (progress_func)
- progress_func(WIMLIB_PROGRESS_MSG_SCAN_END, ¶ms.progress);
+ ret = call_progress(params.progfunc, WIMLIB_PROGRESS_MSG_SCAN_END,
+ ¶ms.progress, params.progctx);
+ if (ret) {
+ free_dentry_tree(branch, wim->lookup_table);
+ goto out_cleanup_after_capture;
+ }
if (WIMLIB_IS_WIM_ROOT_PATH(wim_target_path) &&
branch && !dentry_is_directory(branch))
}
ret = attach_branch(branch, wim_target_path, j,
- add_flags, params.progress_func);
+ add_flags, params.progfunc, params.progctx);
if (ret)
goto out_cleanup_after_capture;
WIMLIB_IS_WIM_ROOT_PATH(wim_target_path))
{
params.add_flags = 0;
- params.progress_func = NULL;
+ params.progfunc = NULL;
params.config = NULL;
/* If a capture configuration file was explicitly specified when
if (ret)
goto out_cleanup_after_capture;
- ret = attach_branch(branch, wimboot_cfgfile, j, 0, NULL);
+ ret = attach_branch(branch, wimboot_cfgfile, j, 0, NULL, NULL);
if (ret)
goto out_cleanup_after_capture;
}
/* Is @d1 a (possibly nonproper) ancestor of @d2? */
static bool
-is_ancestor(struct wim_dentry *d1, struct wim_dentry *d2)
+is_ancestor(const struct wim_dentry *d1, const struct wim_dentry *d2)
{
for (;;) {
if (d2 == d1)
return true;
if (dentry_is_root(d2))
return false;
- d2 = d2->parent;
+ d2 = d2->d_parent;
}
}
if (dentry_has_children(dst))
return -ENOTEMPTY;
}
- parent_of_dst = dst->parent;
+ parent_of_dst = dst->d_parent;
} else {
/* Destination does not exist */
parent_of_dst = get_parent_dentry(wim, to, case_type);
execute_update_commands(WIMStruct *wim,
const struct wimlib_update_command *cmds,
size_t num_cmds,
- int update_flags,
- wimlib_progress_func_t progress_func)
+ int update_flags)
{
struct wim_inode_table *inode_table;
struct wim_sd_set *sd_set;
for (size_t i = 0; i < num_cmds; i++) {
DEBUG("Executing update command %zu of %zu (op=%"TS")",
i + 1, num_cmds, update_op_to_str(cmds[i].op));
- if (update_flags & WIMLIB_UPDATE_FLAG_SEND_PROGRESS &&
- progress_func)
- {
- info.update.command = &cmds[i];
- (*progress_func)(WIMLIB_PROGRESS_MSG_UPDATE_BEGIN_COMMAND,
- &info);
+ info.update.command = &cmds[i];
+ if (update_flags & WIMLIB_UPDATE_FLAG_SEND_PROGRESS) {
+ ret = call_progress(wim->progfunc,
+ WIMLIB_PROGRESS_MSG_UPDATE_BEGIN_COMMAND,
+ &info, wim->progctx);
+ if (ret)
+ goto rollback;
}
- ret = WIMLIB_ERR_INVALID_PARAM;
+
switch (cmds[i].op) {
case WIMLIB_UPDATE_OP_ADD:
ret = execute_add_command(j, wim, &cmds[i], inode_table,
- sd_set, &unhashed_streams,
- progress_func);
+ sd_set, &unhashed_streams);
break;
case WIMLIB_UPDATE_OP_DELETE:
ret = execute_delete_command(j, wim, &cmds[i]);
if (unlikely(ret))
goto rollback;
info.update.completed_commands++;
- if (update_flags & WIMLIB_UPDATE_FLAG_SEND_PROGRESS &&
- progress_func)
- {
- (*progress_func)(WIMLIB_PROGRESS_MSG_UPDATE_END_COMMAND,
- &info);
+ if (update_flags & WIMLIB_UPDATE_FLAG_SEND_PROGRESS) {
+ ret = call_progress(wim->progfunc,
+ WIMLIB_PROGRESS_MSG_UPDATE_END_COMMAND,
+ &info, wim->progctx);
+ if (ret)
+ goto rollback;
}
next_command(j);
}
int image,
const struct wimlib_update_command *cmds,
size_t num_cmds,
- int update_flags,
- wimlib_progress_func_t progress_func)
+ int update_flags)
{
int ret;
struct wimlib_update_command *cmds_copy;
/* Actually execute the update commands. */
DEBUG("Executing %zu update commands", num_cmds);
- ret = execute_update_commands(wim, cmds_copy, num_cmds, update_flags,
- progress_func);
+ ret = execute_update_commands(wim, cmds_copy, num_cmds, update_flags);
if (ret)
goto out_free_cmds_copy;
static int
update1(WIMStruct *wim, int image, const struct wimlib_update_command *cmd)
{
- return wimlib_update_image(wim, image, cmd, 1, 0, NULL);
+ return wimlib_update_image(wim, image, cmd, 1, 0);
}
WIMLIBAPI int