From 34712ec05b66b7bde2c10357ffd9145231a330a1 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Wed, 25 Apr 2018 11:35:59 +0300 Subject: [PATCH] Ticket #3913: implement safe file overwrite. Signed-off-by: Andrew Borodin --- doc/man/mc.1.in | 14 +++++++++++++- doc/man/ru/mc.1.in | 9 +++++++++ src/filemanager/boxes.c | 2 +- src/filemanager/filegui.c | 8 ++++---- src/setup.c | 3 +++ src/setup.h | 1 + 6 files changed, 31 insertions(+), 6 deletions(-) diff --git a/doc/man/mc.1.in b/doc/man/mc.1.in index 1a02c1e86..3303eff7e 100644 --- a/doc/man/mc.1.in +++ b/doc/man/mc.1.in @@ -1962,7 +1962,19 @@ and not to the directory where the link was present. .I Safe delete. If this option is enabled, deleting files and directory hotlist entries unintentionally becomes more difficult. The default selection in the -confirmation dialogs for deletion changes from "Yes" to "No". +confirmation dialogs for deletion changes from +.B Yes +to +.BR No . +This option is disabled by default. +.PP +.I Safe overwrite. +If this option is enabled, overwriting files unintentionally becomes +more difficult. The default selection in the overwrite confirmation dialog +changes from +.B Yes +to +.BR No . This option is disabled by default. .PP .I Auto save setup. diff --git a/doc/man/ru/mc.1.in b/doc/man/ru/mc.1.in index 09ecbc01a..f59bd8629 100644 --- a/doc/man/ru/mc.1.in +++ b/doc/man/ru/mc.1.in @@ -2104,6 +2104,15 @@ like regular expressions). Для того, чтобы достичь таког .BR Нет . По умолчанию эта опция отключена. .PP +.I Безопасная перезапись. +Если эта опция включена, непреднамеренно перезаписать файл будет сложнее. В +диалоговом окне подтверждения перезаписи предлагаемая по умолчанию кнопка +изменяется с +.B Да +на +.BR Нет . +По умолчанию эта опция отключена. +.PP .I Автосохранение настроек. Если эта опция включена, то при выходе из программы Midnight Commander значения всех настраиваемых параметров сохраняются в файле diff --git a/src/filemanager/boxes.c b/src/filemanager/boxes.c index c30be9750..a8f4e00e7 100644 --- a/src/filemanager/boxes.c +++ b/src/filemanager/boxes.c @@ -546,10 +546,10 @@ configure_box (void) QUICK_CHECKBOX (N_("Rotating d&ash"), &nice_rotating_dash, NULL), QUICK_CHECKBOX (N_("Cd follows lin&ks"), &mc_global.vfs.cd_symlinks, NULL), QUICK_CHECKBOX (N_("Sa&fe delete"), &safe_delete, NULL), + QUICK_CHECKBOX (N_("Safe overwrite"), &safe_overwrite, NULL), /* w/o hotkey */ QUICK_CHECKBOX (N_("A&uto save setup"), &auto_save_setup, NULL), QUICK_SEPARATOR (FALSE), QUICK_SEPARATOR (FALSE), - QUICK_SEPARATOR (FALSE), QUICK_STOP_GROUPBOX, QUICK_STOP_COLUMNS, QUICK_BUTTONS_OK_CANCEL, diff --git a/src/filemanager/filegui.c b/src/filemanager/filegui.c index f0053ecbb..8c4fcc030 100644 --- a/src/filemanager/filegui.c +++ b/src/filemanager/filegui.c @@ -157,7 +157,7 @@ statfs (char const *filename, struct fs_info *buf) #include "lib/util.h" #include "lib/widget.h" -#include "src/setup.h" /* verbose */ +#include "src/setup.h" /* verbose, safe_overwrite */ #include "midnight.h" #include "fileopctx.h" /* FILE_CONT */ @@ -409,7 +409,7 @@ overwrite_query_dialog (file_op_context_t * ctx, enum OperationMode mode) const int rd_ylen = 1; int rd_xlen = 60; int y = 2; - unsigned long yes_id; + unsigned long yes_id, no_id; struct { @@ -565,7 +565,7 @@ overwrite_query_dialog (file_op_context_t * ctx, enum OperationMode mode) ADD_RD_LABEL (4, 0, 0, y); /* Overwrite this target? */ yes_id = ADD_RD_BUTTON (5, y); /* Yes */ - ADD_RD_BUTTON (6, y); /* No */ + no_id = ADD_RD_BUTTON (6, y); /* No */ /* "this target..." widgets */ if (!S_ISDIR (ui->d_stat->st_mode)) @@ -591,7 +591,7 @@ overwrite_query_dialog (file_op_context_t * ctx, enum OperationMode mode) label_set_text (LABEL (label1), str_trunc (stripped_name, rd_xlen - 8)); dlg_set_size (ui->replace_dlg, y + 3, rd_xlen); - dlg_select_by_id (ui->replace_dlg, yes_id); + dlg_select_by_id (ui->replace_dlg, safe_overwrite ? no_id : yes_id); result = dlg_run (ui->replace_dlg); dlg_destroy (ui->replace_dlg); diff --git a/src/setup.c b/src/setup.c index 9f4361cfe..f0fe3a78c 100644 --- a/src/setup.c +++ b/src/setup.c @@ -87,6 +87,8 @@ gboolean boot_current_is_left = TRUE; /* If on, default for "No" in delete operations */ gboolean safe_delete = FALSE; +/* If on, default for "No" in overwrite files */ +gboolean safe_overwrite = FALSE; /* Controls screen clearing before an exec */ gboolean clear_before_exec = TRUE; @@ -293,6 +295,7 @@ static const struct { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete }, { "confirm_view_dir", &confirm_view_dir }, { "safe_delete", &safe_delete }, + { "safe_overwrite", &safe_overwrite }, #ifndef HAVE_CHARSET { "eight_bit_clean", &mc_global.eight_bit_clean }, { "full_eight_bits", &mc_global.full_eight_bits }, diff --git a/src/setup.h b/src/setup.h index b483d7da9..7de0fe393 100644 --- a/src/setup.h +++ b/src/setup.h @@ -82,6 +82,7 @@ extern gboolean confirm_exit; extern gboolean confirm_overwrite; extern gboolean confirm_view_dir; extern gboolean safe_delete; +extern gboolean safe_overwrite; extern gboolean clear_before_exec; extern gboolean auto_menu; extern gboolean drop_menus; -- 2.11.4.GIT