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. Rework warn_same_file for more usage glib. ... msg = g_strdup_printf() ...

This commit is contained in:
Ilia Maslakov 2009-03-05 09:59:50 +00:00
parent a9d662aa57
commit a079bd950c

View File

@ -462,6 +462,22 @@ enum {
DEST_FULL /* Created, fully copied */ DEST_FULL /* Created, fully copied */
}; };
static int warn_same_file(const char *fmt, const char *a, const char *b)
{
char *msg;
/* We don't expect %d etc, just %s, so strlen(fmt) should be ok */
int result = 0;
msg = g_strdup_printf (fmt, a, b);
result = query_dialog (MSG_ERROR, msg, D_ERROR, 2, _("&Skip"), _("&Abort"));
g_free(msg);
do_refresh ();
if ( result ) { /* 1 == Abort */
return FILE_ABORT;
} else {
return FILE_SKIP;
}
}
int int
copy_file_file (FileOpContext *ctx, const char *src_path, const char *dst_path, copy_file_file (FileOpContext *ctx, const char *src_path, const char *dst_path,
int ask_overwrite, off_t *progress_count, int ask_overwrite, off_t *progress_count,
@ -516,13 +532,9 @@ copy_file_file (FileOpContext *ctx, const char *src_path, const char *dst_path,
if (dst_exists) { if (dst_exists) {
/* Destination already exists */ /* Destination already exists */
if (sb.st_dev == sb2.st_dev && sb.st_ino == sb2.st_ino) { if (sb.st_dev == sb2.st_dev && sb.st_ino == sb2.st_ino)
message (1, MSG_ERROR, return warn_same_file(_(" `%s' and `%s' are the same file "),
_(" `%s' and `%s' are the same file "), src_path, dst_path); src_path, dst_path);
do_refresh ();
return FILE_SKIP;
}
/* Should we replace destination? */ /* Should we replace destination? */
if (ask_overwrite) { if (ask_overwrite) {
ctx->do_reget = 0; ctx->do_reget = 0;
@ -1048,23 +1060,8 @@ move_file_file (FileOpContext *ctx, const char *s, const char *d,
if (mc_lstat (d, &dst_stats) == 0) { if (mc_lstat (d, &dst_stats) == 0) {
if (src_stats.st_dev == dst_stats.st_dev if (src_stats.st_dev == dst_stats.st_dev
&& src_stats.st_ino == dst_stats.st_ino) { && src_stats.st_ino == dst_stats.st_ino)
int msize = COLS - 36; return warn_same_file(_(" `%s' and `%s' are the same file "), s, d);
char st[MC_MAXPATHLEN];
char dt[MC_MAXPATHLEN];
if (msize < 0)
msize = 40;
msize /= 2;
strcpy (st, path_trunc (s, msize));
strcpy (dt, path_trunc (d, msize));
message (1, MSG_ERROR,
_(" `%s' and `%s' are the same file "), st, dt);
do_refresh ();
return FILE_SKIP;
}
if (S_ISDIR (dst_stats.st_mode)) { if (S_ISDIR (dst_stats.st_mode)) {
message (1, MSG_ERROR, message (1, MSG_ERROR,
_(" Cannot overwrite directory `%s' "), d); _(" Cannot overwrite directory `%s' "), d);
@ -1171,22 +1168,8 @@ move_dir_dir (FileOpContext *ctx, const char *s, const char *d,
} else } else
destdir = concat_dir_and_file (d, x_basename (s)); destdir = concat_dir_and_file (d, x_basename (s));
if (sbuf.st_dev == dbuf.st_dev && sbuf.st_ino == dbuf.st_ino) { if (sbuf.st_dev == dbuf.st_dev && sbuf.st_ino == dbuf.st_ino)
int msize = COLS - 36; return warn_same_file(_(" `%s' and `%s' are the same directory "), s, d);
char st[MC_MAXPATHLEN];
char dt[MC_MAXPATHLEN];
if (msize < 0)
msize = 40;
msize /= 2;
strcpy (st, path_trunc (s, msize));
strcpy (dt, path_trunc (d, msize));
message (1, MSG_ERROR,
_(" `%s' and `%s' are the same directory "), st, dt);
do_refresh ();
return FILE_SKIP;
}
/* Check if the user inputted an existing dir */ /* Check if the user inputted an existing dir */
retry_dst_stat: retry_dst_stat: