From 705afe88c0332317bedc0615fa851dd383aae9b3 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sat, 2 Mar 2013 16:33:21 +0400 Subject: [PATCH] (mc_config_new_or_override_file): minor optimization. Signed-off-by: Andrew Borodin --- lib/mcconfig/common.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/mcconfig/common.c b/lib/mcconfig/common.c index ea708df89..6deade237 100644 --- a/lib/mcconfig/common.c +++ b/lib/mcconfig/common.c @@ -58,29 +58,31 @@ mc_config_new_or_override_file (mc_config_t * mc_config, const gchar * ini_path, ssize_t cur_written; vfs_path_t *ini_vpath; - ini_vpath = vfs_path_from_str (ini_path); data = g_key_file_to_data (mc_config->handle, &len, NULL); if (!exist_file (ini_path)) { ret = g_file_set_contents (ini_path, data, len, error); g_free (data); - vfs_path_free (ini_vpath); return ret; } + mc_util_make_backup_if_possible (ini_path, "~"); + ini_vpath = vfs_path_from_str (ini_path); fd = mc_open (ini_vpath, O_WRONLY | O_TRUNC, 0); + vfs_path_free (ini_vpath); + if (fd == -1) { g_propagate_error (error, g_error_new (MC_ERROR, 0, "%s", unix_error_string (errno))); g_free (data); - vfs_path_free (ini_vpath); return FALSE; } for (written_data = data, total_written = len; (cur_written = mc_write (fd, (const void *) written_data, total_written)) > 0; - written_data += cur_written, total_written -= cur_written); + written_data += cur_written, total_written -= cur_written) + ; mc_close (fd); g_free (data); @@ -88,12 +90,10 @@ mc_config_new_or_override_file (mc_config_t * mc_config, const gchar * ini_path, { mc_util_restore_from_backup_if_possible (ini_path, "~"); g_propagate_error (error, g_error_new (MC_ERROR, 0, "%s", unix_error_string (errno))); - vfs_path_free (ini_vpath); return FALSE; } mc_util_unlink_backup_if_possible (ini_path, "~"); - vfs_path_free (ini_vpath); return TRUE; }