1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-26 21:06:38 +02:00

core: split WeeChat home in 4 directories, use XDG directories by default (issue #1285)

The 4 directories (which can be the same):

- config: configuration files, certificates
- data: log/upgrade files, local plugins, scripts, xfer files
- cache: script repository, scripts downloaded (temporary location)
- runtime: FIFO pipe, relay UNIX sockets
This commit is contained in:
Sébastien Helleu
2021-05-02 11:56:25 +02:00
parent 4c5fcb743b
commit 0f9640a5f3
38 changed files with 1129 additions and 363 deletions
+1 -1
View File
@@ -1523,7 +1523,7 @@ script_action_schedule (const char *action,
int quiet)
{
/* create again "script" directory, just in case it has been removed */
if (!weechat_mkdir_home (SCRIPT_PLUGIN_NAME, 0755))
if (!weechat_mkdir_home ("${weechat_cache_dir}/" SCRIPT_PLUGIN_NAME, 0755))
return;
script_action_add (action);
+9 -9
View File
@@ -189,7 +189,7 @@ script_completion_scripts_files_cb (const void *pointer, void *data,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
char *weechat_home, *directory;
char *weechat_data_dir, *directory;
int length, i;
void *pointers[2];
@@ -199,9 +199,9 @@ script_completion_scripts_files_cb (const void *pointer, void *data,
(void) completion_item;
(void) buffer;
weechat_home = weechat_info_get ("weechat_dir", NULL);
weechat_data_dir = weechat_info_get ("weechat_data_dir", NULL);
length = strlen (weechat_home) + 128 + 1;
length = strlen (weechat_data_dir) + 128 + 1;
directory = malloc (length);
if (directory)
{
@@ -210,16 +210,16 @@ script_completion_scripts_files_cb (const void *pointer, void *data,
pointers[0] = completion;
pointers[1] = script_extension[i];
/* look for files in "~/.weechat/<language>/" */
/* look for files in <weechat_data_dir>/<language> */
snprintf (directory, length,
"%s/%s", weechat_home, script_language[i]);
"%s/%s", weechat_data_dir, script_language[i]);
weechat_exec_on_files (directory, 0, 0,
&script_completion_exec_file_cb,
pointers);
/* look for files in "~/.weechat/<language>/autoload/" */
/* look for files in <weechat_data_dir>/<language>/autoload */
snprintf (directory, length,
"%s/%s/autoload", weechat_home, script_language[i]);
"%s/%s/autoload", weechat_data_dir, script_language[i]);
weechat_exec_on_files (directory, 0, 0,
&script_completion_exec_file_cb,
pointers);
@@ -227,8 +227,8 @@ script_completion_scripts_files_cb (const void *pointer, void *data,
free (directory);
}
if (weechat_home)
free (weechat_home);
if (weechat_data_dir)
free (weechat_data_dir);
return WEECHAT_RC_OK;
}
+23 -7
View File
@@ -148,8 +148,7 @@ script_config_get_diff_command ()
}
/*
* Gets filename with script
* (by default "/home/xxx/.weechat/script/plugins.xml.gz").
* Gets filename with list of scripts.
*
* Note: result must be freed after use.
*/
@@ -159,9 +158,19 @@ script_config_get_xml_filename ()
{
char *path, *filename;
int length;
struct t_hashtable *options;
options = weechat_hashtable_new (
32,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING,
NULL, NULL);
if (options)
weechat_hashtable_set (options, "directory", "cache");
path = weechat_string_eval_path_home (
weechat_config_string (script_config_scripts_path), NULL, NULL, NULL);
weechat_config_string (script_config_scripts_path), NULL, NULL, options);
if (options)
weechat_hashtable_free (options);
length = strlen (path) + 64;
filename = malloc (length);
if (filename)
@@ -172,11 +181,8 @@ script_config_get_xml_filename ()
/*
* Gets filename for a script to download.
*
* If suffix is not NULL, it is added to filename.
*
* Example: "/home/xxx/.weechat/script/go.py"
*
* Note: result must be freed after use.
*/
@@ -186,9 +192,19 @@ script_config_get_script_download_filename (struct t_script_repo *script,
{
char *path, *filename;
int length;
struct t_hashtable *options;
options = weechat_hashtable_new (
32,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING,
NULL, NULL);
if (options)
weechat_hashtable_set (options, "directory", "cache");
path = weechat_string_eval_path_home (
weechat_config_string (script_config_scripts_path), NULL, NULL, NULL);
weechat_config_string (script_config_scripts_path), NULL, NULL, options);
if (options)
weechat_hashtable_free (options);
length = strlen (path) + 1 + strlen (script->name_with_extension)
+ ((suffix) ? strlen (suffix) : 0) + 1;
filename = malloc (length);
+16 -16
View File
@@ -165,28 +165,28 @@ script_repo_search_by_name_ext (const char *name_with_extension)
char *
script_repo_get_filename_loaded (struct t_script_repo *script)
{
char *weechat_home, *filename, resolved_path[PATH_MAX];
char *weechat_data_dir, *filename, resolved_path[PATH_MAX];
int length;
struct stat st;
weechat_home = weechat_info_get ("weechat_dir", NULL);
length = strlen (weechat_home) + strlen (script->name_with_extension) + 64;
weechat_data_dir = weechat_info_get ("weechat_data_dir", NULL);
length = strlen (weechat_data_dir) + strlen (script->name_with_extension) + 64;
filename = malloc (length);
if (!filename)
{
if (weechat_home)
free (weechat_home);
if (weechat_data_dir)
free (weechat_data_dir);
return NULL;
}
snprintf (filename, length, "%s/%s/autoload/%s",
weechat_home,
weechat_data_dir,
script_language[script->language],
script->name_with_extension);
if (stat (filename, &st) != 0)
{
snprintf (filename, length, "%s/%s/%s",
weechat_home,
weechat_data_dir,
script_language[script->language],
script->name_with_extension);
if (stat (filename, &st) != 0)
@@ -195,8 +195,8 @@ script_repo_get_filename_loaded (struct t_script_repo *script)
}
}
if (weechat_home)
free (weechat_home);
if (weechat_data_dir)
free (weechat_data_dir);
if (!filename[0])
{
@@ -798,7 +798,7 @@ void
script_repo_update_status (struct t_script_repo *script)
{
const char *version;
char *weechat_home, *filename, *sha512sum;
char *weechat_data_dir, *filename, *sha512sum;
struct stat st;
int length;
struct t_script_repo *ptr_script;
@@ -807,13 +807,13 @@ script_repo_update_status (struct t_script_repo *script)
sha512sum = NULL;
/* check if script is installed (file found on disk) */
weechat_home = weechat_info_get ("weechat_dir", NULL);
length = strlen (weechat_home) + strlen (script->name_with_extension) + 64;
weechat_data_dir = weechat_info_get ("weechat_data_dir", NULL);
length = strlen (weechat_data_dir) + strlen (script->name_with_extension) + 64;
filename = malloc (length);
if (filename)
{
snprintf (filename, length, "%s/%s/autoload/%s",
weechat_home,
weechat_data_dir,
script_language[script->language],
script->name_with_extension);
if (stat (filename, &st) == 0)
@@ -825,7 +825,7 @@ script_repo_update_status (struct t_script_repo *script)
else
{
snprintf (filename, length, "%s/%s/%s",
weechat_home,
weechat_data_dir,
script_language[script->language],
script->name_with_extension);
if (stat (filename, &st) == 0)
@@ -837,8 +837,8 @@ script_repo_update_status (struct t_script_repo *script)
free (filename);
}
if (weechat_home)
free (weechat_home);
if (weechat_data_dir)
free (weechat_data_dir);
/* check if script is held */
if (script_repo_script_is_held (script))
+1 -1
View File
@@ -371,7 +371,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
script_config_read ();
weechat_mkdir_home (SCRIPT_PLUGIN_NAME, 0755);
weechat_mkdir_home ("${weechat_cache_dir}/" SCRIPT_PLUGIN_NAME, 0755);
script_command_init ();
script_completion_init ();