From ac30e2226d2aac2dbd6a34bd12aa1c8902010662 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Sun, 11 Nov 2007 17:05:42 +0100 Subject: Added log directory creation in logger plugin, removed unused log config options in core --- src/plugins/logger/logger.c | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'src/plugins') diff --git a/src/plugins/logger/logger.c b/src/plugins/logger/logger.c index 0458a0395..3a0690ba6 100644 --- a/src/plugins/logger/logger.c +++ b/src/plugins/logger/logger.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -69,6 +70,51 @@ logger_config_read () } } +/* + * logger_create_directory: create logger directory + * return 1 if success, 0 if failed + */ + +int +logger_create_directory () +{ + int rc; + char *dir1, *dir2, *weechat_dir; + + rc = 1; + + dir1 = weechat_string_replace (logger_path, "~", getenv ("HOME")); + if (dir1) + { + weechat_dir = weechat_info_get ("weechat_dir"); + if (weechat_dir) + { + dir2 = weechat_string_replace (dir1, "%h", weechat_dir); + if (dir2) + { + if (mkdir (dir2, 0755) < 0) + { + if (errno != EEXIST) + rc = 0; + } + else + chmod (dir2, 0700); + free (dir2); + } + else + rc = 0; + free (weechat_dir); + } + else + rc = 0; + free (dir1); + } + else + rc = 0; + + return rc; +} + /* * logger_get_filename: build log filename for a buffer */ @@ -368,6 +414,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin) logger_config_read (); if (!logger_path || !logger_time_format) return PLUGIN_RC_FAILED; + if (!logger_create_directory ()) + return PLUGIN_RC_FAILED; logger_start_buffer_all (); -- cgit v1.2.3