script: allow command /script list when option script.scripts.download_enabled is set to off (closes #1574)

This commit is contained in:
Sébastien Helleu 2020-10-15 20:38:43 +02:00
parent c3707bb6e1
commit 939b16230c
6 changed files with 52 additions and 27 deletions

View File

@ -636,7 +636,7 @@ script_action_run_install (int quiet)
char *filename, *url;
struct t_hashtable *options;
if (!script_download_enabled ())
if (!script_download_enabled (1))
return;
while (1)
@ -1080,7 +1080,7 @@ script_action_run_show (const char *name, int quiet)
char *filename, *url;
struct t_hashtable *options;
if (!script_download_enabled ())
if (!script_download_enabled (1))
return;
if (name)
@ -1510,12 +1510,17 @@ script_action_run_all ()
/*
* Schedules an action.
*
* If "need_repository" is 1, then the action will be executed only when the
* repository file is up-to-date.
* If "need_repository" is 1:
* - if repository is up-to-date: action is executed
* - if "error_repository" is 0: action is executed otherwise the action is
* ignored
* else action is executed.
*/
void
script_action_schedule (const char *action, int need_repository, int quiet)
script_action_schedule (const char *action,
int need_repository, int error_repository,
int quiet)
{
/* create again "script" directory, just in case it has been removed */
if (!weechat_mkdir_home (SCRIPT_PLUGIN_NAME, 0755))
@ -1533,8 +1538,18 @@ script_action_schedule (const char *action, int need_repository, int quiet)
}
else
{
if (!script_repo_file_update (quiet))
if (!error_repository && !script_download_enabled (0))
{
/*
* the action can be executed even without repository
* (example: /script list)
*/
script_action_run_all ();
}
else if (!script_repo_file_update (quiet))
{
script_action_clear ();
}
}
}
else

View File

@ -24,7 +24,7 @@ extern char **script_actions;
extern int script_action_run_all ();
extern void script_action_schedule (const char *action, int need_repository,
int quiet);
int error_repository, int quiet);
extern void script_action_end ();
#endif /* WEECHAT_PLUGIN_SCRIPT_ACTION_H */

View File

@ -37,8 +37,9 @@
*/
void
script_command_action (struct t_gui_buffer *buffer, const char *action,
const char *arguments, int need_repository)
script_command_action (struct t_gui_buffer *buffer,
const char *action, const char *arguments,
int need_repository, int error_repository)
{
struct t_script_repo *ptr_script;
char str_action[4096];
@ -71,7 +72,8 @@ script_command_action (struct t_gui_buffer *buffer, const char *action,
(quiet) ? "-q " : "",
action,
ptr_script->name_with_extension);
script_action_schedule (str_action, need_repository, quiet);
script_action_schedule (str_action, need_repository,
error_repository, quiet);
}
}
else
@ -81,7 +83,8 @@ script_command_action (struct t_gui_buffer *buffer, const char *action,
(quiet) ? "-q " : "",
action,
arguments);
script_action_schedule (str_action, need_repository, quiet);
script_action_schedule (str_action, need_repository,
error_repository, quiet);
}
}
else if (script_buffer && (buffer == script_buffer))
@ -95,7 +98,8 @@ script_command_action (struct t_gui_buffer *buffer, const char *action,
snprintf (str_action, sizeof (str_action),
"-q %s",
action);
script_action_schedule (str_action, need_repository, 1);
script_action_schedule (str_action, need_repository,
error_repository, 1);
}
else
{
@ -109,7 +113,8 @@ script_command_action (struct t_gui_buffer *buffer, const char *action,
"-q %s %s",
action,
ptr_script->name_with_extension);
script_action_schedule (str_action, need_repository, 1);
script_action_schedule (str_action, need_repository,
error_repository, 1);
}
}
}
@ -135,7 +140,7 @@ script_command_script (const void *pointer, void *data,
if (argc == 1)
{
script_action_schedule ("buffer", 1, 0);
script_action_schedule ("buffer", 1, 1, 0);
return WEECHAT_RC_OK;
}
@ -159,13 +164,13 @@ script_command_script (const void *pointer, void *data,
script_repo_filter_scripts ((argc > 2) ? argv_eol[2] : NULL);
else
script_repo_set_filter ((argc > 2) ? argv_eol[2] : NULL);
script_action_schedule ("buffer", 1, 0);
script_action_schedule ("buffer", 1, 1, 0);
return WEECHAT_RC_OK;
}
if (weechat_strcasecmp (argv[1], "list") == 0)
{
script_action_schedule (argv_eol[1], 1, 0);
script_action_schedule (argv_eol[1], 1, 0, 0);
return WEECHAT_RC_OK;
}
@ -179,6 +184,7 @@ script_command_script (const void *pointer, void *data,
script_command_action (buffer,
argv[1],
(argc > 2) ? argv_eol[2] : NULL,
0,
0);
return WEECHAT_RC_OK;
}
@ -193,13 +199,14 @@ script_command_script (const void *pointer, void *data,
script_command_action (buffer,
argv[1],
(argc > 2) ? argv_eol[2] : NULL,
1,
1);
return WEECHAT_RC_OK;
}
if (weechat_strcasecmp (argv[1], "upgrade") == 0)
{
script_action_schedule ("upgrade", 1, 0);
script_action_schedule ("upgrade", 1, 1, 0);
return WEECHAT_RC_OK;
}

View File

@ -1502,7 +1502,7 @@ script_repo_file_update (int quiet)
char *filename, *url;
struct t_hashtable *options;
if (!script_download_enabled ())
if (!script_download_enabled (1))
return 0;
script_repo_remove_all ();

View File

@ -102,22 +102,25 @@ script_language_search_by_extension (const char *extension)
* Checks if download of scripts is enabled.
*
* Returns:
* 0: download NOT enabled (an error is displayed)
* 0: download NOT enabled (an error is displayed if display_error is 1)
* 1: download enabled
*/
int
script_download_enabled ()
script_download_enabled (int display_error)
{
if (weechat_config_boolean (script_config_scripts_download_enabled))
return 1;
/* download not enabled: display an error */
weechat_printf (NULL,
_("%s%s: download of scripts is disabled by default; "
"see /help script.scripts.download_enabled"),
weechat_prefix ("error"),
SCRIPT_PLUGIN_NAME);
if (display_error)
{
/* download not enabled: display an error */
weechat_printf (NULL,
_("%s%s: download of scripts is disabled by default; "
"see /help script.scripts.download_enabled"),
weechat_prefix ("error"),
SCRIPT_PLUGIN_NAME);
}
return 0;
}

View File

@ -34,7 +34,7 @@ extern struct t_hashtable *script_loaded;
extern int script_language_search (const char *language);
extern int script_language_search_by_extension (const char *extension);
extern int script_download_enabled ();
extern int script_download_enabled (int display_error);
extern char *script_build_download_url (const char *url);
extern void script_get_loaded_plugins ();
extern void script_get_scripts ();