mirror of
https://github.com/extrawurst/gitui.git
synced 2024-11-23 20:52:54 +03:00
Add config migration
With the upgrade to version 3 of `dirs`, the `config_dir` function returns a new path for macOS. This migrates the file present at the old location (now available through the `preferences_dir` function) to the new location.
This commit is contained in:
parent
b89ec94066
commit
6b4d088b28
29
src/main.rs
29
src/main.rs
@ -79,6 +79,12 @@ fn main() -> Result<()> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// TODO: Remove this when upgrading from v0.8.x is unlikely
|
||||
// Only run this migration on macOS, as it's the only platform where the config needs to be moved
|
||||
if cfg!(target_os = "macos") {
|
||||
migrate_config()?;
|
||||
}
|
||||
|
||||
setup_terminal()?;
|
||||
defer! {
|
||||
shutdown_terminal().expect("shutdown failed");
|
||||
@ -244,6 +250,29 @@ fn get_app_config_path() -> Result<PathBuf> {
|
||||
Ok(path)
|
||||
}
|
||||
|
||||
fn migrate_config() -> Result<()> {
|
||||
let mut path = dirs::preference_dir().ok_or_else(|| {
|
||||
anyhow!("failed to find os preference dir.")
|
||||
})?;
|
||||
|
||||
path.push("gitui");
|
||||
if !path.exists() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let config_path = get_app_config_path()?;
|
||||
let entries = path.read_dir()?.flatten();
|
||||
for entry in entries {
|
||||
let mut config_path = config_path.clone();
|
||||
config_path.push(entry.file_name());
|
||||
fs::rename(entry.path(), config_path)?;
|
||||
}
|
||||
|
||||
let _ = fs::remove_dir(path);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn setup_logging() -> Result<()> {
|
||||
let mut path = get_app_cache_path()?;
|
||||
path.push("gitui.log");
|
||||
|
Loading…
Reference in New Issue
Block a user