From 6b9c6e20b68bd68f043213a0f7c2cec4f8317800 Mon Sep 17 00:00:00 2001
From: Stephan Dilly <dilly.stephan@gmail.com>
Date: Sun, 25 Oct 2020 18:18:03 +0100
Subject: [PATCH] update to dirs-next and remove migration code

---
 CHANGELOG.md |  1 +
 Cargo.lock   | 17 +++++++++--------
 Cargo.toml   |  2 +-
 src/main.rs  | 33 ++-------------------------------
 4 files changed, 13 insertions(+), 40 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4bfaf212c4..90e9a06218 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 - scrollbar in long commit messages [[@timaliberdov](https://github.com/timaliberdov)] ([#308](https://github.com/extrawurst/gitui/issues/308))
 
 ### Changed
+- upgrade `dirs` to `dirs-next` / remove cfg migration code ([#351](https://github.com/extrawurst/gitui/issues/351)) ([#366](https://github.com/extrawurst/gitui/issues/366))
 - do not highlight selection in diff view when not focused ([#270](https://github.com/extrawurst/gitui/issues/270))
 - copy to clipboard using `xclip`(linux), `pbcopy`(mac) or `clip`(win) [[@cruessler](https://github.com/cruessler)] ([#262](https://github.com/extrawurst/gitui/issues/262))
 - compact treeview [[@WizardOhio24](https://github.com/WizardOhio24)] ([#192](https://github.com/extrawurst/gitui/issues/192))
diff --git a/Cargo.lock b/Cargo.lock
index 53713f75a0..36e6e0ce9f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -355,19 +355,20 @@ dependencies = [
 ]
 
 [[package]]
-name = "dirs"
-version = "3.0.1"
+name = "dirs-next"
+version = "2.0.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "142995ed02755914747cc6ca76fc7e4583cd18578746716d0508ea6ed558b9ff"
+checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1"
 dependencies = [
- "dirs-sys",
+ "cfg-if 1.0.0",
+ "dirs-sys-next",
 ]
 
 [[package]]
-name = "dirs-sys"
-version = "0.3.5"
+name = "dirs-sys-next"
+version = "0.1.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8e93d7f5705de3e49895a2b5e0b8855a1c27f080192ae9c32a6432d50741a57a"
+checksum = "99de365f605554ae33f115102a02057d4fc18b01f3284d6870be0938743cfe7d"
 dependencies = [
  "libc",
  "redox_users",
@@ -447,7 +448,7 @@ dependencies = [
  "clap",
  "crossbeam-channel",
  "crossterm 0.18.0",
- "dirs",
+ "dirs-next",
  "itertools",
  "log",
  "pprof",
diff --git a/Cargo.toml b/Cargo.toml
index 94abe98c5e..d346ca4010 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -29,7 +29,7 @@ itertools = "0.9"
 rayon-core = "1.9"
 log = "0.4"
 simplelog = { version = "0.8", default-features = false }
-dirs = "3.0"
+dirs-next = "2.0"
 crossbeam-channel = "0.5"
 scopeguard = "1.1"
 bitflags = "1.2"
diff --git a/src/main.rs b/src/main.rs
index c8b0694348..976d8d4119 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -83,12 +83,6 @@ 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");
@@ -237,7 +231,7 @@ fn start_terminal<W: Write>(
 }
 
 fn get_app_cache_path() -> Result<PathBuf> {
-    let mut path = dirs::cache_dir()
+    let mut path = dirs_next::cache_dir()
         .ok_or_else(|| anyhow!("failed to find os cache dir."))?;
 
     path.push("gitui");
@@ -246,7 +240,7 @@ fn get_app_cache_path() -> Result<PathBuf> {
 }
 
 fn get_app_config_path() -> Result<PathBuf> {
-    let mut path = dirs::config_dir()
+    let mut path = dirs_next::config_dir()
         .ok_or_else(|| anyhow!("failed to find os config dir."))?;
 
     path.push("gitui");
@@ -254,29 +248,6 @@ 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");