Ticket #19: mc_samefile_abort.2.diff

File mc_samefile_abort.2.diff, 3.6 KB (added by angel_il, 16 years ago)
  • src/file.c

    From 8b6467421c12709ceee6680231e902601de22243 Mon Sep 17 00:00:00 2001
    From: admin <admin@holmes.(none)>
    Date: Thu, 5 Mar 2009 09:02:02 +0000
    Subject: [PATCH] Denis Vlasenko posted a patch which would fix issue when no dialog for break operation. Trouble: recently i accidentally entered '.' instead of '..' in the file copy dialog on a relatively big tree ... for every file in the tree i got the <foo> and <bar> are the same file message box, without any way to escape except killing mc from the outside.
    
    ---
     src/file.c |   65 ++++++++++++++++++++++++------------------------------------
     1 files changed, 26 insertions(+), 39 deletions(-)
    
    diff --git a/src/file.c b/src/file.c
    index 9e0e8c2..df0bf58 100644
    a b enum { 
    462462    DEST_FULL                   /* Created, fully copied */ 
    463463}; 
    464464 
     465static int warn_same_file(const char *fmt, const char *a, const char *b) 
     466{ 
     467    char *msg; 
     468    /* We don't expect %d etc, just %s, so strlen(fmt) should be ok */ 
     469    int n = strlen(fmt) + strlen(a) + strlen(b) + 1; 
     470 
     471    msg = malloc(n); 
     472    if (msg) { 
     473        snprintf(msg, n, fmt, a, b); 
     474        n = query_dialog (MSG_ERROR, msg, 
     475                D_ERROR, 2, _("&Skip"), _("&Abort")); 
     476        free(msg); 
     477        do_refresh (); 
     478        if (n) /* 1 == Abort */ 
     479            return FILE_ABORT; 
     480    } 
     481    return FILE_SKIP; 
     482} 
     483 
    465484int 
    466485copy_file_file (FileOpContext *ctx, const char *src_path, const char *dst_path, 
    467486                int ask_overwrite, off_t *progress_count, 
    copy_file_file (FileOpContext *ctx, const char *src_path, const char *dst_path, 
    516535 
    517536    if (dst_exists) { 
    518537        /* Destination already exists */ 
    519         if (sb.st_dev == sb2.st_dev && sb.st_ino == sb2.st_ino) { 
    520             message (D_ERROR, MSG_ERROR, 
    521                     _(" `%s' and `%s' are the same file "), src_path, dst_path); 
    522             do_refresh (); 
    523             return FILE_SKIP; 
    524         } 
    525  
     538        if (sb.st_dev == sb2.st_dev && sb.st_ino == sb2.st_ino) 
     539            return warn_same_file(_(" `%s' and `%s' are the same file "), 
     540                                src_path, dst_path); 
    526541        /* Should we replace destination? */ 
    527542        if (ask_overwrite) { 
    528543            ctx->do_reget = 0; 
    move_file_file (FileOpContext *ctx, const char *s, const char *d, 
    10481063 
    10491064    if (mc_lstat (d, &dst_stats) == 0) { 
    10501065        if (src_stats.st_dev == dst_stats.st_dev 
    1051             && src_stats.st_ino == dst_stats.st_ino) { 
    1052             int msize = COLS - 36; 
    1053             char st[MC_MAXPATHLEN]; 
    1054             char dt[MC_MAXPATHLEN]; 
    1055  
    1056             if (msize < 0) 
    1057                 msize = 40; 
    1058             msize /= 2; 
    1059  
    1060             strcpy (st, path_trunc (s, msize)); 
    1061             strcpy (dt, path_trunc (d, msize)); 
    1062             message (D_ERROR, MSG_ERROR, 
    1063                         _(" `%s' and `%s' are the same file "), st, dt); 
    1064             do_refresh (); 
    1065             return FILE_SKIP; 
    1066         } 
     1066            && src_stats.st_ino == dst_stats.st_ino) 
     1067            return warn_same_file(_(" `%s' and `%s' are the same file "), s, d); 
    10671068 
    10681069        if (S_ISDIR (dst_stats.st_mode)) { 
    10691070            message (D_ERROR, MSG_ERROR, 
    move_dir_dir (FileOpContext *ctx, const char *s, const char *d, 
    11711172    } else 
    11721173        destdir = concat_dir_and_file (d, x_basename (s)); 
    11731174 
    1174     if (sbuf.st_dev == dbuf.st_dev && sbuf.st_ino == dbuf.st_ino) { 
    1175         int msize = COLS - 36; 
    1176         char st[MC_MAXPATHLEN]; 
    1177         char dt[MC_MAXPATHLEN]; 
    1178  
    1179         if (msize < 0) 
    1180             msize = 40; 
    1181         msize /= 2; 
    1182  
    1183         strcpy (st, path_trunc (s, msize)); 
    1184         strcpy (dt, path_trunc (d, msize)); 
    1185         message (D_ERROR, MSG_ERROR, 
    1186                     _(" `%s' and `%s' are the same directory "), st, dt); 
    1187         do_refresh (); 
    1188         return FILE_SKIP; 
    1189     } 
     1175    if (sbuf.st_dev == dbuf.st_dev && sbuf.st_ino == dbuf.st_ino) 
     1176        return warn_same_file(_(" `%s' and `%s' are the same directory "), s, d); 
    11901177 
    11911178    /* Check if the user inputted an existing dir */ 
    11921179  retry_dst_stat: