src/file.c: move_dir_dir():

* changed type of move_over variable from int to gboolean;
    * fixed memory leak: destdir is not free'd when the same directory is copied;
    * don't use the non-valid dbuf variable if mc_stat(d, &dbuf) returns non-zero.
This commit is contained in:
Andrew Borodin 2009-03-08 13:22:10 +03:00 committed by Ilia Maslakov
parent 5df2f5aa22
commit 8353da9e8f

View File

@ -1146,7 +1146,8 @@ move_dir_dir (FileOpContext *ctx, const char *s, const char *d,
struct link *lp; struct link *lp;
char *destdir; char *destdir;
FileProgressStatus return_status; FileProgressStatus return_status;
int move_over = 0; gboolean move_over = FALSE;
gboolean dstat_ok;
if (file_progress_show_source (ctx, s) == FILE_ABORT || if (file_progress_show_source (ctx, s) == FILE_ABORT ||
file_progress_show_target (ctx, d) == FILE_ABORT) file_progress_show_target (ctx, d) == FILE_ABORT)
@ -1155,17 +1156,18 @@ move_dir_dir (FileOpContext *ctx, const char *s, const char *d,
mc_refresh (); mc_refresh ();
mc_stat (s, &sbuf); mc_stat (s, &sbuf);
if (mc_stat (d, &dbuf)) dstat_ok = (mc_stat (d, &dbuf) == 0);
if (dstat_ok && sbuf.st_dev == dbuf.st_dev && sbuf.st_ino == dbuf.st_ino)
return warn_same_file (_(" `%s' \n and \n `%s' \n are the same directory "), s, d);
if (!dstat_ok)
destdir = g_strdup (d); /* destination doesn't exist */ destdir = g_strdup (d); /* destination doesn't exist */
else if (!ctx->dive_into_subdirs) { else if (!ctx->dive_into_subdirs) {
destdir = g_strdup (d); destdir = g_strdup (d);
move_over = 1; move_over = TRUE;
} 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)
return warn_same_file(_(" `%s' and `%s' are the same directory "), s, d);
/* Check if the user inputted an existing dir */ /* Check if the user inputted an existing dir */
retry_dst_stat: retry_dst_stat:
if (!mc_stat (destdir, &destbuf)) { if (!mc_stat (destdir, &destbuf)) {