Skip to content

Commit 6b4d088

Browse files
jonstodleStephan Dilly
authored andcommitted
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.
1 parent b89ec94 commit 6b4d088

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/main.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ fn main() -> Result<()> {
7979
return Ok(());
8080
}
8181

82+
// TODO: Remove this when upgrading from v0.8.x is unlikely
83+
// Only run this migration on macOS, as it's the only platform where the config needs to be moved
84+
if cfg!(target_os = "macos") {
85+
migrate_config()?;
86+
}
87+
8288
setup_terminal()?;
8389
defer! {
8490
shutdown_terminal().expect("shutdown failed");
@@ -244,6 +250,29 @@ fn get_app_config_path() -> Result<PathBuf> {
244250
Ok(path)
245251
}
246252

253+
fn migrate_config() -> Result<()> {
254+
let mut path = dirs::preference_dir().ok_or_else(|| {
255+
anyhow!("failed to find os preference dir.")
256+
})?;
257+
258+
path.push("gitui");
259+
if !path.exists() {
260+
return Ok(());
261+
}
262+
263+
let config_path = get_app_config_path()?;
264+
let entries = path.read_dir()?.flatten();
265+
for entry in entries {
266+
let mut config_path = config_path.clone();
267+
config_path.push(entry.file_name());
268+
fs::rename(entry.path(), config_path)?;
269+
}
270+
271+
let _ = fs::remove_dir(path);
272+
273+
Ok(())
274+
}
275+
247276
fn setup_logging() -> Result<()> {
248277
let mut path = get_app_cache_path()?;
249278
path.push("gitui.log");

0 commit comments

Comments
 (0)