From 58bba43490b98aa545d8eea4e6a042e868360749 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Sun, 15 Dec 2013 18:49:14 +0100 Subject: [PATCH] Ticket #3142: fix file out-of-date-ness check on saving. The code depended on the execution and outcome of the hardlink check. This was bogus - the two checks have nothing in common except the stat() call they both depend on. --- src/editor/editcmd.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index 202cb79fa..5aaa27ba5 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -159,11 +159,12 @@ edit_save_file (WEdit * edit, const vfs_path_t * filename_vpath) char *p; gchar *tmp; off_t filelen = 0; - int this_save_mode, fd = -1; + int this_save_mode, rv, fd = -1; vfs_path_t *real_filename_vpath; vfs_path_t *savename_vpath = NULL; const char *start_filename; const vfs_path_element_t *vpath_element; + struct stat sb; vpath_element = vfs_path_get_by_index (filename_vpath, 0); if (vpath_element == NULL) @@ -198,13 +199,10 @@ edit_save_file (WEdit * edit, const vfs_path_t * filename_vpath) mc_close (fd); } - if (this_save_mode == EDIT_QUICK_SAVE && !edit->skip_detach_prompt) + rv = mc_stat (real_filename_vpath, &sb); + if (rv == 0) { - int rv; - struct stat sb; - - rv = mc_stat (real_filename_vpath, &sb); - if (rv == 0 && sb.st_nlink > 1) + if (this_save_mode == EDIT_QUICK_SAVE && !edit->skip_detach_prompt && sb.st_nlink > 1) { rv = edit_query_dialog3 (_("Warning"), _("File has hard-links. Detach before saving?"), @@ -224,7 +222,7 @@ edit_save_file (WEdit * edit, const vfs_path_t * filename_vpath) } /* Prevent overwriting changes from other editor sessions. */ - if (rv == 0 && edit->stat1.st_mtime != 0 && edit->stat1.st_mtime != sb.st_mtime) + if (edit->stat1.st_mtime != 0 && edit->stat1.st_mtime != sb.st_mtime) { /* The default action is "Cancel". */ query_set_sel (1);