(file_op_total_context_t): remove. All members were moved to file_op_context_t.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2024-08-17 14:57:49 +03:00
parent dde9002aaf
commit b2b10f1f87
8 changed files with 112 additions and 163 deletions

View File

@ -814,13 +814,13 @@ panel_operate_init_totals (const WPanel *panel, const vfs_path_t *source,
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
static FileProgressStatus static FileProgressStatus
progress_update_one (file_op_total_context_t *tctx, file_op_context_t *ctx, off_t add) progress_update_one (file_op_context_t *ctx, off_t add)
{ {
gint64 tv_current; gint64 tv_current;
static gint64 tv_start = -1; static gint64 tv_start = -1;
tctx->progress_count++; ctx->progress_count++;
tctx->progress_bytes += (uintmax_t) add; ctx->progress_bytes += (uintmax_t) add;
tv_current = g_get_monotonic_time (); tv_current = g_get_monotonic_time ();
@ -831,8 +831,8 @@ progress_update_one (file_op_total_context_t *tctx, file_op_context_t *ctx, off_
{ {
if (verbose && ctx->dialog_type == FILEGUI_DIALOG_MULTI_ITEM) if (verbose && ctx->dialog_type == FILEGUI_DIALOG_MULTI_ITEM)
{ {
file_progress_show_count (ctx, tctx->progress_count, ctx->total_count); file_progress_show_count (ctx, ctx->progress_count, ctx->total_count);
file_progress_show_total (tctx, ctx, tctx->progress_bytes, TRUE); file_progress_show_total (ctx, ctx->progress_bytes, TRUE);
} }
tv_start = tv_current; tv_start = tv_current;
@ -1131,8 +1131,8 @@ files_error (const char *format, const char *file1, const char *file2)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
static void static void
copy_file_file_display_progress (file_op_total_context_t *tctx, file_op_context_t *ctx, copy_file_file_display_progress (file_op_context_t *ctx, gint64 tv_current, off_t file_part,
gint64 tv_current, off_t file_part, off_t file_size) off_t file_size)
{ {
gint64 dt; gint64 dt;
@ -1156,12 +1156,12 @@ copy_file_file_display_progress (file_op_total_context_t *tctx, file_op_context_
{ {
gint64 total_secs; gint64 total_secs;
total_secs = (tv_current - tctx->total_transfer_start) / G_USEC_PER_SEC; total_secs = (tv_current - ctx->total_transfer_start) / G_USEC_PER_SEC;
total_secs = MAX (1, total_secs); total_secs = MAX (1, total_secs);
tctx->total_bps = tctx->copied_bytes / total_secs; ctx->total_bps = ctx->copied_bytes / total_secs;
const uintmax_t remain_bytes = ctx->total_bytes - tctx->copied_bytes; const uintmax_t remain_bytes = ctx->total_bytes - ctx->copied_bytes;
tctx->total_eta_secs = tctx->total_bps != 0 ? remain_bytes / tctx->total_bps : 0; ctx->total_eta_secs = ctx->total_bps != 0 ? remain_bytes / ctx->total_bps : 0;
} }
} }
@ -1191,7 +1191,6 @@ try_remove_file (file_op_context_t *ctx, const vfs_path_t *vpath, FileProgressSt
* Move single file or one of many files from one location to another. * Move single file or one of many files from one location to another.
* *
* @panel pointer to panel in case of single file, NULL otherwise * @panel pointer to panel in case of single file, NULL otherwise
* @tctx file operation total context object
* @ctx file operation context object * @ctx file operation context object
* @s source file name * @s source file name
* @d destination file name * @d destination file name
@ -1199,8 +1198,7 @@ try_remove_file (file_op_context_t *ctx, const vfs_path_t *vpath, FileProgressSt
* @return operation result * @return operation result
*/ */
static FileProgressStatus static FileProgressStatus
move_file_file (const WPanel *panel, file_op_total_context_t *tctx, file_op_context_t *ctx, move_file_file (const WPanel *panel, file_op_context_t *ctx, const char *s, const char *d)
const char *s, const char *d)
{ {
struct stat src_stat, dst_stat; struct stat src_stat, dst_stat;
FileProgressStatus return_status = FILE_CONT; FileProgressStatus return_status = FILE_CONT;
@ -1283,7 +1281,7 @@ move_file_file (const WPanel *panel, file_op_total_context_t *tctx, file_op_cont
if (mc_rename (src_vpath, dst_vpath) == 0) if (mc_rename (src_vpath, dst_vpath) == 0)
{ {
/* FIXME: do we really need to update progress in case of single file? */ /* FIXME: do we really need to update progress in case of single file? */
return_status = progress_update_one (tctx, ctx, src_stat.st_size); return_status = progress_update_one (ctx, src_stat.st_size);
goto ret; goto ret;
} }
} }
@ -1324,10 +1322,10 @@ move_file_file (const WPanel *panel, file_op_total_context_t *tctx, file_op_cont
goto ret; goto ret;
} }
old_ask_overwrite = tctx->ask_overwrite; old_ask_overwrite = ctx->ask_overwrite;
tctx->ask_overwrite = FALSE; ctx->ask_overwrite = FALSE;
return_status = copy_file_file (tctx, ctx, s, d); return_status = copy_file_file (ctx, s, d);
tctx->ask_overwrite = old_ask_overwrite; ctx->ask_overwrite = old_ask_overwrite;
if (return_status != FILE_CONT) if (return_status != FILE_CONT)
goto ret; goto ret;
@ -1353,7 +1351,7 @@ move_file_file (const WPanel *panel, file_op_total_context_t *tctx, file_op_cont
goto ret; goto ret;
if (!copy_done) if (!copy_done)
return_status = progress_update_one (tctx, ctx, src_stat.st_size); return_status = progress_update_one (ctx, src_stat.st_size);
ret: ret:
vfs_path_free (src_vpath, TRUE); vfs_path_free (src_vpath, TRUE);
@ -1369,22 +1367,22 @@ move_file_file (const WPanel *panel, file_op_total_context_t *tctx, file_op_cont
/** Don't update progress status if progress_count==NULL */ /** Don't update progress status if progress_count==NULL */
static FileProgressStatus static FileProgressStatus
erase_file (file_op_total_context_t *tctx, file_op_context_t *ctx, const vfs_path_t *vpath) erase_file (file_op_context_t *ctx, const vfs_path_t *vpath)
{ {
struct stat buf; struct stat buf;
FileProgressStatus return_status; FileProgressStatus return_status;
/* check buttons if deleting info was changed */ /* check buttons if deleting info was changed */
if (file_progress_show_deleting (ctx, vpath, &tctx->progress_count)) if (file_progress_show_deleting (ctx, vpath, &ctx->progress_count))
{ {
file_progress_show_count (ctx, tctx->progress_count, ctx->total_count); file_progress_show_count (ctx, ctx->progress_count, ctx->total_count);
if (file_progress_check_buttons (ctx) == FILE_ABORT) if (file_progress_check_buttons (ctx) == FILE_ABORT)
return FILE_ABORT; return FILE_ABORT;
mc_refresh (); mc_refresh ();
} }
if (tctx->progress_count != 0 && mc_lstat (vpath, &buf) != 0) if (ctx->progress_count != 0 && mc_lstat (vpath, &buf) != 0)
{ {
/* ignore, most likely the mc_unlink fails, too */ /* ignore, most likely the mc_unlink fails, too */
buf.st_size = 0; buf.st_size = 0;
@ -1393,7 +1391,7 @@ erase_file (file_op_total_context_t *tctx, file_op_context_t *ctx, const vfs_pat
if (!try_remove_file (ctx, vpath, &return_status) && return_status == FILE_ABORT) if (!try_remove_file (ctx, vpath, &return_status) && return_status == FILE_ABORT)
return FILE_ABORT; return FILE_ABORT;
if (tctx->progress_count == 0) if (ctx->progress_count == 0)
return FILE_CONT; return FILE_CONT;
return file_progress_check_buttons (ctx); return file_progress_check_buttons (ctx);
@ -1430,7 +1428,7 @@ try_erase_dir (file_op_context_t *ctx, const vfs_path_t *vpath)
ignore_all -> remove as much as possible ignore_all -> remove as much as possible
*/ */
static FileProgressStatus static FileProgressStatus
recursive_erase (file_op_total_context_t *tctx, file_op_context_t *ctx, const vfs_path_t *vpath) recursive_erase (file_op_context_t *ctx, const vfs_path_t *vpath)
{ {
struct vfs_dirent *next; struct vfs_dirent *next;
DIR *reading; DIR *reading;
@ -1456,9 +1454,9 @@ recursive_erase (file_op_total_context_t *tctx, file_op_context_t *ctx, const vf
return FILE_RETRY; return FILE_RETRY;
} }
if (S_ISDIR (buf.st_mode)) if (S_ISDIR (buf.st_mode))
return_status = recursive_erase (tctx, ctx, tmp_vpath); return_status = recursive_erase (ctx, tmp_vpath);
else else
return_status = erase_file (tctx, ctx, tmp_vpath); return_status = erase_file (ctx, tmp_vpath);
vfs_path_free (tmp_vpath, TRUE); vfs_path_free (tmp_vpath, TRUE);
} }
mc_closedir (reading); mc_closedir (reading);
@ -1467,7 +1465,7 @@ recursive_erase (file_op_total_context_t *tctx, file_op_context_t *ctx, const vf
return FILE_ABORT; return FILE_ABORT;
file_progress_show_deleting (ctx, vpath, NULL); file_progress_show_deleting (ctx, vpath, NULL);
file_progress_show_count (ctx, tctx->progress_count, ctx->total_count); file_progress_show_count (ctx, ctx->progress_count, ctx->total_count);
if (file_progress_check_buttons (ctx) == FILE_ABORT) if (file_progress_check_buttons (ctx) == FILE_ABORT)
return FILE_ABORT; return FILE_ABORT;
@ -1534,13 +1532,12 @@ erase_dir_iff_empty (file_op_context_t *ctx, const vfs_path_t *vpath, size_t cou
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
static void static void
erase_dir_after_copy (file_op_total_context_t *tctx, file_op_context_t *ctx, erase_dir_after_copy (file_op_context_t *ctx, const vfs_path_t *vpath, FileProgressStatus *status)
const vfs_path_t *vpath, FileProgressStatus *status)
{ {
if (ctx->erase_at_end && erase_list != NULL) if (ctx->erase_at_end && erase_list != NULL)
{ {
/* Reset progress count before delete to avoid counting files twice */ /* Reset progress count before delete to avoid counting files twice */
tctx->progress_count = tctx->prev_progress_count; ctx->progress_count = ctx->prev_progress_count;
while (!g_queue_is_empty (erase_list) && *status != FILE_ABORT) while (!g_queue_is_empty (erase_list) && *status != FILE_ABORT)
{ {
@ -1549,18 +1546,18 @@ erase_dir_after_copy (file_op_total_context_t *tctx, file_op_context_t *ctx,
lp = (link_t *) g_queue_pop_head (erase_list); lp = (link_t *) g_queue_pop_head (erase_list);
if (S_ISDIR (lp->st_mode)) if (S_ISDIR (lp->st_mode))
*status = erase_dir_iff_empty (ctx, lp->src_vpath, tctx->progress_count); *status = erase_dir_iff_empty (ctx, lp->src_vpath, ctx->progress_count);
else else
*status = erase_file (tctx, ctx, lp->src_vpath); *status = erase_file (ctx, lp->src_vpath);
free_link (lp); free_link (lp);
} }
/* Save progress counter before move next directory */ /* Save progress counter before move next directory */
tctx->prev_progress_count = tctx->progress_count; ctx->prev_progress_count = ctx->progress_count;
} }
erase_dir_iff_empty (ctx, vpath, tctx->progress_count); erase_dir_iff_empty (ctx, vpath, ctx->progress_count);
} }
/* }}} */ /* }}} */
@ -1571,7 +1568,6 @@ erase_dir_after_copy (file_op_total_context_t *tctx, file_op_context_t *ctx,
* Move single directory or one of many directories from one location to another. * Move single directory or one of many directories from one location to another.
* *
* @panel pointer to panel in case of single directory, NULL otherwise * @panel pointer to panel in case of single directory, NULL otherwise
* @tctx file operation total context object
* @ctx file operation context object * @ctx file operation context object
* @s source directory name * @s source directory name
* @d destination directory name * @d destination directory name
@ -1579,8 +1575,7 @@ erase_dir_after_copy (file_op_total_context_t *tctx, file_op_context_t *ctx,
* @return operation result * @return operation result
*/ */
static FileProgressStatus static FileProgressStatus
do_move_dir_dir (const WPanel *panel, file_op_total_context_t *tctx, file_op_context_t *ctx, do_move_dir_dir (const WPanel *panel, file_op_context_t *ctx, const char *s, const char *d)
const char *s, const char *d)
{ {
struct stat src_stat, dst_stat; struct stat src_stat, dst_stat;
FileProgressStatus return_status = FILE_CONT; FileProgressStatus return_status = FILE_CONT;
@ -1642,7 +1637,7 @@ do_move_dir_dir (const WPanel *panel, file_op_total_context_t *tctx, file_op_con
goto ret; goto ret;
} }
return_status = copy_dir_dir (tctx, ctx, s, d, FALSE, TRUE, TRUE, NULL); return_status = copy_dir_dir (ctx, s, d, FALSE, TRUE, TRUE, NULL);
if (return_status != FILE_CONT) if (return_status != FILE_CONT)
goto ret; goto ret;
@ -1697,7 +1692,7 @@ do_move_dir_dir (const WPanel *panel, file_op_total_context_t *tctx, file_op_con
goto ret; goto ret;
} }
return_status = copy_dir_dir (tctx, ctx, s, d, FALSE, FALSE, TRUE, NULL); return_status = copy_dir_dir (ctx, s, d, FALSE, FALSE, TRUE, NULL);
if (return_status != FILE_CONT) if (return_status != FILE_CONT)
goto ret; goto ret;
@ -1719,7 +1714,7 @@ do_move_dir_dir (const WPanel *panel, file_op_total_context_t *tctx, file_op_con
mc_refresh (); mc_refresh ();
erase_dir_after_copy (tctx, ctx, src_vpath, &return_status); erase_dir_after_copy (ctx, src_vpath, &return_status);
ret: ret:
erase_list = free_erase_list (erase_list); erase_list = free_erase_list (erase_list);
@ -2002,9 +1997,8 @@ do_confirm_erase (const WPanel *panel, const char *source, struct stat *src_stat
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
static FileProgressStatus static FileProgressStatus
operate_single_file (const WPanel *panel, file_op_total_context_t *tctx, file_op_context_t *ctx, operate_single_file (const WPanel *panel, file_op_context_t *ctx, const char *src,
const char *src, struct stat *src_stat, const char *dest, struct stat *src_stat, const char *dest, filegui_dialog_type_t dialog_type)
filegui_dialog_type_t dialog_type)
{ {
FileProgressStatus value; FileProgressStatus value;
vfs_path_t *src_vpath; vfs_path_t *src_vpath;
@ -2031,9 +2025,9 @@ operate_single_file (const WPanel *panel, file_op_total_context_t *tctx, file_op
if (value == FILE_CONT) if (value == FILE_CONT)
{ {
if (is_file) if (is_file)
value = erase_file (tctx, ctx, src_vpath); value = erase_file (ctx, src_vpath);
else else
value = erase_dir (tctx, ctx, src_vpath); value = erase_dir (ctx, src_vpath);
} }
} }
else else
@ -2069,9 +2063,9 @@ operate_single_file (const WPanel *panel, file_op_total_context_t *tctx, file_op
} }
if (is_file) if (is_file)
value = copy_file_file (tctx, ctx, src, dest); value = copy_file_file (ctx, src, dest);
else else
value = copy_dir_dir (tctx, ctx, src, dest, TRUE, FALSE, FALSE, NULL); value = copy_dir_dir (ctx, src, dest, TRUE, FALSE, FALSE, NULL);
} }
break; break;
@ -2083,9 +2077,9 @@ operate_single_file (const WPanel *panel, file_op_total_context_t *tctx, file_op
file_progress_ui_create (ctx, TRUE, FILEGUI_DIALOG_ONE_ITEM); file_progress_ui_create (ctx, TRUE, FILEGUI_DIALOG_ONE_ITEM);
if (is_file) if (is_file)
value = move_file_file (panel, tctx, ctx, src, dest); value = move_file_file (panel, ctx, src, dest);
else else
value = do_move_dir_dir (panel, tctx, ctx, src, dest); value = do_move_dir_dir (panel, ctx, src, dest);
break; break;
default: default:
@ -2105,8 +2099,8 @@ operate_single_file (const WPanel *panel, file_op_total_context_t *tctx, file_op
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
static FileProgressStatus static FileProgressStatus
operate_one_file (const WPanel *panel, file_op_total_context_t *tctx, file_op_context_t *ctx, operate_one_file (const WPanel *panel, file_op_context_t *ctx, const char *src,
const char *src, struct stat *src_stat, const char *dest) struct stat *src_stat, const char *dest)
{ {
FileProgressStatus value = FILE_CONT; FileProgressStatus value = FILE_CONT;
vfs_path_t *src_vpath; vfs_path_t *src_vpath;
@ -2122,9 +2116,9 @@ operate_one_file (const WPanel *panel, file_op_total_context_t *tctx, file_op_co
if (ctx->operation == OP_DELETE) if (ctx->operation == OP_DELETE)
{ {
if (is_file) if (is_file)
value = erase_file (tctx, ctx, src_vpath); value = erase_file (ctx, src_vpath);
else else
value = erase_dir (tctx, ctx, src_vpath); value = erase_dir (ctx, src_vpath);
} }
else else
{ {
@ -2145,17 +2139,17 @@ operate_one_file (const WPanel *panel, file_op_total_context_t *tctx, file_op_co
is_file = !S_ISDIR (src_stat->st_mode); is_file = !S_ISDIR (src_stat->st_mode);
if (is_file) if (is_file)
value = copy_file_file (tctx, ctx, src, dest); value = copy_file_file (ctx, src, dest);
else else
value = copy_dir_dir (tctx, ctx, src, dest, TRUE, FALSE, FALSE, NULL); value = copy_dir_dir (ctx, src, dest, TRUE, FALSE, FALSE, NULL);
dest_dirs = free_linklist (dest_dirs); dest_dirs = free_linklist (dest_dirs);
break; break;
case OP_MOVE: case OP_MOVE:
if (is_file) if (is_file)
value = move_file_file (NULL, tctx, ctx, src, dest); value = move_file_file (NULL, ctx, src, dest);
else else
value = do_move_dir_dir (NULL, tctx, ctx, src, dest); value = do_move_dir_dir (NULL, ctx, src, dest);
break; break;
default: default:
@ -2250,8 +2244,7 @@ file_is_symlink_to_dir (const vfs_path_t *vpath, struct stat *st, gboolean *stal
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
FileProgressStatus FileProgressStatus
copy_file_file (file_op_total_context_t *tctx, file_op_context_t *ctx, copy_file_file (file_op_context_t *ctx, const char *src_path, const char *dst_path)
const char *src_path, const char *dst_path)
{ {
uid_t src_uid = (uid_t) (-1); uid_t src_uid = (uid_t) (-1);
gid_t src_gid = (gid_t) (-1); gid_t src_gid = (gid_t) (-1);
@ -2363,7 +2356,7 @@ copy_file_file (file_op_total_context_t *tctx, file_op_context_t *ctx,
goto ret_fast; goto ret_fast;
/* Should we replace destination? */ /* Should we replace destination? */
if (tctx->ask_overwrite) if (ctx->ask_overwrite)
{ {
ctx->do_reget = 0; ctx->do_reget = 0;
return_status = query_replace (ctx, src_path, &src_stat, dst_path, &dst_stat); return_status = query_replace (ctx, src_path, &src_stat, dst_path, &dst_stat);
@ -2653,7 +2646,7 @@ copy_file_file (file_op_total_context_t *tctx, file_op_context_t *ctx,
if (verbose) if (verbose)
{ {
if (tctx->total_bps == 0 || (file_size / tctx->total_bps) > FILEOP_UPDATE_INTERVAL) if (ctx->total_bps == 0 || (file_size / ctx->total_bps) > FILEOP_UPDATE_INTERVAL)
file_progress_show (ctx, 0, file_size, "", TRUE); file_progress_show (ctx, 0, file_size, "", TRUE);
else else
file_progress_show (ctx, 1, 1, "", TRUE); file_progress_show (ctx, 1, 1, "", TRUE);
@ -2745,14 +2738,14 @@ copy_file_file (file_op_total_context_t *tctx, file_op_context_t *ctx,
} }
} }
tctx->copied_bytes = tctx->progress_bytes + file_part + ctx->do_reget; ctx->copied_bytes = ctx->progress_bytes + file_part + ctx->do_reget;
usecs = tv_current - tv_last_update; usecs = tv_current - tv_last_update;
update_usecs = tv_current - tv_last_input; update_usecs = tv_current - tv_last_input;
if (is_first_time || usecs > FILEOP_UPDATE_INTERVAL_US) if (is_first_time || usecs > FILEOP_UPDATE_INTERVAL_US)
{ {
copy_file_file_display_progress (tctx, ctx, tv_current, file_part, copy_file_file_display_progress (ctx, tv_current, file_part,
file_size - ctx->do_reget); file_size - ctx->do_reget);
tv_last_update = tv_current; tv_last_update = tv_current;
} }
@ -2762,14 +2755,14 @@ copy_file_file (file_op_total_context_t *tctx, file_op_context_t *ctx,
if (update_usecs > FILEOP_STALLING_INTERVAL_US) if (update_usecs > FILEOP_STALLING_INTERVAL_US)
stalled_msg = _("(stalled)"); stalled_msg = _("(stalled)");
force_update = (tv_current - tctx->total_transfer_start) > FILEOP_UPDATE_INTERVAL_US; force_update = (tv_current - ctx->total_transfer_start) > FILEOP_UPDATE_INTERVAL_US;
if (verbose) if (verbose)
{ {
if (ctx->dialog_type == FILEGUI_DIALOG_MULTI_ITEM) if (ctx->dialog_type == FILEGUI_DIALOG_MULTI_ITEM)
{ {
file_progress_show_count (ctx, tctx->progress_count, ctx->total_count); file_progress_show_count (ctx, ctx->progress_count, ctx->total_count);
file_progress_show_total (tctx, ctx, tctx->copied_bytes, force_update); file_progress_show_total (ctx, ctx->copied_bytes, force_update);
} }
file_progress_show (ctx, file_part + ctx->do_reget, file_size, stalled_msg, file_progress_show (ctx, file_part + ctx->do_reget, file_size, stalled_msg,
@ -2943,7 +2936,7 @@ copy_file_file (file_op_total_context_t *tctx, file_op_context_t *ctx,
} }
if (return_status == FILE_CONT) if (return_status == FILE_CONT)
return_status = progress_update_one (tctx, ctx, file_size); return_status = progress_update_one (ctx, file_size);
ret_fast: ret_fast:
vfs_path_free (src_vpath, TRUE); vfs_path_free (src_vpath, TRUE);
@ -2960,8 +2953,8 @@ copy_file_file (file_op_total_context_t *tctx, file_op_context_t *ctx,
function calls */ function calls */
FileProgressStatus FileProgressStatus
copy_dir_dir (file_op_total_context_t *tctx, file_op_context_t *ctx, const char *s, const char *d, copy_dir_dir (file_op_context_t *ctx, const char *s, const char *d, gboolean toplevel,
gboolean toplevel, gboolean move_over, gboolean do_delete, GSList *parent_dirs) gboolean move_over, gboolean do_delete, GSList *parent_dirs)
{ {
struct vfs_dirent *next; struct vfs_dirent *next;
struct stat dst_stat, src_stat; struct stat dst_stat, src_stat;
@ -3205,8 +3198,7 @@ copy_dir_dir (file_op_total_context_t *tctx, file_op_context_t *ctx, const char
* dir already exists. So, we give the recursive call the flag 0 * dir already exists. So, we give the recursive call the flag 0
* meaning no toplevel. * meaning no toplevel.
*/ */
return_status = return_status = copy_dir_dir (ctx, path, mdpath, FALSE, FALSE, do_delete, parent_dirs);
copy_dir_dir (tctx, ctx, path, mdpath, FALSE, FALSE, do_delete, parent_dirs);
g_free (mdpath); g_free (mdpath);
} }
else else
@ -3214,7 +3206,7 @@ copy_dir_dir (file_op_total_context_t *tctx, file_op_context_t *ctx, const char
char *dest_file; char *dest_file;
dest_file = mc_build_filename (d, x_basename (path), (char *) NULL); dest_file = mc_build_filename (d, x_basename (path), (char *) NULL);
return_status = copy_file_file (tctx, ctx, path, dest_file); return_status = copy_file_file (ctx, path, dest_file);
g_free (dest_file); g_free (dest_file);
} }
@ -3234,9 +3226,9 @@ copy_dir_dir (file_op_total_context_t *tctx, file_op_context_t *ctx, const char
tmp_vpath = NULL; tmp_vpath = NULL;
} }
else if (S_ISDIR (dst_stat.st_mode)) else if (S_ISDIR (dst_stat.st_mode))
return_status = erase_dir_iff_empty (ctx, tmp_vpath, tctx->progress_count); return_status = erase_dir_iff_empty (ctx, tmp_vpath, ctx->progress_count);
else else
return_status = erase_file (tctx, ctx, tmp_vpath); return_status = erase_file (ctx, tmp_vpath);
} }
vfs_path_free (tmp_vpath, TRUE); vfs_path_free (tmp_vpath, TRUE);
} }
@ -3277,9 +3269,9 @@ copy_dir_dir (file_op_total_context_t *tctx, file_op_context_t *ctx, const char
/* {{{ Move routines */ /* {{{ Move routines */
FileProgressStatus FileProgressStatus
move_dir_dir (file_op_total_context_t *tctx, file_op_context_t *ctx, const char *s, const char *d) move_dir_dir (file_op_context_t *ctx, const char *s, const char *d)
{ {
return do_move_dir_dir (NULL, tctx, ctx, s, d); return do_move_dir_dir (NULL, ctx, s, d);
} }
/* }}} */ /* }}} */
@ -3288,10 +3280,10 @@ move_dir_dir (file_op_total_context_t *tctx, file_op_context_t *ctx, const char
/* {{{ Erase routines */ /* {{{ Erase routines */
FileProgressStatus FileProgressStatus
erase_dir (file_op_total_context_t *tctx, file_op_context_t *ctx, const vfs_path_t *vpath) erase_dir (file_op_context_t *ctx, const vfs_path_t *vpath)
{ {
file_progress_show_deleting (ctx, vpath, NULL); file_progress_show_deleting (ctx, vpath, NULL);
file_progress_show_count (ctx, tctx->progress_count, ctx->total_count); file_progress_show_count (ctx, ctx->progress_count, ctx->total_count);
if (file_progress_check_buttons (ctx) == FILE_ABORT) if (file_progress_check_buttons (ctx) == FILE_ABORT)
return FILE_ABORT; return FILE_ABORT;
@ -3310,7 +3302,7 @@ erase_dir (file_op_total_context_t *tctx, file_op_context_t *ctx, const vfs_path
error = query_recursive (ctx, vfs_path_as_str (vpath)); error = query_recursive (ctx, vfs_path_as_str (vpath));
if (error == FILE_CONT) if (error == FILE_CONT)
error = recursive_erase (tctx, ctx, vpath); error = recursive_erase (ctx, vpath);
return error; return error;
} }
@ -3462,7 +3454,6 @@ panel_operate (void *source_panel, FileOperation operation, gboolean force_singl
int i; int i;
FileProgressStatus value; FileProgressStatus value;
file_op_context_t *ctx; file_op_context_t *ctx;
file_op_total_context_t *tctx;
filegui_dialog_type_t dialog_type = FILEGUI_DIALOG_ONE_ITEM; filegui_dialog_type_t dialog_type = FILEGUI_DIALOG_ONE_ITEM;
gboolean do_bg = FALSE; /* do background operation? */ gboolean do_bg = FALSE; /* do background operation? */
@ -3508,8 +3499,7 @@ panel_operate (void *source_panel, FileOperation operation, gboolean force_singl
goto ret_fast; goto ret_fast;
} }
tctx = file_op_total_context_new (); ctx->total_transfer_start = g_get_monotonic_time ();
tctx->total_transfer_start = g_get_monotonic_time ();
#ifdef ENABLE_BACKGROUND #ifdef ENABLE_BACKGROUND
/* Did the user select to do a background operation? */ /* Did the user select to do a background operation? */
@ -3586,7 +3576,7 @@ panel_operate (void *source_panel, FileOperation operation, gboolean force_singl
} }
} }
value = operate_single_file (panel, tctx, ctx, source, &src_stat, dest, dialog_type); value = operate_single_file (panel, ctx, source, &src_stat, dest, dialog_type);
if ((value == FILE_CONT) && !force_single) if ((value == FILE_CONT) && !force_single)
unmark_files (panel); unmark_files (panel);
} }
@ -3630,7 +3620,7 @@ panel_operate (void *source_panel, FileOperation operation, gboolean force_singl
source2 = panel->dir.list[i].fname->str; source2 = panel->dir.list[i].fname->str;
src_stat = panel->dir.list[i].st; src_stat = panel->dir.list[i].st;
value = operate_one_file (panel, tctx, ctx, source2, &src_stat, dest); value = operate_one_file (panel, ctx, source2, &src_stat, dest);
if (value == FILE_ABORT) if (value == FILE_ABORT)
break; break;
@ -3642,8 +3632,8 @@ panel_operate (void *source_panel, FileOperation operation, gboolean force_singl
{ {
if (ctx->dialog_type == FILEGUI_DIALOG_MULTI_ITEM) if (ctx->dialog_type == FILEGUI_DIALOG_MULTI_ITEM)
{ {
file_progress_show_count (ctx, tctx->progress_count, ctx->total_count); file_progress_show_count (ctx, ctx->progress_count, ctx->total_count);
file_progress_show_total (tctx, ctx, tctx->progress_bytes, FALSE); file_progress_show_total (ctx, ctx->progress_bytes, FALSE);
} }
if (operation != OP_DELETE) if (operation != OP_DELETE)
@ -3692,7 +3682,6 @@ panel_operate (void *source_panel, FileOperation operation, gboolean force_singl
} }
#endif /* ENABLE_BACKGROUND */ #endif /* ENABLE_BACKGROUND */
file_op_total_context_destroy (tctx);
ret_fast: ret_fast:
file_op_context_destroy (ctx); file_op_context_destroy (ctx);

View File

@ -41,16 +41,13 @@ struct dirsize_status_msg_t
gboolean file_is_symlink_to_dir (const vfs_path_t * path, struct stat *st, gboolean * stale_link); gboolean file_is_symlink_to_dir (const vfs_path_t * path, struct stat *st, gboolean * stale_link);
FileProgressStatus copy_file_file (file_op_total_context_t * tctx, file_op_context_t * ctx, FileProgressStatus copy_file_file (file_op_context_t * ctx, const char *src_path,
const char *src_path, const char *dst_path); const char *dst_path);
FileProgressStatus move_dir_dir (file_op_total_context_t * tctx, file_op_context_t * ctx, FileProgressStatus move_dir_dir (file_op_context_t * ctx, const char *s, const char *d);
const char *s, const char *d); FileProgressStatus copy_dir_dir (file_op_context_t * ctx, const char *s, const char *d,
FileProgressStatus copy_dir_dir (file_op_total_context_t * tctx, file_op_context_t * ctx,
const char *s, const char *d,
gboolean toplevel, gboolean move_over, gboolean do_delete, gboolean toplevel, gboolean move_over, gboolean do_delete,
GSList * parent_dirs); GSList * parent_dirs);
FileProgressStatus erase_dir (file_op_total_context_t * tctx, file_op_context_t * ctx, FileProgressStatus erase_dir (file_op_context_t * ctx, const vfs_path_t * vpath);
const vfs_path_t * vpath);
gboolean panel_operate (void *source_panel, FileOperation op, gboolean force_single); gboolean panel_operate (void *source_panel, FileOperation op, gboolean force_single);

View File

@ -1052,8 +1052,7 @@ file_progress_show_count (file_op_context_t *ctx, size_t done, size_t total)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
void void
file_progress_show_total (file_op_total_context_t *tctx, file_op_context_t *ctx, file_progress_show_total (file_op_context_t *ctx, uintmax_t copied_bytes, gboolean show_summary)
uintmax_t copied_bytes, gboolean show_summary)
{ {
char buffer2[BUF_TINY]; char buffer2[BUF_TINY];
char buffer3[BUF_TINY]; char buffer3[BUF_TINY];
@ -1076,7 +1075,7 @@ file_progress_show_total (file_op_total_context_t *tctx, file_op_context_t *ctx,
} }
} }
if (!show_summary && tctx->total_bps == 0) if (!show_summary && ctx->total_bps == 0)
return; return;
if (ui->time_label != NULL) if (ui->time_label != NULL)
@ -1085,26 +1084,26 @@ file_progress_show_total (file_op_total_context_t *tctx, file_op_context_t *ctx,
char buffer4[BUF_TINY]; char buffer4[BUF_TINY];
tv_current = g_get_monotonic_time (); tv_current = g_get_monotonic_time ();
file_frmt_time (buffer2, (tv_current - tctx->total_transfer_start) / G_USEC_PER_SEC); file_frmt_time (buffer2, (tv_current - ctx->total_transfer_start) / G_USEC_PER_SEC);
if (ctx->totals_computed) if (ctx->totals_computed)
{ {
file_eta_prepare_for_show (buffer3, tctx->total_eta_secs, TRUE); file_eta_prepare_for_show (buffer3, ctx->total_eta_secs, TRUE);
if (tctx->total_bps == 0) if (ctx->total_bps == 0)
label_set_textv (ui->time_label, _("Time: %s %s"), buffer2, buffer3); label_set_textv (ui->time_label, _("Time: %s %s"), buffer2, buffer3);
else else
{ {
file_bps_prepare_for_show (buffer4, (long) tctx->total_bps); file_bps_prepare_for_show (buffer4, (long) ctx->total_bps);
label_set_textv (ui->time_label, _("Time: %s %s (%s)"), buffer2, buffer3, buffer4); label_set_textv (ui->time_label, _("Time: %s %s (%s)"), buffer2, buffer3, buffer4);
} }
} }
else else
{ {
if (tctx->total_bps == 0) if (ctx->total_bps == 0)
label_set_textv (ui->time_label, _("Time: %s"), buffer2); label_set_textv (ui->time_label, _("Time: %s"), buffer2);
else else
{ {
file_bps_prepare_for_show (buffer4, (long) tctx->total_bps); file_bps_prepare_for_show (buffer4, (long) ctx->total_bps);
label_set_textv (ui->time_label, _("Time: %s (%s)"), buffer2, buffer4); label_set_textv (ui->time_label, _("Time: %s (%s)"), buffer2, buffer4);
} }
} }
@ -1112,7 +1111,7 @@ file_progress_show_total (file_op_total_context_t *tctx, file_op_context_t *ctx,
if (ui->total_bytes_label != NULL) if (ui->total_bytes_label != NULL)
{ {
size_trunc_len (buffer2, 5, tctx->copied_bytes, 0, panels_options.kilobyte_si); size_trunc_len (buffer2, 5, ctx->copied_bytes, 0, panels_options.kilobyte_si);
if (!ctx->totals_computed) if (!ctx->totals_computed)
hline_set_textv (ui->total_bytes_label, _(" Total: %s "), buffer2); hline_set_textv (ui->total_bytes_label, _(" Total: %s "), buffer2);

View File

@ -30,8 +30,8 @@ FileProgressStatus file_progress_check_buttons (file_op_context_t * ctx);
void file_progress_show (file_op_context_t * ctx, off_t done, off_t total, void file_progress_show (file_op_context_t * ctx, off_t done, off_t total,
const char *stalled_msg, gboolean force_update); const char *stalled_msg, gboolean force_update);
void file_progress_show_count (file_op_context_t * ctx, size_t done, size_t total); void file_progress_show_count (file_op_context_t * ctx, size_t done, size_t total);
void file_progress_show_total (file_op_total_context_t * tctx, file_op_context_t * ctx, void file_progress_show_total (file_op_context_t * ctx, uintmax_t copied_bytes,
uintmax_t copied_bytes, gboolean show_summary); gboolean show_summary);
void file_progress_show_source (file_op_context_t * ctx, const vfs_path_t * vpath); void file_progress_show_source (file_op_context_t * ctx, const vfs_path_t * vpath);
void file_progress_show_target (file_op_context_t * ctx, const vfs_path_t * vpath); void file_progress_show_target (file_op_context_t * ctx, const vfs_path_t * vpath);
gboolean file_progress_show_deleting (file_op_context_t * ctx, const vfs_path_t * vpath, gboolean file_progress_show_deleting (file_op_context_t * ctx, const vfs_path_t * vpath,

View File

@ -78,6 +78,7 @@ file_op_context_new (FileOperation op)
ctx->preserve_uidgid = (geteuid () == 0); ctx->preserve_uidgid = (geteuid () == 0);
ctx->umask_kill = (mode_t) (~0); ctx->umask_kill = (mode_t) (~0);
ctx->erase_at_end = TRUE; ctx->erase_at_end = TRUE;
ctx->ask_overwrite = TRUE;
return ctx; return ctx;
} }
@ -103,22 +104,3 @@ file_op_context_destroy (file_op_context_t *ctx)
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
file_op_total_context_t *
file_op_total_context_new (void)
{
file_op_total_context_t *tctx;
tctx = g_new0 (file_op_total_context_t, 1);
tctx->ask_overwrite = TRUE;
return tctx;
}
/* --------------------------------------------------------------------------------------------- */
void
file_op_total_context_destroy (file_op_total_context_t *tctx)
{
g_free (tctx);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -91,11 +91,20 @@ typedef struct
filegui_dialog_type_t dialog_type; filegui_dialog_type_t dialog_type;
/* Counters for progress indicators */ /* Counters for progress indicators */
size_t progress_count;
size_t prev_progress_count; /* Used in OP_MOVE between copy and remove directories */
uintmax_t progress_bytes;
uintmax_t copied_bytes;
size_t total_count; size_t total_count;
uintmax_t total_bytes; uintmax_t total_bytes;
/* Whether the panel total has been computed */ /* Whether the panel total has been computed */
gboolean totals_computed; gboolean totals_computed;
size_t total_bps;
gint64 total_transfer_start;
double total_eta_secs;
/* Result from the recursive query */ /* Result from the recursive query */
FileCopyMode recursive_result; FileCopyMode recursive_result;
@ -155,23 +164,12 @@ typedef struct
/* Whether the file operation is in pause */ /* Whether the file operation is in pause */
gboolean suspended; gboolean suspended;
gboolean ask_overwrite;
/* User interface data goes here */ /* User interface data goes here */
void *ui; void *ui;
} file_op_context_t; } file_op_context_t;
typedef struct
{
size_t progress_count;
size_t prev_progress_count; /* Used in OP_MOVE between copy and remove directories */
uintmax_t progress_bytes;
uintmax_t copied_bytes;
size_t total_bps;
gint64 total_transfer_start;
double total_eta_secs;
gboolean ask_overwrite;
} file_op_total_context_t;
/*** global variables defined in .c file *********************************************************/ /*** global variables defined in .c file *********************************************************/
extern const char *op_names[3]; extern const char *op_names[3];
@ -181,9 +179,6 @@ extern const char *op_names[3];
file_op_context_t *file_op_context_new (FileOperation op); file_op_context_t *file_op_context_new (FileOperation op);
void file_op_context_destroy (file_op_context_t * ctx); void file_op_context_destroy (file_op_context_t * ctx);
file_op_total_context_t *file_op_total_context_new (void);
void file_op_total_context_destroy (file_op_total_context_t * tctx);
/* The following functions are implemented separately by each port */ /* The following functions are implemented separately by each port */
FileProgressStatus file_progress_real_query_replace (file_op_context_t * ctx, FileProgressStatus file_progress_real_query_replace (file_op_context_t * ctx,
enum OperationMode mode, const char *src, enum OperationMode mode, const char *src,

View File

@ -723,15 +723,12 @@ tree_copy (WTree *tree, const char *default_dest)
if (dest != NULL && *dest != '\0') if (dest != NULL && *dest != '\0')
{ {
file_op_context_t *ctx; file_op_context_t *ctx;
file_op_total_context_t *tctx;
ctx = file_op_context_new (OP_COPY); ctx = file_op_context_new (OP_COPY);
tctx = file_op_total_context_new ();
file_progress_ui_create (ctx, FALSE, FILEGUI_DIALOG_MULTI_ITEM); file_progress_ui_create (ctx, FALSE, FILEGUI_DIALOG_MULTI_ITEM);
tctx->ask_overwrite = FALSE; ctx->ask_overwrite = FALSE;
copy_dir_dir (tctx, ctx, vfs_path_as_str (tree->selected_ptr->name), dest, TRUE, FALSE, copy_dir_dir (ctx, vfs_path_as_str (tree->selected_ptr->name), dest, TRUE, FALSE, FALSE,
FALSE, NULL); NULL);
file_op_total_context_destroy (tctx);
file_op_context_destroy (ctx); file_op_context_destroy (ctx);
} }
@ -770,13 +767,10 @@ tree_move (WTree *tree, const char *default_dest)
else else
{ {
file_op_context_t *ctx; file_op_context_t *ctx;
file_op_total_context_t *tctx;
ctx = file_op_context_new (OP_MOVE); ctx = file_op_context_new (OP_MOVE);
tctx = file_op_total_context_new ();
file_progress_ui_create (ctx, FALSE, FILEGUI_DIALOG_ONE_ITEM); file_progress_ui_create (ctx, FALSE, FILEGUI_DIALOG_ONE_ITEM);
move_dir_dir (tctx, ctx, vfs_path_as_str (tree->selected_ptr->name), dest); move_dir_dir (ctx, vfs_path_as_str (tree->selected_ptr->name), dest);
file_op_total_context_destroy (tctx);
file_op_context_destroy (ctx); file_op_context_destroy (ctx);
} }
@ -811,7 +805,6 @@ tree_rmdir (void *data)
{ {
WTree *tree = data; WTree *tree = data;
file_op_context_t *ctx; file_op_context_t *ctx;
file_op_total_context_t *tctx;
if (tree->selected_ptr == NULL) if (tree->selected_ptr == NULL)
return; return;
@ -830,12 +823,9 @@ tree_rmdir (void *data)
} }
ctx = file_op_context_new (OP_DELETE); ctx = file_op_context_new (OP_DELETE);
tctx = file_op_total_context_new ();
file_progress_ui_create (ctx, FALSE, FILEGUI_DIALOG_ONE_ITEM); file_progress_ui_create (ctx, FALSE, FILEGUI_DIALOG_ONE_ITEM);
if (erase_dir (tctx, ctx, tree->selected_ptr->name) == FILE_CONT) if (erase_dir (ctx, tree->selected_ptr->name) == FILE_CONT)
tree_forget (tree); tree_forget (tree);
file_op_total_context_destroy (tctx);
file_op_context_destroy (ctx); file_op_context_destroy (ctx);
} }

View File

@ -55,17 +55,14 @@ check_for_default (const vfs_path_t *default_file_vpath, const vfs_path_t *file_
if (!exist_file (vfs_path_as_str (file_vpath))) if (!exist_file (vfs_path_as_str (file_vpath)))
{ {
file_op_context_t *ctx; file_op_context_t *ctx;
file_op_total_context_t *tctx;
if (!exist_file (vfs_path_as_str (default_file_vpath))) if (!exist_file (vfs_path_as_str (default_file_vpath)))
return FALSE; return FALSE;
ctx = file_op_context_new (OP_COPY); ctx = file_op_context_new (OP_COPY);
tctx = file_op_total_context_new ();
file_progress_ui_create (ctx, 0, FALSE); file_progress_ui_create (ctx, 0, FALSE);
copy_file_file (tctx, ctx, vfs_path_as_str (default_file_vpath), copy_file_file (ctx, vfs_path_as_str (default_file_vpath),
vfs_path_as_str (file_vpath)); vfs_path_as_str (file_vpath));
file_op_total_context_destroy (tctx);
file_op_context_destroy (ctx); file_op_context_destroy (ctx);
} }