From e2fb1c8dd33fde79569722bd812a17381141ba5a Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Fri, 24 Aug 2012 16:01:15 +0300 Subject: [PATCH] Ticket #2832: Fixed mcedit: unable to save changes in "Safe save" mode If mcedit is configured to use "Safe save" I'm unable to save changes to existing file. Same problem is for editor_option_save_mode=2 (backup mode) Saving to new file works. Signed-off-by: Slava Zanko --- src/editor/editcmd.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index 2261aaadb..536ac7e1f 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -222,7 +222,8 @@ edit_save_file (WEdit * edit, const vfs_path_t * filename_vpath) if (savedir == NULL) savedir = g_strdup ("."); - saveprefix = mc_build_filename (savedir, "cooledit", NULL); + /* Token-related function never return leading slash, so we need add it manually */ + saveprefix = mc_build_filename ("/", savedir, "cooledit", NULL); g_free (savedir); fd = mc_mkstemps (&savename_vpath, saveprefix, NULL); g_free (saveprefix); @@ -365,13 +366,21 @@ edit_save_file (WEdit * edit, const vfs_path_t * filename_vpath) if (this_save_mode == EDIT_DO_BACKUP) { + char *tmp_store_filename; + vfs_path_element_t *last_vpath_element; vfs_path_t *tmp_vpath; gboolean ok; #ifdef HAVE_ASSERT_H assert (option_backup_ext != NULL); #endif - tmp_vpath = vfs_path_append_new (real_filename_vpath, option_backup_ext, (char *) NULL); + /* add backup extention to the path */ + tmp_vpath = vfs_path_clone (real_filename_vpath); + last_vpath_element = (vfs_path_element_t *) vfs_path_get_by_index (tmp_vpath, -1); + tmp_store_filename = last_vpath_element->path; + last_vpath_element->path = g_strdup_printf ("%s%s", tmp_store_filename, option_backup_ext); + g_free (tmp_store_filename); + ok = (mc_rename (real_filename_vpath, tmp_vpath) != -1); vfs_path_free (tmp_vpath); if (!ok) -- 2.11.4.GIT