updated: [689164a] copy/move dialog: add trailing '/' to default destination path (fix #181)



The following commit has been merged in the mc-4.6 branch:
commit 689164a6bc39b5c987c52141822db181f1be01f2
Author: Sergei Trofimovich <slyfox inbox ru>
Date:   Wed Jan 28 23:08:31 2009 +0200

    copy/move dialog: add trailing '/' to default destination path (fix #181)
    
    Problem:
      When user tried to copy/move file (F5/F6) - he could run into trouble if
      destination directory is removed (it can be removed by user from another mc session).
      Operation is performed and(!) file is renamed.
      So when when user issues 'cp /tmp/a.file /tmp/b' - he gets not expected /tmp/b/a.file,
      but /tmp.b !
    
    Solution:
      Add trailing space for destination directory for non-local copy/move(F5/F6) operations.
      So operation, given above will take form: 'cp /tmp/a.file /tmp/b/' disambiguating b
      meaning.
    
    Signed-off-by: Sergei Trofimovich <slyfox inbox ru>

diff --git a/src/file.c b/src/file.c
index a19633a..272f9a7 100644
--- a/src/file.c
+++ b/src/file.c
@@ -50,6 +50,8 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
+#include <mhl/string.h>
+
 #include "global.h"
 #include "tty.h"
 #include "eregex.h"
@@ -1777,6 +1779,7 @@ panel_operate (void *source_panel, FileOperation operation,
 	}
     } else if (operation != OP_DELETE) {
 	char *dest_dir;
+	char *dest_dir_;
 
 	/* Forced single operations default to the original name */
 	if (force_single)
@@ -1786,9 +1789,27 @@ panel_operate (void *source_panel, FileOperation operation,
 	else
 	    dest_dir = panel->cwd;
 
+	/*
+	 * Add trailing backslash only when do non-locally ops.
+	 * It saves user from occasional file renames (when destination
+	 * dir is deleted)
+	 */
+	if (force_single)
+	    // just copy
+	    dest_dir_ = mhl_str_dup (dest_dir);
+	else
+	    // add trailing separator
+	    dest_dir_ = mhl_str_concat (dest_dir, PATH_SEP_STR);
+	if (!dest_dir_) {
+	    file_op_context_destroy (ctx);
+	    return 0;
+	}
+
 	dest =
-	    file_mask_dialog (ctx, operation, cmd_buf, dest_dir,
+	    file_mask_dialog (ctx, operation, cmd_buf, dest_dir_,
 			      single_entry, &do_bg);
+	mhl_mem_free(dest_dir_);
+
 	if (!dest) {
 	    file_op_context_destroy (ctx);
 	    return 0;

-- 
Midnight Commander Development


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]