summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2023-09-22 22:51:44 +0200
committerSébastien Helleu <flashcode@flashtux.org>2023-09-22 22:51:44 +0200
commitd6e4e87faf90eacf9be316b024cc1dce0fd683ee (patch)
treea872666260be430bfc7eb2d7ea6e66e76e7744c0
parent12106ae7ba0c149e2c3a2fe7fa65d48acc851249 (diff)
downloadweechat-d6e4e87faf90eacf9be316b024cc1dce0fd683ee.zip
script: fix removal of script in system directory while trying to install a script (closes #2019)
-rw-r--r--ChangeLog.adoc1
-rw-r--r--src/plugins/guile/weechat-guile.c2
-rw-r--r--src/plugins/javascript/weechat-js.cpp2
-rw-r--r--src/plugins/lua/weechat-lua.c2
-rw-r--r--src/plugins/perl/weechat-perl.c2
-rw-r--r--src/plugins/php/weechat-php.c2
-rw-r--r--src/plugins/plugin-script.c38
-rw-r--r--src/plugins/plugin-script.h3
-rw-r--r--src/plugins/python/weechat-python.c2
-rw-r--r--src/plugins/ruby/weechat-ruby.c2
-rw-r--r--src/plugins/tcl/weechat-tcl.c2
11 files changed, 32 insertions, 26 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc
index 27734bb99..1d5130a19 100644
--- a/ChangeLog.adoc
+++ b/ChangeLog.adoc
@@ -68,6 +68,7 @@ Bug fixes::
* irc: add missing "account-tag" in list of supported capabilities
* irc: add channel in "autojoin" server option only when the channel is actually joined (issue #1990)
* relay: synchronize nick modes with IRC client upon connection (issue #1984)
+ * script: fix removal of script in system directory while trying to install a script (issue #2019)
* script: fix autoload of multiple scripts at once with `/script autoload` (issue #2018)
* script: fix crash when a `/script` command triggers another `/script` command (issue #923)
* script: add local key bindings during the buffer creation
diff --git a/src/plugins/guile/weechat-guile.c b/src/plugins/guile/weechat-guile.c
index ce9cd4d87..678cbd5cd 100644
--- a/src/plugins/guile/weechat-guile.c
+++ b/src/plugins/guile/weechat-guile.c
@@ -876,7 +876,7 @@ weechat_guile_command_cb (const void *pointer, void *data,
{
/* load guile script */
path_script = plugin_script_search_path (weechat_guile_plugin,
- ptr_name);
+ ptr_name, 1);
weechat_guile_load ((path_script) ? path_script : ptr_name,
NULL);
if (path_script)
diff --git a/src/plugins/javascript/weechat-js.cpp b/src/plugins/javascript/weechat-js.cpp
index a33b2d1be..446586396 100644
--- a/src/plugins/javascript/weechat-js.cpp
+++ b/src/plugins/javascript/weechat-js.cpp
@@ -657,7 +657,7 @@ weechat_js_command_cb (const void *pointer, void *data,
{
/* load javascript script */
path_script = plugin_script_search_path (weechat_js_plugin,
- ptr_name);
+ ptr_name, 1);
weechat_js_load ((path_script) ? path_script : ptr_name,
NULL);
if (path_script)
diff --git a/src/plugins/lua/weechat-lua.c b/src/plugins/lua/weechat-lua.c
index f9338120c..3686fa6d1 100644
--- a/src/plugins/lua/weechat-lua.c
+++ b/src/plugins/lua/weechat-lua.c
@@ -975,7 +975,7 @@ weechat_lua_command_cb (const void *pointer, void *data,
{
/* load lua script */
path_script = plugin_script_search_path (weechat_lua_plugin,
- ptr_name);
+ ptr_name, 1);
weechat_lua_load ((path_script) ? path_script : ptr_name,
NULL);
if (path_script)
diff --git a/src/plugins/perl/weechat-perl.c b/src/plugins/perl/weechat-perl.c
index 1796679d9..d6c3475ff 100644
--- a/src/plugins/perl/weechat-perl.c
+++ b/src/plugins/perl/weechat-perl.c
@@ -963,7 +963,7 @@ weechat_perl_command_cb (const void *pointer, void *data,
{
/* load perl script */
path_script = plugin_script_search_path (weechat_perl_plugin,
- ptr_name);
+ ptr_name, 1);
weechat_perl_load ((path_script) ? path_script : ptr_name,
NULL);
if (path_script)
diff --git a/src/plugins/php/weechat-php.c b/src/plugins/php/weechat-php.c
index 5d83482e5..23890a3d5 100644
--- a/src/plugins/php/weechat-php.c
+++ b/src/plugins/php/weechat-php.c
@@ -980,7 +980,7 @@ weechat_php_command_cb (const void *pointer, void *data,
{
/* load PHP script */
path_script = plugin_script_search_path (weechat_php_plugin,
- ptr_name);
+ ptr_name, 1);
weechat_php_load ((path_script) ? path_script : ptr_name,
NULL);
if (path_script)
diff --git a/src/plugins/plugin-script.c b/src/plugins/plugin-script.c
index 0ed7e2ab2..142dd7c10 100644
--- a/src/plugins/plugin-script.c
+++ b/src/plugins/plugin-script.c
@@ -537,7 +537,8 @@ plugin_script_search_by_full_name (struct t_plugin_script *scripts,
char *
plugin_script_search_path (struct t_weechat_plugin *weechat_plugin,
- const char *filename)
+ const char *filename,
+ int search_system_dir)
{
char *final_name, *weechat_data_dir, *dir_system;
int length;
@@ -602,28 +603,31 @@ plugin_script_search_path (struct t_weechat_plugin *weechat_plugin,
free (weechat_data_dir);
}
- /* try WeeChat system dir */
- dir_system = weechat_info_get ("weechat_sharedir", "");
- if (dir_system)
+ if (search_system_dir)
{
- length = strlen (dir_system) + strlen (weechat_plugin->name) +
- strlen (filename) + 16;
- final_name = malloc (length);
- if (final_name)
+ /* try WeeChat system dir */
+ dir_system = weechat_info_get ("weechat_sharedir", "");
+ if (dir_system)
{
- snprintf (final_name,length,
- "%s/%s/%s", dir_system, weechat_plugin->name, filename);
- if ((stat (final_name, &st) == 0) && (st.st_size > 0))
+ length = strlen (dir_system) + strlen (weechat_plugin->name) +
+ strlen (filename) + 16;
+ final_name = malloc (length);
+ if (final_name)
{
- free (dir_system);
- return final_name;
+ snprintf (final_name,length,
+ "%s/%s/%s", dir_system, weechat_plugin->name, filename);
+ if ((stat (final_name, &st) == 0) && (st.st_size > 0))
+ {
+ free (dir_system);
+ return final_name;
+ }
+ free (final_name);
}
- free (final_name);
+ free (dir_system);
}
- free (dir_system);
}
- return strdup (filename);
+ return NULL;
}
/*
@@ -1147,7 +1151,7 @@ plugin_script_remove_file (struct t_weechat_plugin *weechat_plugin,
i = 0;
while (i < 2)
{
- path_script = plugin_script_search_path (weechat_plugin, name);
+ path_script = plugin_script_search_path (weechat_plugin, name, 0);
/*
* script not found? (if path_script == name, that means the function
* above did not find the script)
diff --git a/src/plugins/plugin-script.h b/src/plugins/plugin-script.h
index e4b3081c0..c3db986ac 100644
--- a/src/plugins/plugin-script.h
+++ b/src/plugins/plugin-script.h
@@ -135,7 +135,8 @@ extern void plugin_script_auto_load (struct t_weechat_plugin *weechat_plugin,
extern struct t_plugin_script *plugin_script_search (struct t_plugin_script *scripts,
const char *name);
extern char *plugin_script_search_path (struct t_weechat_plugin *weechat_plugin,
- const char *filename);
+ const char *filename,
+ int search_system_dir);
extern struct t_plugin_script *plugin_script_alloc (const char *filename,
const char *name,
const char *author,
diff --git a/src/plugins/python/weechat-python.c b/src/plugins/python/weechat-python.c
index 8a5883327..edbc26b16 100644
--- a/src/plugins/python/weechat-python.c
+++ b/src/plugins/python/weechat-python.c
@@ -1201,7 +1201,7 @@ weechat_python_command_cb (const void *pointer, void *data,
{
/* load python script */
path_script = plugin_script_search_path (weechat_python_plugin,
- ptr_name);
+ ptr_name, 1);
weechat_python_load ((path_script) ? path_script : ptr_name,
NULL);
if (path_script)
diff --git a/src/plugins/ruby/weechat-ruby.c b/src/plugins/ruby/weechat-ruby.c
index fa940ea92..391d0d236 100644
--- a/src/plugins/ruby/weechat-ruby.c
+++ b/src/plugins/ruby/weechat-ruby.c
@@ -1003,7 +1003,7 @@ weechat_ruby_command_cb (const void *pointer, void *data,
{
/* load ruby script */
path_script = plugin_script_search_path (weechat_ruby_plugin,
- ptr_name);
+ ptr_name, 1);
weechat_ruby_load ((path_script) ? path_script : ptr_name,
NULL);
if (path_script)
diff --git a/src/plugins/tcl/weechat-tcl.c b/src/plugins/tcl/weechat-tcl.c
index 1e53932c5..b202e7c44 100644
--- a/src/plugins/tcl/weechat-tcl.c
+++ b/src/plugins/tcl/weechat-tcl.c
@@ -658,7 +658,7 @@ weechat_tcl_command_cb (const void *pointer, void *data,
{
/* load tcl script */
path_script = plugin_script_search_path (weechat_tcl_plugin,
- ptr_name);
+ ptr_name, 1);
weechat_tcl_load ((path_script) ? path_script : ptr_name,
NULL);
if (path_script)