Skip to content

Commit 212ce86

Browse files
jonstodleStephan Dilly
authored andcommitted
Move config directory
This changes the config directory from the `dirs::cache_dir` to `dirs::config_dir`. It does however keep the cache directory as the default logging directory, as it seems a better fit. It also adds a function, `migrate_config`, which is called at startup to move directory entries inside the "old" config directory to the "new" one (but it skips moving log files). The intention is that this function can be removed after a few releases when the likelihood of someone upgrading from 0.6.0 or earlier is fairly small. Fixes #98
1 parent 602257f commit 212ce86

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

THEMES.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ default on light terminal:
44
![](assets/light-theme.png)
55

66
to change the colors of the program you have to modify `theme.ron` file
7-
[Ron format](https://github.com/ron-rs/ron) located at config path (same as [log path](README.md#diagnostics)).
7+
[Ron format](https://github.com/ron-rs/ron) located at config path. The path differs depending on the operating system:
8+
9+
* `$HOME/Library/Preferences/gitui/theme.ron` (mac)
10+
* `$XDG_CONFIG_HOME/gitui/theme.ron` (linux using XDG)
11+
* `$HOME/.config/gitui/theme.ron` (linux)
812

913
Valid colors can be found in [ColorDef](./src/ui/style.rs#ColorDef) struct. note that rgb colors might not be supported
10-
in every terminal.
14+
in every terminal.

src/main.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ fn main() -> Result<()> {
6666
return Ok(());
6767
}
6868

69+
// TODO: To be removed in a future version, when upgrading from 0.6.x or earlier is unlikely
70+
migrate_config()?;
71+
6972
setup_terminal()?;
7073
defer! {
7174
shutdown_terminal().expect("shutdown failed");
@@ -202,7 +205,26 @@ fn start_terminal<W: Write>(
202205
Ok(terminal)
203206
}
204207

205-
fn get_app_config_path() -> Result<PathBuf> {
208+
fn migrate_config() -> Result<()> {
209+
let cache_path: PathBuf = get_app_cache_path()?;
210+
211+
let entries = cache_path
212+
.read_dir()?
213+
.flat_map(|dir_entry| dir_entry)
214+
.filter(|entry| {
215+
!entry.file_name().to_string_lossy().ends_with(".log")
216+
});
217+
218+
for entry in entries {
219+
let mut config_path: PathBuf = get_app_config_path()?;
220+
config_path.push(entry.file_name());
221+
fs::rename(entry.path(), config_path)?;
222+
}
223+
224+
Ok(())
225+
}
226+
227+
fn get_app_cache_path() -> Result<PathBuf> {
206228
let mut path = dirs::cache_dir()
207229
.ok_or_else(|| anyhow!("failed to find os cache dir."))?;
208230

@@ -211,8 +233,17 @@ fn get_app_config_path() -> Result<PathBuf> {
211233
Ok(path)
212234
}
213235

236+
fn get_app_config_path() -> Result<PathBuf> {
237+
let mut path = dirs::config_dir()
238+
.ok_or_else(|| anyhow!("failed to find os config dir."))?;
239+
240+
path.push("gitui");
241+
fs::create_dir_all(&path)?;
242+
Ok(path)
243+
}
244+
214245
fn setup_logging() -> Result<()> {
215-
let mut path = get_app_config_path()?;
246+
let mut path = get_app_cache_path()?;
216247
path.push("gitui.log");
217248

218249
let _ = WriteLogger::init(

0 commit comments

Comments
 (0)