diff options
-rw-r--r-- | doc/en/weechat_plugin_api.en.adoc | 6 | ||||
-rw-r--r-- | doc/fr/weechat_plugin_api.fr.adoc | 6 | ||||
-rw-r--r-- | doc/it/weechat_plugin_api.it.adoc | 6 | ||||
-rw-r--r-- | doc/ja/weechat_plugin_api.ja.adoc | 6 | ||||
-rw-r--r-- | doc/sr/weechat_plugin_api.sr.adoc | 7 | ||||
-rw-r--r-- | src/core/core-command.c | 3 | ||||
-rw-r--r-- | src/core/core-completion.c | 1 | ||||
-rw-r--r-- | src/core/core-debug.c | 3 | ||||
-rw-r--r-- | src/core/core-dir.c | 85 | ||||
-rw-r--r-- | src/core/core-eval.c | 6 | ||||
-rw-r--r-- | src/core/core-log.c | 8 | ||||
-rw-r--r-- | src/core/core-string.c | 2 | ||||
-rw-r--r-- | src/core/weechat.c | 7 | ||||
-rw-r--r-- | src/core/weechat.h | 1 | ||||
-rw-r--r-- | src/plugins/plugin-api-info.c | 24 | ||||
-rw-r--r-- | tests/unit/core/test-core-string.cpp | 20 | ||||
-rw-r--r-- | tests/unit/plugins/test-plugin-api-info.cpp | 10 |
17 files changed, 166 insertions, 35 deletions
diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc index 78405efdb..fa51ff16e 100644 --- a/doc/en/weechat_plugin_api.en.adoc +++ b/doc/en/weechat_plugin_api.en.adoc @@ -2977,13 +2977,16 @@ expanded to last): | `+${weechat_xxx_dir}+` | 3.2 | A WeeChat directory: `+${weechat_config_dir}+`, `+${weechat_data_dir}+`, - `+${weechat_cache_dir}+` or `+${weechat_runtime_dir}+`. + `+${weechat_state_dir}+`, `+${weechat_cache_dir}+` or `+${weechat_runtime_dir}+`. | >> `+${weechat_config_dir}+` + == `+/home/user/.config/weechat+` + + >> `+${weechat_data_dir}+` + == `+/home/user/.local/share/weechat+` + + + >> `+${weechat_state_dir}+` + + == `+/home/user/.local/state/weechat+` + + + >> `+${weechat_cache_dir}+` + == `+/home/user/.cache/weechat+` + + @@ -4343,6 +4346,7 @@ Arguments: strings to force a specific WeeChat directory (WeeChat ≥ 3.2): ** `${weechat_config_dir}` ** `${weechat_data_dir}` (default) +** `${weechat_state_dir}` ** `${weechat_cache_dir}` ** `${weechat_runtime_dir}` * _mode_: mode for directory diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc index ec62d7d9e..ba5751aad 100644 --- a/doc/fr/weechat_plugin_api.fr.adoc +++ b/doc/fr/weechat_plugin_api.fr.adoc @@ -3031,13 +3031,16 @@ première étendue à la dernière) : | `+${weechat_xxx_dir}+` | 3.2 | Un répertoire WeeChat : `+${weechat_config_dir}+`, `+${weechat_data_dir}+`, - `+${weechat_cache_dir}+` ou `+${weechat_runtime_dir}+`. + `+${weechat_state_dir}+`, `+${weechat_cache_dir}+` ou `+${weechat_runtime_dir}+`. | >> `+${weechat_config_dir}+` + == `+/home/user/.config/weechat+` + + >> `+${weechat_data_dir}+` + == `+/home/user/.local/share/weechat+` + + + >> `+${weechat_state_dir}+` + + == `+/home/user/.local/state/weechat+` + + + >> `+${weechat_cache_dir}+` + == `+/home/user/.cache/weechat+` + + @@ -4420,6 +4423,7 @@ Paramètres : chaînes pour forcer un répertoire spécifique de WeeChat (WeeChat ≥ 3.2) : ** `${weechat_config_dir}` ** `${weechat_data_dir}` (par défaut) +** `${weechat_state_dir}` ** `${weechat_cache_dir}` ** `${weechat_runtime_dir}` * _mode_ : mode pour le répertoire diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc index f3d001cac..a30583725 100644 --- a/doc/it/weechat_plugin_api.it.adoc +++ b/doc/it/weechat_plugin_api.it.adoc @@ -3133,13 +3133,16 @@ expanded to last): | `+${weechat_xxx_dir}+` | 3.2 | A WeeChat directory: `+${weechat_config_dir}+`, `+${weechat_data_dir}+`, - `+${weechat_cache_dir}+` or `+${weechat_runtime_dir}+`. + `+${weechat_state_dir}+`, `+${weechat_cache_dir}+` or `+${weechat_runtime_dir}+`. | >> `+${weechat_config_dir}+` + == `+/home/user/.config/weechat+` + + >> `+${weechat_data_dir}+` + == `+/home/user/.local/share/weechat+` + + + >> `+${weechat_state_dir}+` + + == `+/home/user/.local/state/weechat+` + + + >> `+${weechat_cache_dir}+` + == `+/home/user/.cache/weechat+` + + @@ -4550,6 +4553,7 @@ Argomenti: strings to force a specific WeeChat directory (WeeChat ≥ 3.2): ** `${weechat_config_dir}` ** `${weechat_data_dir}` (default) +** `${weechat_state_dir}` ** `${weechat_cache_dir}` ** `${weechat_runtime_dir}` * _mode_: modalità per la cartella diff --git a/doc/ja/weechat_plugin_api.ja.adoc b/doc/ja/weechat_plugin_api.ja.adoc index 6b8ea1577..51c99f79c 100644 --- a/doc/ja/weechat_plugin_api.ja.adoc +++ b/doc/ja/weechat_plugin_api.ja.adoc @@ -3072,13 +3072,16 @@ str5 = weechat.string_eval_expression("password=abc password=def", {}, {}, optio // TRANSLATION MISSING | `+${weechat_xxx_dir}+` | 3.2 | A WeeChat directory: `+${weechat_config_dir}+`, `+${weechat_data_dir}+`, - `+${weechat_cache_dir}+` or `+${weechat_runtime_dir}+`. + `+${weechat_state_dir}+`, `+${weechat_cache_dir}+` or `+${weechat_runtime_dir}+`. | >> `+${weechat_config_dir}+` + == `+/home/user/.config/weechat+` + + >> `+${weechat_data_dir}+` + == `+/home/user/.local/share/weechat+` + + + >> `+${weechat_state_dir}+` + + == `+/home/user/.local/state/weechat+` + + + >> `+${weechat_cache_dir}+` + == `+/home/user/.cache/weechat+` + + @@ -4476,6 +4479,7 @@ int weechat_mkdir_home (char *directory, int mode); strings to force a specific WeeChat directory (WeeChat ≥ 3.2): ** `${weechat_config_dir}` ** `${weechat_data_dir}` (default) +** `${weechat_state_dir}` ** `${weechat_cache_dir}` ** `${weechat_runtime_dir}` * _mode_: ディレクトリのモード diff --git a/doc/sr/weechat_plugin_api.sr.adoc b/doc/sr/weechat_plugin_api.sr.adoc index 19955a3e2..0c5840c40 100644 --- a/doc/sr/weechat_plugin_api.sr.adoc +++ b/doc/sr/weechat_plugin_api.sr.adoc @@ -2872,13 +2872,17 @@ str5 = weechat.string_eval_expression("password=abc password=def", {}, {}, optio | `+${weechat_xxx_dir}+` | 3.2 | WeeChat директоријум: `+${weechat_config_dir}+`, `+${weechat_data_dir}+`, - `+${weechat_cache_dir}+` или `+${weechat_runtime_dir}+`. + `+${weechat_state_dir}+`, `+${weechat_cache_dir}+` + или `+${weechat_runtime_dir}+`. | >> `+${weechat_config_dir}+` + == `+/home/user/.config/weechat+` + + >> `+${weechat_data_dir}+` + == `+/home/user/.local/share/weechat+` + + + >> `+${weechat_state_dir}+` + + == `+/home/user/.local/state/weechat+` + + + >> `+${weechat_cache_dir}+` + == `+/home/user/.cache/weechat+` + + @@ -4211,6 +4215,7 @@ int weechat_mkdir_home (char *directory, int mode); * _directory_: име директоријума који трба да се креира; може почети једним од следећих стрингова чиме се форсира одређени WeeChat директоријум (WeeChat ≥ 3.2): ** `${weechat_config_dir}` ** `${weechat_data_dir}` (подразумевано) +** `${weechat_state_dir}` ** `${weechat_cache_dir}` ** `${weechat_runtime_dir}` * _mode_: режим за директоријум diff --git a/src/core/core-command.c b/src/core/core-command.c index bfd38b1a9..e205465d3 100644 --- a/src/core/core-command.c +++ b/src/core/core-command.c @@ -8383,8 +8383,9 @@ command_init () N_(" - ${name}: the user-defined variable"), N_(" - ${weechat_config_dir}: WeeChat config directory"), N_(" - ${weechat_data_dir}: WeeChat data directory"), + N_(" - ${weechat_state_dir}: WeeChat state directory"), N_(" - ${weechat_cache_dir}: WeeChat cache directory"), - N_(" - ${weechat_runtmie_dir}: WeeChat runtime directory"), + N_(" - ${weechat_runtime_dir}: WeeChat runtime directory"), N_(" - ${eval:string}: the evaluated string"), N_(" - ${eval_cond:string}: the evaluated condition"), N_(" - ${esc:string} or ${\\string}: the string with escaped chars"), diff --git a/src/core/core-completion.c b/src/core/core-completion.c index 598859b67..77dbbeb39 100644 --- a/src/core/core-completion.c +++ b/src/core/core-completion.c @@ -2172,6 +2172,7 @@ completion_list_add_eval_variables_cb (const void *pointer, void *data, "${weechat_config_dir}", "${weechat_data_dir}", "${weechat_runtime_dir}", + "${weechat_state_dir}", "${window}", "${window.buffer}", "${window.buffer.xxx}", diff --git a/src/core/core-debug.c b/src/core/core-debug.c index d5153ca26..7da06e42d 100644 --- a/src/core/core-debug.c +++ b/src/core/core-debug.c @@ -172,7 +172,7 @@ debug_sigsegv_cb () string_fprintf (stderr, "*** Full crash dump was saved to %s/weechat.log file." "\n", - weechat_data_dir); + weechat_state_dir); } string_fprintf ( stderr, @@ -765,6 +765,7 @@ debug_directories () gui_chat_printf (NULL, " home:"); gui_chat_printf (NULL, " config: %s%s", weechat_config_dir, str_temp); gui_chat_printf (NULL, " data: %s%s", weechat_data_dir, str_temp); + gui_chat_printf (NULL, " state: %s%s", weechat_state_dir, str_temp); gui_chat_printf (NULL, " cache: %s%s", weechat_cache_dir, str_temp); gui_chat_printf (NULL, " runtime: %s%s", weechat_runtime_dir, str_temp); gui_chat_printf (NULL, " lib: %s", WEECHAT_LIBDIR); diff --git a/src/core/core-dir.c b/src/core/core-dir.c index 86560d433..1c3205446 100644 --- a/src/core/core-dir.c +++ b/src/core/core-dir.c @@ -108,7 +108,7 @@ dir_get_temp_dir () int dir_mkdir_home (const char *directory, int mode) { - char *dir, *dir1, *dir2, *dir3, *dir4; + char *dir, *dir1, *dir2, *dir3, *dir4, *dir5; int rc, dir_length; rc = 0; @@ -117,6 +117,7 @@ dir_mkdir_home (const char *directory, int mode) dir2 = NULL; dir3 = NULL; dir4 = NULL; + dir5 = NULL; if (!directory) goto end; @@ -143,16 +144,20 @@ dir_mkdir_home (const char *directory, int mode) if (!dir2) goto end; - dir3 = string_replace (dir2, "${weechat_cache_dir}", weechat_cache_dir); + dir3 = string_replace (dir2, "${weechat_state_dir}", weechat_state_dir); if (!dir3) goto end; - dir4 = string_replace (dir3, "${weechat_runtime_dir}", weechat_runtime_dir); + dir4 = string_replace (dir3, "${weechat_cache_dir}", weechat_cache_dir); if (!dir4) goto end; + dir5 = string_replace (dir4, "${weechat_runtime_dir}", weechat_runtime_dir); + if (!dir5) + goto end; + /* build directory, adding WeeChat home */ - if (mkdir (dir4, mode) < 0) + if (mkdir (dir5, mode) < 0) { if (errno != EEXIST) goto end; @@ -171,6 +176,8 @@ end: free (dir3); if (dir4) free (dir4); + if (dir5) + free (dir5); return rc; } @@ -331,21 +338,23 @@ dir_set_home_path (char *path) { weechat_config_dir = string_expand_home (paths[0]); weechat_data_dir = string_expand_home (paths[0]); + weechat_state_dir = string_expand_home (paths[0]); weechat_cache_dir = string_expand_home (paths[0]); weechat_runtime_dir = string_expand_home (paths[0]); } - else if (num_paths == 4) + else if (num_paths == 5) { weechat_config_dir = string_expand_home (paths[0]); weechat_data_dir = string_expand_home (paths[1]); - weechat_cache_dir = string_expand_home (paths[2]); - weechat_runtime_dir = string_expand_home (paths[3]); + weechat_state_dir = string_expand_home (paths[2]); + weechat_cache_dir = string_expand_home (paths[3]); + weechat_runtime_dir = string_expand_home (paths[4]); } else { string_fprintf (stderr, _("Error: wrong number of paths for home directories " - "(expected: 1 or 4, received: %d)\n"), + "(expected: 1 or 5, received: %d)\n"), num_paths); goto end; } @@ -402,6 +411,7 @@ dir_create_home_temp_dir () weechat_config_dir = strdup (ptr_weechat_home); weechat_data_dir = strdup (ptr_weechat_home); + weechat_state_dir = strdup (ptr_weechat_home); weechat_cache_dir = strdup (ptr_weechat_home); weechat_runtime_dir = strdup (ptr_weechat_home); @@ -430,14 +440,16 @@ end: */ int -dir_find_xdg_dirs (char **config_dir, char **data_dir, char **cache_dir, - char **runtime_dir) +dir_find_xdg_dirs (char **config_dir, char **data_dir, char **state_dir, + char **cache_dir, char **runtime_dir) { char *ptr_home, path[PATH_MAX]; - char *xdg_config_home, *xdg_data_home, *xdg_cache_home, *xdg_runtime_dir; + char *xdg_config_home, *xdg_data_home, *xdg_state_home, *xdg_cache_home; + char *xdg_runtime_dir; *config_dir = NULL; *data_dir = NULL; + *state_dir = NULL; *cache_dir = NULL; *runtime_dir = NULL; @@ -447,6 +459,7 @@ dir_find_xdg_dirs (char **config_dir, char **data_dir, char **cache_dir, xdg_config_home = getenv ("XDG_CONFIG_HOME"); xdg_data_home = getenv ("XDG_DATA_HOME"); + xdg_state_home = getenv ("XDG_STATE_HOME"); xdg_cache_home = getenv ("XDG_CACHE_HOME"); xdg_runtime_dir = getenv ("XDG_RUNTIME_DIR"); @@ -485,6 +498,24 @@ dir_find_xdg_dirs (char **config_dir, char **data_dir, char **cache_dir, if (!*data_dir) goto error_memory; + /* set state dir: $XDG_STATE_HOME/weechat or $HOME/.local/state/weechat */ + if (xdg_state_home && xdg_state_home[0]) + { + snprintf (path, sizeof (path), + "%s%s%s", + xdg_state_home, DIR_SEPARATOR, "weechat"); + } + else + { + snprintf (path, sizeof (path), + "%s%s%s%s%s%s%s", + ptr_home, DIR_SEPARATOR, ".local", DIR_SEPARATOR, "state", + DIR_SEPARATOR, "weechat"); + } + *state_dir = strdup (path); + if (!*state_dir) + goto error_memory; + /* set cache dir: $XDG_CACHE_HOME/weechat or $HOME/.cache/weechat */ if (xdg_cache_home && xdg_cache_home[0]) { @@ -539,6 +570,11 @@ error: free (*data_dir); *data_dir = NULL; } + if (*state_dir) + { + free (*state_dir); + *state_dir = NULL; + } if (*cache_dir) { free (*cache_dir); @@ -565,7 +601,7 @@ int dir_find_home_dirs () { char *ptr_home, *ptr_weechat_home, *config_weechat_home; - char *config_dir, *data_dir, *cache_dir, *runtime_dir; + char *config_dir, *data_dir, *state_dir, *cache_dir, *runtime_dir; char path[PATH_MAX]; /* temporary WeeChat home */ @@ -586,7 +622,8 @@ dir_find_home_dirs () if (config_weechat_home[0]) return dir_set_home_path (config_weechat_home); - if (!dir_find_xdg_dirs (&config_dir, &data_dir, &cache_dir, &runtime_dir)) + if (!dir_find_xdg_dirs (&config_dir, &data_dir, &state_dir, &cache_dir, + &runtime_dir)) return 0; /* check if {weechat_config_dir}/weechat.conf exists */ @@ -611,10 +648,12 @@ dir_find_home_dirs () ptr_home, DIR_SEPARATOR, ".weechat"); weechat_config_dir = strdup (path); weechat_data_dir = strdup (path); + weechat_state_dir = strdup (path); weechat_cache_dir = strdup (path); weechat_runtime_dir = strdup (path); free (config_dir); free (data_dir); + free (state_dir); free (cache_dir); free (runtime_dir); return 1; @@ -624,6 +663,7 @@ dir_find_home_dirs () use_xdg: weechat_config_dir = config_dir; weechat_data_dir = data_dir; + weechat_state_dir = state_dir; weechat_cache_dir = cache_dir; weechat_runtime_dir = runtime_dir; return 1; @@ -706,12 +746,15 @@ dir_create_home_dirs () dir_remove_trailing_separators (weechat_config_dir); dir_remove_trailing_separators (weechat_data_dir); + dir_remove_trailing_separators (weechat_state_dir); dir_remove_trailing_separators (weechat_cache_dir); dir_remove_trailing_separators (weechat_runtime_dir); rc = dir_create_home_dir (weechat_config_dir); if (rc && (strcmp (weechat_config_dir, weechat_data_dir) != 0)) rc = dir_create_home_dir (weechat_data_dir); + if (rc && (strcmp (weechat_config_dir, weechat_state_dir) != 0)) + rc = dir_create_home_dir (weechat_state_dir); if (rc && (strcmp (weechat_config_dir, weechat_cache_dir) != 0)) rc = dir_create_home_dir (weechat_cache_dir); if (rc && (strcmp (weechat_config_dir, weechat_runtime_dir) != 0)) @@ -733,6 +776,8 @@ dir_remove_home_dirs () dir_rmtree (weechat_config_dir); if (strcmp (weechat_config_dir, weechat_data_dir) != 0) dir_rmtree (weechat_data_dir); + if (strcmp (weechat_config_dir, weechat_state_dir) != 0) + dir_rmtree (weechat_state_dir); if (strcmp (weechat_config_dir, weechat_cache_dir) != 0) dir_rmtree (weechat_cache_dir); if (strcmp (weechat_config_dir, weechat_runtime_dir) != 0) @@ -741,11 +786,12 @@ dir_remove_home_dirs () /* * Returns a string with home directories separated by colons, in this order: - * config_dir, data_dir, cache_dir, runtime_dir. + * config_dir, data_dir, state_dir, cache_dir, runtime_dir. * * Example of value returned: * /home/user/.config/weechat:/home/user/.local/share/weechat: - * /home/user/.cache/weechat:/run/user/1000/weechat + * /home/user/.local/state/weechat:/home/user/.cache/weechat: + * /run/user/1000/weechat * * Note: result must be freed after use. */ @@ -753,13 +799,14 @@ dir_remove_home_dirs () char * dir_get_string_home_dirs () { - char *dirs[5]; + char *dirs[6]; dirs[0] = weechat_config_dir; dirs[1] = weechat_data_dir; - dirs[2] = weechat_cache_dir; - dirs[3] = weechat_runtime_dir; - dirs[4] = NULL; + dirs[2] = weechat_state_dir; + dirs[3] = weechat_cache_dir; + dirs[4] = weechat_runtime_dir; + dirs[5] = NULL; return string_rebuild_split_string ((const char **)dirs, ":", 0, -1); } diff --git a/src/core/core-eval.c b/src/core/core-eval.c index 661a4d6e0..ad66caf3a 100644 --- a/src/core/core-eval.c +++ b/src/core/core-eval.c @@ -1564,6 +1564,7 @@ eval_syntax_highlight (const char *text, struct t_eval_context *eval_context) * - ${name}: the variable from hashtable "user_vars" or "extra_vars" * - ${weechat_config_dir}: WeeChat config directory * - ${weechat_data_dir}: WeeChat data directory + * - ${weechat_state_dir}: WeeChat state directory * - ${weechat_cache_dir}: WeeChat cache directory * - ${weechat_runtmie_dir}: WeeChat runtime directory * - ${eval:string}: the evaluated string @@ -1702,6 +1703,11 @@ eval_replace_vars_cb (void *data, value = strdup (weechat_data_dir); goto end; } + if (strcmp (text, "weechat_state_dir") == 0) + { + value = strdup (weechat_state_dir); + goto end; + } if (strcmp (text, "weechat_cache_dir") == 0) { value = strdup (weechat_cache_dir); diff --git a/src/core/core-log.c b/src/core/core-log.c index d62a705e3..2ad0b3213 100644 --- a/src/core/core-log.c +++ b/src/core/core-log.c @@ -79,10 +79,10 @@ log_open (const char *filename, const char *mode) } else { - filename_length = strlen (weechat_data_dir) + 64; + filename_length = strlen (weechat_state_dir) + 64; weechat_log_filename = malloc (filename_length); snprintf (weechat_log_filename, filename_length, - "%s/%s", weechat_data_dir, WEECHAT_LOG_NAME); + "%s/%s", weechat_state_dir, WEECHAT_LOG_NAME); weechat_log_file = fopen (weechat_log_filename, mode); } @@ -273,7 +273,7 @@ log_crash_rename () log_close (); - length = strlen (weechat_data_dir) + 128; + length = strlen (weechat_state_dir) + 128; new_name = malloc (length); if (new_name) { @@ -281,7 +281,7 @@ log_crash_rename () local_time = localtime (&time_now); snprintf (new_name, length, "%s/weechat_crash_%04d%02d%02d_%d.log", - weechat_data_dir, + weechat_state_dir, local_time->tm_year + 1900, local_time->tm_mon + 1, local_time->tm_mday, diff --git a/src/core/core-string.c b/src/core/core-string.c index 4b8f3c957..20202616e 100644 --- a/src/core/core-string.c +++ b/src/core/core-string.c @@ -1153,6 +1153,8 @@ string_eval_path_home (const char *path, ptr_directory = weechat_config_dir; else if (strcmp (ptr_option_directory, "data") == 0) ptr_directory = weechat_data_dir; + else if (strcmp (ptr_option_directory, "state") == 0) + ptr_directory = weechat_state_dir; else if (strcmp (ptr_option_directory, "cache") == 0) ptr_directory = weechat_cache_dir; else if (strcmp (ptr_option_directory, "runtime") == 0) diff --git a/src/core/weechat.c b/src/core/weechat.c index 78ed20f5a..d0796d401 100644 --- a/src/core/weechat.c +++ b/src/core/weechat.c @@ -115,6 +115,7 @@ int weechat_home_temp = 0; /* 1 if using a temporary home */ int weechat_home_delete_on_exit = 0; /* 1 if home is deleted on exit */ char *weechat_config_dir = NULL; /* config directory */ char *weechat_data_dir = NULL; /* data directory */ +char *weechat_state_dir = NULL; /* state directory */ char *weechat_cache_dir = NULL; /* cache directory */ char *weechat_runtime_dir = NULL; /* runtime directory */ int weechat_locale_ok = 0; /* is locale OK? */ @@ -178,8 +179,8 @@ weechat_display_usage () " -c, --colors display default colors in terminal " "and exit\n" " -d, --dir <path> force a single WeeChat home directory\n" - " or 4 different directories separated " - "by colons (in this order: config, data, cache, runtime)\n" + " or 5 different directories separated " + "by colons (in this order: config, data, state, cache, runtime)\n" " (environment variable WEECHAT_HOME is " "read if this option is not given)\n" " -t, --temp-dir create a temporary WeeChat home " @@ -583,6 +584,8 @@ weechat_shutdown (int return_code, int crash) free (weechat_config_dir); if (weechat_data_dir) free (weechat_data_dir); + if (weechat_state_dir) + free (weechat_state_dir); if (weechat_cache_dir) free (weechat_cache_dir); if (weechat_runtime_dir) diff --git a/src/core/weechat.h b/src/core/weechat.h index 283732c3b..a7f597ee3 100644 --- a/src/core/weechat.h +++ b/src/core/weechat.h @@ -115,6 +115,7 @@ extern int weechat_home_temp; extern int weechat_home_delete_on_exit; extern char *weechat_config_dir; extern char *weechat_data_dir; +extern char *weechat_state_dir; extern char *weechat_cache_dir; extern char *weechat_runtime_dir; extern char *weechat_local_charset; diff --git a/src/plugins/plugin-api-info.c b/src/plugins/plugin-api-info.c index 9c6a81dbd..f059b2782 100644 --- a/src/plugins/plugin-api-info.c +++ b/src/plugins/plugin-api-info.c @@ -240,6 +240,24 @@ plugin_api_info_weechat_data_dir_cb (const void *pointer, void *data, } /* + * Returns WeeChat info "weechat_state_dir". + */ + +char * +plugin_api_info_weechat_state_dir_cb (const void *pointer, void *data, + const char *info_name, + const char *arguments) +{ + /* make C compiler happy */ + (void) pointer; + (void) data; + (void) info_name; + (void) arguments; + + return plugin_api_info_absolute_path (weechat_state_dir); +} + +/* * Returns WeeChat info "weechat_cache_dir". */ @@ -2109,7 +2127,8 @@ plugin_api_info_init () N_("WeeChat directory " "(*deprecated* since version 3.2, replaced by " "\"weechat_config_dir\", \"weechat_data_dir\", " - "\"weechat_cache_dir\" and \"weechat_runtime_dir\")"), + "\"weechat_state_dir\" , \"weechat_cache_dir\" " + "and \"weechat_runtime_dir\")"), NULL, &plugin_api_info_weechat_data_dir_cb, NULL, NULL); hook_info (NULL, "weechat_config_dir", N_("WeeChat config directory"), @@ -2117,6 +2136,9 @@ plugin_api_info_init () hook_info (NULL, "weechat_data_dir", N_("WeeChat data directory"), NULL, &plugin_api_info_weechat_data_dir_cb, NULL, NULL); + hook_info (NULL, "weechat_state_dir", + N_("WeeChat state directory"), + NULL, &plugin_api_info_weechat_state_dir_cb, NULL, NULL); hook_info (NULL, "weechat_cache_dir", N_("WeeChat cache directory"), NULL, &plugin_api_info_weechat_cache_dir_cb, NULL, NULL); diff --git a/tests/unit/core/test-core-string.cpp b/tests/unit/core/test-core-string.cpp index 2d6552a31..580fc64ce 100644 --- a/tests/unit/core/test-core-string.cpp +++ b/tests/unit/core/test-core-string.cpp @@ -962,7 +962,8 @@ TEST(CoreString, EvalPathHome) { char *home, *result; int length_home, length_weechat_config_dir, length_weechat_data_dir; - int length_weechat_cache_dir, length_weechat_runtime_dir; + int length_weechat_state_dir, length_weechat_cache_dir; + int length_weechat_runtime_dir; struct t_hashtable *extra_vars, *options; home = getenv ("HOME"); @@ -971,6 +972,7 @@ TEST(CoreString, EvalPathHome) length_weechat_config_dir = strlen (weechat_config_dir); length_weechat_data_dir = strlen (weechat_data_dir); + length_weechat_state_dir = strlen (weechat_state_dir); length_weechat_cache_dir = strlen (weechat_cache_dir); length_weechat_runtime_dir = strlen (weechat_runtime_dir); @@ -1014,6 +1016,14 @@ TEST(CoreString, EvalPathHome) STRCMP_EQUAL(result + length_weechat_data_dir, "/test"); free (result); + /* "%h" with forced state dir */ + hashtable_set (options, "directory", "state"); + result = string_eval_path_home ("%h/test", NULL, NULL, options); + CHECK(strncmp (result, weechat_state_dir, length_weechat_state_dir) == 0); + LONGS_EQUAL(length_weechat_state_dir + 5, strlen (result)); + STRCMP_EQUAL(result + length_weechat_state_dir, "/test"); + free (result); + /* "%h" with forced cache dir */ hashtable_set (options, "directory", "cache"); result = string_eval_path_home ("%h/test", NULL, NULL, options); @@ -1048,6 +1058,14 @@ TEST(CoreString, EvalPathHome) STRCMP_EQUAL(result + length_weechat_data_dir, "/path"); free (result); + /* state dir */ + result = string_eval_path_home ("${weechat_state_dir}/path", + NULL, NULL, NULL); + CHECK(strncmp (result, weechat_state_dir, length_weechat_state_dir) == 0); + LONGS_EQUAL(length_weechat_state_dir + 5, strlen (result)); + STRCMP_EQUAL(result + length_weechat_state_dir, "/path"); + free (result); + /* cache dir */ result = string_eval_path_home ("${weechat_cache_dir}/path", NULL, NULL, NULL); diff --git a/tests/unit/plugins/test-plugin-api-info.cpp b/tests/unit/plugins/test-plugin-api-info.cpp index 07a31f9b0..a58c14f4d 100644 --- a/tests/unit/plugins/test-plugin-api-info.cpp +++ b/tests/unit/plugins/test-plugin-api-info.cpp @@ -164,8 +164,9 @@ TEST(PluginApiInfo, AbsolutePath) * plugin_api_info_absolute_path * plugin_api_info_weechat_config_dir_cb * plugin_api_info_weechat_data_dir_cb + * plugin_api_info_weechat_state_dir_cb * plugin_api_info_weechat_cache_dir_cb - * plugin_api_info_weechat_cache_dir_cb + * plugin_api_info_weechat_runtime_dir_cb */ TEST(PluginApiInfo, WeechatDir) @@ -186,6 +187,13 @@ TEST(PluginApiInfo, WeechatDir) CHECK(strstr (str, "/tmp_weechat_test")); free (str); + str = hook_info_get (NULL, "weechat_state_dir", NULL); + CHECK(str); + CHECK(str[0] == '/'); + CHECK(strlen (str) > 1); + CHECK(strstr (str, "/tmp_weechat_test")); + free (str); + str = hook_info_get (NULL, "weechat_cache_dir", NULL); CHECK(str); CHECK(str[0] == '/'); |