1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-12 14:14:48 +02:00

core: add support for $XDG_STATE_HOME

This commit is contained in:
90
2024-04-08 18:46:27 +01:00
committed by Sébastien Helleu
parent 3bfe4e52ca
commit 8c3f16dbe3
17 changed files with 166 additions and 35 deletions
+5 -1
View File
@@ -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
+5 -1
View File
@@ -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
+5 -1
View File
@@ -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
+5 -1
View File
@@ -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_: ディレクトリのモード
+6 -1
View File
@@ -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_: режим за директоријум
+2 -1
View File
@@ -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"),
+1
View File
@@ -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}",
+2 -1
View File
@@ -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);
+66 -19
View File
@@ -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);
}
+6
View File
@@ -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);
+4 -4
View File
@@ -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,
+2
View File
@@ -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)
+5 -2
View File
@@ -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)
+1
View File
@@ -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;
+23 -1
View File
@@ -239,6 +239,24 @@ plugin_api_info_weechat_data_dir_cb (const void *pointer, void *data,
return plugin_api_info_absolute_path (weechat_data_dir);
}
/*
* 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);
+19 -1
View File
@@ -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);
+9 -1
View File
@@ -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] == '/');