From 0780ef2970ed5fbcf63f38498c2b94671c64fadf Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sun, 28 Jul 2024 16:04:18 +0300 Subject: [PATCH] Refactoring of file and directory delete routines. * (file_progress_show_deleting): take 'vfs_path_t *' instead of 'char *'. * (try_erase_dir): likewise. * (erase_file): sync with new file_progress_show_deleting(). * (recursive_erase): sync with new file_progress_show_deleting() and try_erase_dir(). * (erase_dir_iff_empty): likewise. * (erase_dir): likewise. Signed-off-by: Andrew Borodin --- src/filemanager/file.c | 27 +++++++++++---------------- src/filemanager/filegui.c | 4 +++- src/filemanager/filegui.h | 3 ++- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/filemanager/file.c b/src/filemanager/file.c index 8ded73c9d..1428ae6f8 100644 --- a/src/filemanager/file.c +++ b/src/filemanager/file.c @@ -1386,7 +1386,7 @@ erase_file (file_op_total_context_t *tctx, file_op_context_t *ctx, const vfs_pat FileProgressStatus return_status; /* check buttons if deleting info was changed */ - if (file_progress_show_deleting (ctx, vfs_path_as_str (vpath), &tctx->progress_count)) + if (file_progress_show_deleting (ctx, vpath, &tctx->progress_count)) { file_progress_show_count (ctx, tctx->progress_count, ctx->progress_count); if (check_progress_buttons (ctx) == FILE_ABORT) @@ -1413,10 +1413,13 @@ erase_file (file_op_total_context_t *tctx, file_op_context_t *ctx, const vfs_pat /* --------------------------------------------------------------------------------------------- */ static FileProgressStatus -try_erase_dir (file_op_context_t *ctx, const char *dir) +try_erase_dir (file_op_context_t *ctx, const vfs_path_t *vpath) { + const char *dir; FileProgressStatus return_status = FILE_CONT; + dir = vfs_path_as_str (vpath); + while (my_rmdir (dir) != 0 && !ctx->skip_all) { return_status = file_error (TRUE, _("Cannot remove directory \"%s\"\n%s"), dir); @@ -1442,7 +1445,6 @@ recursive_erase (file_op_total_context_t *tctx, file_op_context_t *ctx, const vf { struct vfs_dirent *next; DIR *reading; - const char *s; FileProgressStatus return_status = FILE_CONT; reading = mc_opendir (vpath); @@ -1475,16 +1477,14 @@ recursive_erase (file_op_total_context_t *tctx, file_op_context_t *ctx, const vf if (return_status == FILE_ABORT) return FILE_ABORT; - s = vfs_path_as_str (vpath); - - file_progress_show_deleting (ctx, s, NULL); + file_progress_show_deleting (ctx, vpath, NULL); file_progress_show_count (ctx, tctx->progress_count, ctx->progress_count); if (check_progress_buttons (ctx) == FILE_ABORT) return FILE_ABORT; mc_refresh (); - return try_erase_dir (ctx, s); + return try_erase_dir (ctx, vpath); } /* --------------------------------------------------------------------------------------------- */ @@ -1528,11 +1528,7 @@ check_dir_is_empty (const vfs_path_t *vpath) static FileProgressStatus erase_dir_iff_empty (file_op_context_t *ctx, const vfs_path_t *vpath, size_t count) { - const char *s; - - s = vfs_path_as_str (vpath); - - file_progress_show_deleting (ctx, s, NULL); + file_progress_show_deleting (ctx, vpath, NULL); file_progress_show_count (ctx, count, ctx->progress_count); if (check_progress_buttons (ctx) == FILE_ABORT) return FILE_ABORT; @@ -1543,10 +1539,9 @@ erase_dir_iff_empty (file_op_context_t *ctx, const vfs_path_t *vpath, size_t cou return FILE_CONT; /* not empty or error */ - return try_erase_dir (ctx, s); + return try_erase_dir (ctx, vpath); } - /* --------------------------------------------------------------------------------------------- */ static void @@ -3258,7 +3253,7 @@ move_dir_dir (file_op_total_context_t *tctx, file_op_context_t *ctx, const char FileProgressStatus erase_dir (file_op_total_context_t *tctx, file_op_context_t *ctx, const vfs_path_t *vpath) { - file_progress_show_deleting (ctx, vfs_path_as_str (vpath), NULL); + file_progress_show_deleting (ctx, vpath, NULL); file_progress_show_count (ctx, tctx->progress_count, ctx->progress_count); if (check_progress_buttons (ctx) == FILE_ABORT) return FILE_ABORT; @@ -3282,7 +3277,7 @@ erase_dir (file_op_total_context_t *tctx, file_op_context_t *ctx, const vfs_path return error; } - return try_erase_dir (ctx, vfs_path_as_str (vpath)); + return try_erase_dir (ctx, vpath); } /* }}} */ diff --git a/src/filemanager/filegui.c b/src/filemanager/filegui.c index e3f6b5442..b6b0032d8 100644 --- a/src/filemanager/filegui.c +++ b/src/filemanager/filegui.c @@ -1176,7 +1176,7 @@ 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 char *s, size_t *count) +file_progress_show_deleting (file_op_context_t *ctx, const vfs_path_t *vpath, size_t *count) { static gint64 timestamp = 0; /* update with 25 FPS rate */ @@ -1192,12 +1192,14 @@ file_progress_show_deleting (file_op_context_t *ctx, const char *s, size_t *coun if (ret) { file_op_context_ui_t *ui; + const char *s; ui = ctx->ui; if (ui->src_file_label != NULL) label_set_text (ui->src_file_label, _("Deleting")); + s = vfs_path_as_str (vpath); label_set_text (ui->src_file, truncFileStringSecure (ui->op_dlg, s)); } diff --git a/src/filemanager/filegui.h b/src/filemanager/filegui.h index 47e17ab68..0eb412845 100644 --- a/src/filemanager/filegui.h +++ b/src/filemanager/filegui.h @@ -34,7 +34,8 @@ void file_progress_show_total (file_op_total_context_t * tctx, file_op_context_t uintmax_t copied_bytes, gboolean show_summary); 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); -gboolean file_progress_show_deleting (file_op_context_t * ctx, const char *path, size_t *count); +gboolean file_progress_show_deleting (file_op_context_t * ctx, const vfs_path_t * vpath, + size_t *count); /*** inline functions ****************************************************************************/ #endif /* MC__FILEGUI_H */