diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2012-03-13 18:13:45 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2012-03-13 18:13:45 +0100 |
commit | 3a2a1ce6f276d7fec7bddade3ef0471a72d691b4 (patch) | |
tree | 0991f19660330eeeba934d7332bb189b15c21d77 | |
parent | fc5f5a56dc9e444573aa226ae2a84df360b4f549 (diff) | |
download | weechat-3a2a1ce6f276d7fec7bddade3ef0471a72d691b4.zip |
core: follow symbolic links when writing configuration files (.conf) (task #11779)
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | src/core/wee-config-file.c | 18 |
2 files changed, 20 insertions, 2 deletions
@@ -1,12 +1,14 @@ WeeChat ChangeLog ================= Sébastien Helleu <flashcode@flashtux.org> -v0.3.8-dev, 2012-03-12 +v0.3.8-dev, 2012-03-13 Version 0.3.8 (under dev!) -------------------------- +* core: follow symbolic links when writing configuration files (.conf) + (task #11779) * core: fix lost scroll when switching to a buffer with a pending search * core: add support of terminal "bracketed paste mode", new options weechat.look.paste_bracketed and weechat.look.paste_bracketed_timer_delay diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c index dbcc231f0..59c9da9e2 100644 --- a/src/core/wee-config-file.c +++ b/src/core/wee-config-file.c @@ -26,6 +26,7 @@ #include "config.h" #endif +#include <limits.h> #include <stdlib.h> #include <stddef.h> #include <unistd.h> @@ -1911,7 +1912,7 @@ config_file_write_internal (struct t_config_file *config_file, int default_options) { int filename_length, rc; - char *filename, *filename2; + char *filename, *filename2, resolved_path[PATH_MAX]; struct t_config_section *ptr_section; struct t_config_option *ptr_option; @@ -1939,6 +1940,21 @@ config_file_write_internal (struct t_config_file *config_file, } snprintf (filename2, filename_length + 32, "%s.weechattmp", filename); + /* if filename is a symbolic link, use target as filename */ + if (realpath (filename, resolved_path)) + { + if (strcmp (filename, resolved_path) != 0) + { + free (filename); + filename = strdup (resolved_path); + if (!filename) + { + free (filename2); + return WEECHAT_CONFIG_WRITE_MEMORY_ERROR; + } + } + } + log_printf (_("Writing configuration file %s %s"), config_file->filename, (default_options) ? _("(default options)") : ""); |