From a290589f7cb3c4d59afa1a3a9a67f0b7eda4720a Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Sun, 17 Mar 2013 18:45:55 +0100 Subject: [PATCH] scripts: create directories (language and language/autoload) on each action (install/remove/autoload), just in case they have been removed (bug #38473) --- ChangeLog | 6 ++++-- src/plugins/plugin-script.c | 42 +++++++++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 70a158caf..9433f8f74 100644 --- a/ChangeLog +++ b/ChangeLog @@ -71,11 +71,13 @@ Version 0.4.1 (under dev!) * rmodifier: rename default rmodifier "nickserv" to "command_auth" (with new modifier "irc_command_auth"), add default rmodifier "message_auth" (modifier "irc_message_auth") -* script: create "script" directory on each action (just in case it has been - removed) (bug #38472) +* script: create "script" directory on each action, just in case it has been + removed (bug #38472) * script: add option script.scripts.autoload, add options "autoload", "noautoload" and "toggleautoload" for command /script, add action "A" (meta-A) on script buffer (toggle autoload) (task #12393) +* scripts: create directories (language and language/autoload) on each action + (install/remove/autoload), just in case they have been removed (bug #38473) * scripts: do not allow empty script name in function "register" * xfer: fix freeze of DCC file received: use non-blocking socket after connection to sender and ensure the ACK is properly sent (bug #38340) diff --git a/src/plugins/plugin-script.c b/src/plugins/plugin-script.c index 3f311cccc..8acfe54cf 100644 --- a/src/plugins/plugin-script.c +++ b/src/plugins/plugin-script.c @@ -78,6 +78,29 @@ plugin_script_config_cb (void *data, const char *option, const char *value) return WEECHAT_RC_OK; } +/* + * Creates directories for plugin in WeeChat home: + * - ~/.weechat/XXX/ + * - ~/.weechat/XXX/autoload/ + */ + +void +plugin_script_create_dirs (struct t_weechat_plugin *weechat_plugin) +{ + char *string; + int length; + + weechat_mkdir_home (weechat_plugin->name, 0755); + length = strlen (weechat_plugin->name) + strlen ("/autoload") + 1; + string = malloc (length); + if (string) + { + snprintf (string, length, "%s/autoload", weechat_plugin->name); + weechat_mkdir_home (string, 0755); + free (string); + } +} + /* * Initializes script plugin: * - reads configuration @@ -112,15 +135,7 @@ plugin_script_init (struct t_weechat_plugin *weechat_plugin, } /* create directories in WeeChat home */ - weechat_mkdir_home (weechat_plugin->name, 0755); - length = strlen (weechat_plugin->name) + strlen ("/autoload") + 1; - string = malloc (length); - if (string) - { - snprintf (string, length, "%s/autoload", weechat_plugin->name); - weechat_mkdir_home (string, 0755); - free (string); - } + plugin_script_create_dirs (weechat_plugin); /* add command */ completion = NULL; @@ -952,6 +967,9 @@ plugin_script_action_install (struct t_weechat_plugin *weechat_plugin, if (!*list) return; + /* create again directories, just in case they have been removed */ + plugin_script_create_dirs (weechat_plugin); + ptr_list = *list; autoload = 0; *quiet = 0; @@ -1094,6 +1112,9 @@ plugin_script_action_remove (struct t_weechat_plugin *weechat_plugin, if (!*list) return; + /* create again directories, just in case they have been removed */ + plugin_script_create_dirs (weechat_plugin); + ptr_list = *list; *quiet = 0; if (strncmp (ptr_list, "-q ", 3) == 0) @@ -1146,6 +1167,9 @@ plugin_script_action_autoload (struct t_weechat_plugin *weechat_plugin, if (!*list) return; + /* create again directories, just in case they have been removed */ + plugin_script_create_dirs (weechat_plugin); + ptr_list = *list; autoload = 0; *quiet = 0;