Ticket #181: 0001-copy-move-dialog-add-trailing-to-default-destin.patch

File 0001-copy-move-dialog-add-trailing-to-default-destin.patch, 2.2 KB (added by slyfox, 13 years ago)

Add trailing '/' when generate default copy/move dialog to disambiguate target_dir meaning.

  • src/file.c

    From ea499a0f02cb91a8c7b8c77dfefd47d917b9a349 Mon Sep 17 00:00:00 2001
    From: Sergei Trofimovich <slyfox@inbox.ru>
    Date: Wed, 28 Jan 2009 23:08:31 +0200
    Subject: [PATCH] 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>
    ---
     src/file.c |   25 ++++++++++++++++++++++++-
     1 files changed, 24 insertions(+), 1 deletions(-)
    
    diff --git a/src/file.c b/src/file.c
    index 73346ca..80b0ed7 100644
    a b  
    5050#include <sys/stat.h> 
    5151#include <unistd.h> 
    5252 
     53#include <mhl/string.h> 
     54 
    5355#include "global.h" 
    5456#include "tty.h" 
    5557#include "eregex.h" 
    panel_operate (void *source_panel, FileOperation operation, 
    17831785        } 
    17841786    } else if (operation != OP_DELETE) { 
    17851787        char *dest_dir; 
     1788        char *dest_dir_; 
    17861789 
    17871790        /* Forced single operations default to the original name */ 
    17881791        if (force_single) 
    panel_operate (void *source_panel, FileOperation operation, 
    17921795        else 
    17931796            dest_dir = panel->cwd; 
    17941797 
     1798        /* 
     1799         * Add trailing backslash only when do non-locally ops. 
     1800         * It saves user from occasional file renames (when destination 
     1801         * dir is deleted) 
     1802         */ 
     1803        if (force_single) 
     1804            // just copy 
     1805            dest_dir_ = mhl_str_dup (dest_dir); 
     1806        else 
     1807        { 
     1808            // add trailing separator 
     1809            dest_dir_ = mhl_str_concat (dest_dir, PATH_SEP_STR); 
     1810            if (!dest_dir_) { 
     1811                file_op_context_destroy (ctx); 
     1812                return 0; 
     1813            } 
     1814        } 
     1815 
    17951816        dest = 
    1796             file_mask_dialog (ctx, operation, cmd_buf, dest_dir, 
     1817            file_mask_dialog (ctx, operation, cmd_buf, dest_dir_, 
    17971818                              single_entry, &do_bg); 
     1819        mhl_mem_free(dest_dir_); 
     1820 
    17981821        if (!dest) { 
    17991822            file_op_context_destroy (ctx); 
    18001823            return 0;