Ticket #19: mc_samefile_abort.diff

File mc_samefile_abort.diff, 2.9 KB (added by slavazanko, 15 years ago)

patch that fix this bug

  • src/file.c

    diff -urpN mc-4.6.1.org/src/file.c mc-4.6.1.cp/src/file.c
    old new enum { 
    458458    DEST_FULL                   /* Created, fully copied */ 
    459459}; 
    460460 
     461static int warn_same_file(const char *fmt, const char *a, const char *b) 
     462{ 
     463    char *msg; 
     464    /* We don't expect %d etc, just %s, so strlen(fmt) should be ok */ 
     465    int n = strlen(fmt) + strlen(a) + strlen(b) + 1; 
     466 
     467    msg = malloc(n); 
     468    if (msg) { 
     469        snprintf(msg, n, fmt, a, b); 
     470        n = query_dialog (MSG_ERROR, msg, 
     471                D_ERROR, 2, _("&Skip"), _("&Abort")); 
     472        free(msg); 
     473        do_refresh (); 
     474        if (n) /* 1 == Abort */ 
     475            return FILE_ABORT; 
     476    } 
     477    return FILE_SKIP; 
     478} 
     479 
    461480int 
    462481copy_file_file (FileOpContext *ctx, const char *src_path, const char *dst_path, 
    463482                int ask_overwrite, off_t *progress_count, 
    copy_file_file (FileOpContext *ctx, cons 
    512531 
    513532    if (dst_exists) { 
    514533        /* Destination already exists */ 
    515         if (sb.st_dev == sb2.st_dev && sb.st_ino == sb2.st_ino) { 
    516             message (1, MSG_ERROR, 
    517                     _(" `%s' and `%s' are the same file "), src_path, dst_path); 
    518             do_refresh (); 
    519             return FILE_SKIP; 
    520         } 
     534        if (sb.st_dev == sb2.st_dev && sb.st_ino == sb2.st_ino) 
     535            return warn_same_file(_(" `%s' and `%s' are the same file "), 
     536                                src_path, dst_path); 
    521537 
    522538        /* Should we replace destination? */ 
    523539        if (ask_overwrite) { 
    move_file_file (FileOpContext *ctx, cons 
    10431059 
    10441060    if (mc_lstat (d, &dst_stats) == 0) { 
    10451061        if (src_stats.st_dev == dst_stats.st_dev 
    1046             && src_stats.st_ino == dst_stats.st_ino) { 
    1047             int msize = COLS - 36; 
    1048             char st[MC_MAXPATHLEN]; 
    1049             char dt[MC_MAXPATHLEN]; 
    1050  
    1051             if (msize < 0) 
    1052                 msize = 40; 
    1053             msize /= 2; 
    1054  
    1055             strcpy (st, path_trunc (s, msize)); 
    1056             strcpy (dt, path_trunc (d, msize)); 
    1057             message (1, MSG_ERROR, 
    1058                         _(" `%s' and `%s' are the same file "), st, dt); 
    1059             do_refresh (); 
    1060             return FILE_SKIP; 
    1061         } 
     1062            && src_stats.st_ino == dst_stats.st_ino) 
     1063            return warn_same_file(_(" `%s' and `%s' are the same file "), s, d); 
    10621064 
    10631065        if (S_ISDIR (dst_stats.st_mode)) { 
    10641066            message (1, MSG_ERROR, 
    move_dir_dir (FileOpContext *ctx, const  
    11611163    } else 
    11621164        destdir = concat_dir_and_file (d, x_basename (s)); 
    11631165 
    1164     if (sbuf.st_dev == dbuf.st_dev && sbuf.st_ino == dbuf.st_ino) { 
    1165         int msize = COLS - 36; 
    1166         char st[MC_MAXPATHLEN]; 
    1167         char dt[MC_MAXPATHLEN]; 
    1168  
    1169         if (msize < 0) 
    1170             msize = 40; 
    1171         msize /= 2; 
    1172  
    1173         strcpy (st, path_trunc (s, msize)); 
    1174         strcpy (dt, path_trunc (d, msize)); 
    1175         message (1, MSG_ERROR, 
    1176                     _(" `%s' and `%s' are the same directory "), st, dt); 
    1177         do_refresh (); 
    1178         return FILE_SKIP; 
    1179     } 
     1166    if (sbuf.st_dev == dbuf.st_dev && sbuf.st_ino == dbuf.st_ino) 
     1167        return warn_same_file(_(" `%s' and `%s' are the same directory "), s, d); 
    11801168 
    11811169    /* Check if the user inputted an existing dir */ 
    11821170  retry_dst_stat: