From: Daniel Carl Date: Mon, 12 Oct 2020 21:28:47 +0000 (+0200) Subject: Move some file to $XDG_DATA_HOME #582. X-Git-Url: https://git.owens.tech/git.owens.tech/git.owens.tech/git?a=commitdiff_plain;h=HEAD;p=vimb.git Move some file to $XDG_DATA_HOME #582. Do not store all files in XDG_CONFIG_HOME. --- diff --git a/CHANGELOG.md b/CHANGELOG.md index fc4ef85..bab4bef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. * The new env variable `$VIMB_SELECTION` is set to the current selected text whenever a `shellcmd` is run #592. * Allow to push link url to queue by `` #610. +### Changed +* Modes some files from `$XDG_CONFIG_HOME/vimb` into `$XDG_DATA_HOME/vimb` #582. + Following files are affected `bookmark`, `closed`, `command`, `config`, + `cookies.db`, `history`, `queue` and `search`. + Existing files could be moved to the new location by + ``` + mv $XDG_CONFIG_HOME/vimb/{bookmark,closed,command,cookies.db,history,queue,search} \ + $XDG_DATA_HOME/vimb + + # and same for existing profiles + mkdir $XDG_DATA_HOME/vimb/ + mv $XDG_CONFIG_HOME/vimb//{bookmark,closed,command,cookies.db,history,queue,search} \ + $XDG_DATA_HOME/vimb/ + ``` ### Fixed * Fixed ignored last line in config file if this line did not end in newline. * Fixed crash in normal_focus_last_active (Thanks to Maxime Coste) diff --git a/doc/vimb.1 b/doc/vimb.1 index f075f7c..a8f7e8a 100644 --- a/doc/vimb.1 +++ b/doc/vimb.1 @@ -1542,6 +1542,24 @@ this subdirectory. .I config Configuration file to set WebKit setting, some GUI styles and keybindings. .TP +.I scripts.js +This file can be used to run user scripts, that are injected into every page +that is opened. +.TP +.I style.css +File for userdefined CSS styles. +These file is used if the config variable `stylesheet' is enabled. +.PD +.RE +. +.TP +.IR $XDG_DATA_HOME/vimb[/PROFILE] +Directory for runtime data. +If executed with \fB-p \fIPROFILE\fR parameter, data files are written from +this subdirectory. +. +.RS +.PD 0 .I cookies.db Sqlite cookie storage. This file will not be touched if option \-\-incognito is set. @@ -1568,20 +1586,8 @@ Holds the read it later queue filled by `qpush'. .I search This file holds the history of search queries. This file will not be touched if option \-\-incognito is set. -.TP -.I scripts.js -This file can be used to run user scripts, that are injected into every page -that is opened. -.TP -.I style.css -File for userdefined CSS styles. -These file is used if the config variable `stylesheet' is enabled. .PD .RE -.TP -There are also some sample scripts installed together with Vimb under -PREFIX/share/vimb/examples. -. . .SH ENVIRONMENT .TP diff --git a/src/main.c b/src/main.c index 24f48ae..cf643b5 100644 --- a/src/main.c +++ b/src/main.c @@ -1828,9 +1828,9 @@ static void vimb_setup(void) { WebKitWebContext *ctx; WebKitCookieManager *cm; - char *path; + char *path, *dataPath; - /* prepare the file pathes */ + /* Prepare files in XDG_CONFIG_HOME */ path = util_get_config_dir(); if (vb.configfile) { @@ -1840,21 +1840,23 @@ static void vimb_setup(void) } else { vb.files[FILES_CONFIG] = g_build_filename(path, "config", NULL); } + vb.files[FILES_SCRIPT] = g_build_filename(path, "scripts.js", NULL); + vb.files[FILES_USER_STYLE] = g_build_filename(path, "style.css", NULL); + g_free(path); - /* Setup those files that are use multiple time during runtime */ + /* Prepare files in XDG_DATA_HOME */ + dataPath = util_get_data_dir(); if (!vb.incognito) { - vb.files[FILES_CLOSED] = g_build_filename(path, "closed", NULL); - vb.files[FILES_COOKIE] = g_build_filename(path, "cookies.db", NULL); + vb.files[FILES_CLOSED] = g_build_filename(dataPath, "closed", NULL); + vb.files[FILES_COOKIE] = g_build_filename(dataPath, "cookies.db", NULL); } - vb.files[FILES_BOOKMARK] = g_build_filename(path, "bookmark", NULL); - vb.files[FILES_QUEUE] = g_build_filename(path, "queue", NULL); - vb.files[FILES_SCRIPT] = g_build_filename(path, "scripts.js", NULL); - vb.files[FILES_USER_STYLE] = g_build_filename(path, "style.css", NULL); + vb.files[FILES_BOOKMARK] = g_build_filename(dataPath, "bookmark", NULL); + vb.files[FILES_QUEUE] = g_build_filename(dataPath, "queue", NULL); - vb.storage[STORAGE_HISTORY] = file_storage_new(path, "history", vb.incognito); - vb.storage[STORAGE_COMMAND] = file_storage_new(path, "command", vb.incognito); - vb.storage[STORAGE_SEARCH] = file_storage_new(path, "search", vb.incognito); - g_free(path); + vb.storage[STORAGE_HISTORY] = file_storage_new(dataPath, "history", vb.incognito); + vb.storage[STORAGE_COMMAND] = file_storage_new(dataPath, "command", vb.incognito); + vb.storage[STORAGE_SEARCH] = file_storage_new(dataPath, "search", vb.incognito); + g_free(dataPath); /* Use seperate rendering processed for the webview of the clients in the * current instance. This must be called as soon as possible according to diff --git a/src/util.c b/src/util.c index a716b03..56bbb0c 100644 --- a/src/util.c +++ b/src/util.c @@ -340,6 +340,18 @@ char *util_get_config_dir(void) return path; } +/** + * Retrieves the data directory path according to current used profile. + * Returned string must be freed. + */ +char *util_get_data_dir(void) +{ + char *path = g_build_filename(g_get_user_data_dir(), PROJECT, vb.profile, NULL); + create_dir_if_not_exists(path); + + return path; +} + /** * Retrieves the length bytes from given file. * diff --git a/src/util.h b/src/util.h index e4e887c..4d6e573 100644 --- a/src/util.h +++ b/src/util.h @@ -40,6 +40,7 @@ void util_file_prepend_line(const char *file, const char *line, unsigned int max_lines); char *util_file_pop_line(const char *file, int *item_count); char *util_get_config_dir(void); +char *util_get_data_dir(void); char *util_get_file_contents(const char *filename, gsize *length); gboolean util_file_set_content(const char *file, const char *contents); char **util_get_lines(const char *filename);