Skip to content

Commit

Permalink
Move some file to $XDG_DATA_HOME #582.
Browse files Browse the repository at this point in the history
Do not store all files in XDG_CONFIG_HOME.
  • Loading branch information
fanglingsu committed Oct 12, 2020
1 parent e92deb9 commit 14a9d2c
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 25 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<S-LeftMouse>` #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/<ProfileName>
mv $XDG_CONFIG_HOME/vimb/<ProfileName>/{bookmark,closed,command,cookies.db,history,queue,search} \
$XDG_DATA_HOME/vimb/<ProfileName>
```
### 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)
Expand Down
30 changes: 18 additions & 12 deletions doc/vimb.1
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
28 changes: 15 additions & 13 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
1 change: 1 addition & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 14a9d2c

Please sign in to comment.