From 05e1e31072c12ff9a897ce1ba83bb53cb0518cd8 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Sat, 9 Nov 2013 08:44:48 +0100 Subject: [PATCH] core: create .conf file with default options only if the file does not exist (and not on read error with existing file) --- ChangeLog | 2 ++ src/core/wee-config-file.c | 26 ++++++++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index c81cfd37a..fb1d4f8d2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,8 @@ http://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes] == Version 0.4.3 (under dev) +* core: create .conf file with default options only if the file does not exist + (and not on read error with existing file) * core: fix highlight on action messages: skip the nick at beginning to prevent highlight on it (bug #40516) * core: add default keys `meta2-1;3H` / `meta2-1;3F` (alt+home/end) and diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c index c1aca9c7e..0603c0b2c 100644 --- a/src/core/wee-config-file.c +++ b/src/core/wee-config-file.c @@ -2199,26 +2199,28 @@ config_file_read_internal (struct t_config_file *config_file, int reload) return WEECHAT_CONFIG_READ_FILE_NOT_FOUND; /* build filename */ - filename_length = strlen (weechat_home) + strlen (config_file->filename) + 2; + filename_length = strlen (weechat_home) + strlen (DIR_SEPARATOR) + + strlen (config_file->filename) + 1; filename = malloc (filename_length); if (!filename) return WEECHAT_CONFIG_READ_MEMORY_ERROR; snprintf (filename, filename_length, "%s%s%s", weechat_home, DIR_SEPARATOR, config_file->filename); + + /* create file with default options if it does not exist */ + if (access (filename, F_OK) != 0) + config_file_write_internal (config_file, 1); + + /* read config file */ config_file->file = fopen (filename, "r"); if (!config_file->file) { - config_file_write_internal (config_file, 1); - config_file->file = fopen (filename, "r"); - if (!config_file->file) - { - gui_chat_printf (NULL, - _("%sWarning: configuration file \"%s\" not found"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - filename); - free (filename); - return WEECHAT_CONFIG_READ_FILE_NOT_FOUND; - } + gui_chat_printf (NULL, + _("%sWarning: configuration file \"%s\" not found"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + filename); + free (filename); + return WEECHAT_CONFIG_READ_FILE_NOT_FOUND; } if (!reload)