Browse Source

Ticket #3913: implement safe file overwrite.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Andrew Borodin 6 years ago
parent
commit
34712ec05b
6 changed files with 31 additions and 6 deletions
  1. 13 1
      doc/man/mc.1.in
  2. 9 0
      doc/man/ru/mc.1.in
  3. 1 1
      src/filemanager/boxes.c
  4. 4 4
      src/filemanager/filegui.c
  5. 3 0
      src/setup.c
  6. 1 0
      src/setup.h

+ 13 - 1
doc/man/mc.1.in

@@ -1962,7 +1962,19 @@ and not to the directory where the link was present.
 .I Safe delete.
 .I Safe delete.
 If this option is enabled, deleting files and directory hotlist entries
 If this option is enabled, deleting files and directory hotlist entries
 unintentionally becomes more difficult.  The default selection in the
 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.
 This option is disabled by default.
 .PP
 .PP
 .I Auto save setup.
 .I Auto save setup.

+ 9 - 0
doc/man/ru/mc.1.in

@@ -2104,6 +2104,15 @@ like regular expressions). Для того, чтобы достичь таког
 .BR Нет .
 .BR Нет .
 По умолчанию эта опция отключена.
 По умолчанию эта опция отключена.
 .PP
 .PP
+.I Безопасная перезапись.
+Если эта опция включена, непреднамеренно перезаписать файл будет сложнее. В
+диалоговом окне подтверждения перезаписи предлагаемая по умолчанию кнопка
+изменяется с
+.B Да
+на
+.BR Нет .
+По умолчанию эта опция отключена.
+.PP
 .I Автосохранение настроек.
 .I Автосохранение настроек.
 Если эта опция включена, то при выходе из программы Midnight Commander
 Если эта опция включена, то при выходе из программы Midnight Commander
 значения всех настраиваемых параметров сохраняются в файле
 значения всех настраиваемых параметров сохраняются в файле

+ 1 - 1
src/filemanager/boxes.c

@@ -546,10 +546,10 @@ configure_box (void)
                     QUICK_CHECKBOX (N_("Rotating d&ash"), &nice_rotating_dash, NULL),
                     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_("Cd follows lin&ks"), &mc_global.vfs.cd_symlinks, NULL),
                     QUICK_CHECKBOX (N_("Sa&fe delete"), &safe_delete, 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_CHECKBOX (N_("A&uto save setup"), &auto_save_setup, NULL),
                     QUICK_SEPARATOR (FALSE),
                     QUICK_SEPARATOR (FALSE),
                     QUICK_SEPARATOR (FALSE),
                     QUICK_SEPARATOR (FALSE),
-                    QUICK_SEPARATOR (FALSE),
                 QUICK_STOP_GROUPBOX,
                 QUICK_STOP_GROUPBOX,
             QUICK_STOP_COLUMNS,
             QUICK_STOP_COLUMNS,
             QUICK_BUTTONS_OK_CANCEL,
             QUICK_BUTTONS_OK_CANCEL,

+ 4 - 4
src/filemanager/filegui.c

@@ -157,7 +157,7 @@ statfs (char const *filename, struct fs_info *buf)
 #include "lib/util.h"
 #include "lib/util.h"
 #include "lib/widget.h"
 #include "lib/widget.h"
 
 
-#include "src/setup.h"          /* verbose */
+#include "src/setup.h"          /* verbose, safe_overwrite */
 
 
 #include "midnight.h"
 #include "midnight.h"
 #include "fileopctx.h"          /* FILE_CONT */
 #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;
     const int rd_ylen = 1;
     int rd_xlen = 60;
     int rd_xlen = 60;
     int y = 2;
     int y = 2;
-    unsigned long yes_id;
+    unsigned long yes_id, no_id;
 
 
     struct
     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? */
     ADD_RD_LABEL (4, 0, 0, y);  /* Overwrite this target? */
     yes_id = ADD_RD_BUTTON (5, y);      /* Yes */
     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 */
     /* "this target..." widgets */
     if (!S_ISDIR (ui->d_stat->st_mode))
     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));
     label_set_text (LABEL (label1), str_trunc (stripped_name, rd_xlen - 8));
     dlg_set_size (ui->replace_dlg, y + 3, rd_xlen);
     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);
     result = dlg_run (ui->replace_dlg);
     dlg_destroy (ui->replace_dlg);
     dlg_destroy (ui->replace_dlg);
 
 

+ 3 - 0
src/setup.c

@@ -87,6 +87,8 @@ gboolean boot_current_is_left = TRUE;
 
 
 /* If on, default for "No" in delete operations */
 /* If on, default for "No" in delete operations */
 gboolean safe_delete = FALSE;
 gboolean safe_delete = FALSE;
+/* If on, default for "No" in overwrite files */
+gboolean safe_overwrite = FALSE;
 
 
 /* Controls screen clearing before an exec */
 /* Controls screen clearing before an exec */
 gboolean clear_before_exec = TRUE;
 gboolean clear_before_exec = TRUE;
@@ -293,6 +295,7 @@ static const struct
     { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete },
     { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete },
     { "confirm_view_dir", &confirm_view_dir },
     { "confirm_view_dir", &confirm_view_dir },
     { "safe_delete", &safe_delete },
     { "safe_delete", &safe_delete },
+    { "safe_overwrite", &safe_overwrite },
 #ifndef HAVE_CHARSET
 #ifndef HAVE_CHARSET
     { "eight_bit_clean", &mc_global.eight_bit_clean },
     { "eight_bit_clean", &mc_global.eight_bit_clean },
     { "full_eight_bits", &mc_global.full_eight_bits },
     { "full_eight_bits", &mc_global.full_eight_bits },

+ 1 - 0
src/setup.h

@@ -82,6 +82,7 @@ extern gboolean confirm_exit;
 extern gboolean confirm_overwrite;
 extern gboolean confirm_overwrite;
 extern gboolean confirm_view_dir;
 extern gboolean confirm_view_dir;
 extern gboolean safe_delete;
 extern gboolean safe_delete;
+extern gboolean safe_overwrite;
 extern gboolean clear_before_exec;
 extern gboolean clear_before_exec;
 extern gboolean auto_menu;
 extern gboolean auto_menu;
 extern gboolean drop_menus;
 extern gboolean drop_menus;