Switch from dirs_next 2.0 to dirs 5.0

This commit is contained in:
Jan Christian Grünhage 2024-07-16 01:15:48 +02:00
parent 3d1145e759
commit 3dc5ea6d6a
11 changed files with 37 additions and 31 deletions

30
Cargo.lock generated
View File

@ -1219,24 +1219,24 @@ dependencies = [
] ]
[[package]] [[package]]
name = "dirs-next" name = "dirs"
version = "2.0.0" version = "5.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225"
dependencies = [ dependencies = [
"cfg-if", "dirs-sys",
"dirs-sys-next",
] ]
[[package]] [[package]]
name = "dirs-sys-next" name = "dirs-sys"
version = "0.1.2" version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c"
dependencies = [ dependencies = [
"libc", "libc",
"option-ext",
"redox_users", "redox_users",
"winapi", "windows-sys 0.48.0",
] ]
[[package]] [[package]]
@ -2873,7 +2873,7 @@ dependencies = [
"assert_cmd", "assert_cmd",
"crossterm", "crossterm",
"ctrlc", "ctrlc",
"dirs-next", "dirs",
"log", "log",
"miette", "miette",
"mimalloc", "mimalloc",
@ -3047,7 +3047,7 @@ dependencies = [
"deunicode", "deunicode",
"dialoguer", "dialoguer",
"digest", "digest",
"dirs-next", "dirs",
"dtparse", "dtparse",
"encoding_rs", "encoding_rs",
"fancy-regex", "fancy-regex",
@ -3245,7 +3245,7 @@ dependencies = [
name = "nu-path" name = "nu-path"
version = "0.95.1" version = "0.95.1"
dependencies = [ dependencies = [
"dirs-next", "dirs",
"omnipath", "omnipath",
"pwd", "pwd",
] ]
@ -3836,6 +3836,12 @@ dependencies = [
"vcpkg", "vcpkg",
] ]
[[package]]
name = "option-ext"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
[[package]] [[package]]
name = "ordered-multimap" name = "ordered-multimap"
version = "0.7.3" version = "0.7.3"

View File

@ -83,7 +83,7 @@ ctrlc = "3.4"
deunicode = "1.6.0" deunicode = "1.6.0"
dialoguer = { default-features = false, version = "0.11" } dialoguer = { default-features = false, version = "0.11" }
digest = { default-features = false, version = "0.10" } digest = { default-features = false, version = "0.10" }
dirs-next = "2.0" dirs = "5.0"
dtparse = "2.0" dtparse = "2.0"
encoding_rs = "0.8" encoding_rs = "0.8"
fancy-regex = "0.13" fancy-regex = "0.13"
@ -201,7 +201,7 @@ reedline = { workspace = true, features = ["bashisms", "sqlite"] }
crossterm = { workspace = true } crossterm = { workspace = true }
ctrlc = { workspace = true } ctrlc = { workspace = true }
dirs-next = { workspace = true } dirs = { workspace = true }
log = { workspace = true } log = { workspace = true }
miette = { workspace = true, features = ["fancy-no-backtrace", "fancy"] } miette = { workspace = true, features = ["fancy-no-backtrace", "fancy"] }
mimalloc = { version = "0.1.42", default-features = false, optional = true } mimalloc = { version = "0.1.42", default-features = false, optional = true }
@ -229,7 +229,7 @@ nu-test-support = { path = "./crates/nu-test-support", version = "0.95.1" }
nu-plugin-protocol = { path = "./crates/nu-plugin-protocol", version = "0.95.1" } nu-plugin-protocol = { path = "./crates/nu-plugin-protocol", version = "0.95.1" }
nu-plugin-core = { path = "./crates/nu-plugin-core", version = "0.95.1" } nu-plugin-core = { path = "./crates/nu-plugin-core", version = "0.95.1" }
assert_cmd = "2.0" assert_cmd = "2.0"
dirs-next = { workspace = true } dirs = { workspace = true }
tango-bench = "0.5" tango-bench = "0.5"
pretty_assertions = { workspace = true } pretty_assertions = { workspace = true }
regex = { workspace = true } regex = { workspace = true }

View File

@ -140,10 +140,10 @@ trash-support = ["trash"]
nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.95.1" } nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.95.1" }
nu-test-support = { path = "../nu-test-support", version = "0.95.1" } nu-test-support = { path = "../nu-test-support", version = "0.95.1" }
dirs-next = { workspace = true } dirs = { workspace = true }
mockito = { workspace = true, default-features = false } mockito = { workspace = true, default-features = false }
quickcheck = { workspace = true } quickcheck = { workspace = true }
quickcheck_macros = { workspace = true } quickcheck_macros = { workspace = true }
rstest = { workspace = true, default-features = false } rstest = { workspace = true, default-features = false }
pretty_assertions = { workspace = true } pretty_assertions = { workspace = true }
tempfile = { workspace = true } tempfile = { workspace = true }

View File

@ -606,7 +606,7 @@ mod test {
assert_eq!(actual, expected); assert_eq!(actual, expected);
let actual = expand_glob("~/foo.txt", cwd, Span::unknown(), &Signals::empty()).unwrap(); let actual = expand_glob("~/foo.txt", cwd, Span::unknown(), &Signals::empty()).unwrap();
let home = dirs_next::home_dir().expect("failed to get home dir"); let home = dirs::home_dir().expect("failed to get home dir");
let expected: Vec<OsString> = vec![home.join("foo.txt").into()]; let expected: Vec<OsString> = vec![home.join("foo.txt").into()];
assert_eq!(actual, expected); assert_eq!(actual, expected);
}) })

View File

@ -151,7 +151,7 @@ fn filesystem_change_to_home_directory() {
" "
); );
assert_eq!(Some(PathBuf::from(actual.out)), dirs_next::home_dir()); assert_eq!(Some(PathBuf::from(actual.out)), dirs::home_dir());
}) })
} }

View File

@ -309,7 +309,7 @@ fn external_arg_expand_tilde() {
"# "#
)); ));
let home = dirs_next::home_dir().expect("failed to find home dir"); let home = dirs::home_dir().expect("failed to find home dir");
assert_eq!( assert_eq!(
actual.out, actual.out,

View File

@ -12,10 +12,10 @@ exclude = ["/fuzz"]
bench = false bench = false
[dependencies] [dependencies]
dirs-next = { workspace = true } dirs = { workspace = true }
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
omnipath = { workspace = true } omnipath = { workspace = true }
[target.'cfg(all(unix, not(target_os = "macos"), not(target_os = "android")))'.dependencies] [target.'cfg(all(unix, not(target_os = "macos"), not(target_os = "android")))'.dependencies]
pwd = { workspace = true } pwd = { workspace = true }

View File

@ -3,14 +3,14 @@ use omnipath::WinPathExt;
use std::path::PathBuf; use std::path::PathBuf;
pub fn home_dir() -> Option<PathBuf> { pub fn home_dir() -> Option<PathBuf> {
dirs_next::home_dir() dirs::home_dir()
} }
/// Return the data directory for the current platform or XDG_DATA_HOME if specified. /// Return the data directory for the current platform or XDG_DATA_HOME if specified.
pub fn data_dir() -> Option<PathBuf> { pub fn data_dir() -> Option<PathBuf> {
match std::env::var("XDG_DATA_HOME").map(PathBuf::from) { match std::env::var("XDG_DATA_HOME").map(PathBuf::from) {
Ok(xdg_data) if xdg_data.is_absolute() => Some(canonicalize(&xdg_data).unwrap_or(xdg_data)), Ok(xdg_data) if xdg_data.is_absolute() => Some(canonicalize(&xdg_data).unwrap_or(xdg_data)),
_ => get_canonicalized_path(dirs_next::data_dir()), _ => get_canonicalized_path(dirs::data_dir()),
} }
} }
@ -20,7 +20,7 @@ pub fn cache_dir() -> Option<PathBuf> {
Ok(xdg_cache) if xdg_cache.is_absolute() => { Ok(xdg_cache) if xdg_cache.is_absolute() => {
Some(canonicalize(&xdg_cache).unwrap_or(xdg_cache)) Some(canonicalize(&xdg_cache).unwrap_or(xdg_cache))
} }
_ => get_canonicalized_path(dirs_next::cache_dir()), _ => get_canonicalized_path(dirs::cache_dir()),
} }
} }
@ -30,7 +30,7 @@ pub fn config_dir() -> Option<PathBuf> {
Ok(xdg_config) if xdg_config.is_absolute() => { Ok(xdg_config) if xdg_config.is_absolute() => {
Some(canonicalize(&xdg_config).unwrap_or(xdg_config)) Some(canonicalize(&xdg_config).unwrap_or(xdg_config))
} }
_ => get_canonicalized_path(dirs_next::config_dir()), _ => get_canonicalized_path(dirs::config_dir()),
} }
} }

View File

@ -77,7 +77,7 @@ fn user_home_dir(username: &str) -> PathBuf {
fn user_home_dir(username: &str) -> PathBuf { fn user_home_dir(username: &str) -> PathBuf {
use std::path::Component; use std::path::Component;
match dirs_next::home_dir() { match dirs::home_dir() {
None => { None => {
// Termux always has the same home directory // Termux always has the same home directory
#[cfg(target_os = "android")] #[cfg(target_os = "android")]
@ -145,7 +145,7 @@ fn expand_tilde_with_another_user_home(path: &Path) -> PathBuf {
/// Expand tilde ("~") into a home directory if it is the first path component /// Expand tilde ("~") into a home directory if it is the first path component
pub fn expand_tilde(path: impl AsRef<Path>) -> PathBuf { pub fn expand_tilde(path: impl AsRef<Path>) -> PathBuf {
// TODO: Extend this to work with "~user" style of home paths // TODO: Extend this to work with "~user" style of home paths
expand_tilde_with_home(path, dirs_next::home_dir()) expand_tilde_with_home(path, dirs::home_dir())
} }
#[cfg(test)] #[cfg(test)]

View File

@ -100,7 +100,7 @@ fn main() -> Result<()> {
}, },
); );
} else if let Some(old_config) = } else if let Some(old_config) =
nu_path::get_canonicalized_path(dirs_next::config_dir()).map(|p| p.join("nushell")) nu_path::get_canonicalized_path(dirs::config_dir()).map(|p| p.join("nushell"))
{ {
let xdg_config_empty = nushell_config_path let xdg_config_empty = nushell_config_path
.read_dir() .read_dir()

View File

@ -235,7 +235,7 @@ fn test_xdg_config_empty() {
playground.with_env("XDG_CONFIG_HOME", ""); playground.with_env("XDG_CONFIG_HOME", "");
let actual = run(playground, "$nu.default-config-dir"); let actual = run(playground, "$nu.default-config-dir");
let expected = dirs_next::config_dir().unwrap().join("nushell"); let expected = dirs::config_dir().unwrap().join("nushell");
assert_eq!( assert_eq!(
actual, actual,
adjust_canonicalization(expected.canonicalize().unwrap_or(expected)) adjust_canonicalization(expected.canonicalize().unwrap_or(expected))
@ -250,7 +250,7 @@ fn test_xdg_config_bad() {
playground.with_env("XDG_CONFIG_HOME", xdg_config_home); playground.with_env("XDG_CONFIG_HOME", xdg_config_home);
let actual = run(playground, "$nu.default-config-dir"); let actual = run(playground, "$nu.default-config-dir");
let expected = dirs_next::config_dir().unwrap().join("nushell"); let expected = dirs::config_dir().unwrap().join("nushell");
assert_eq!( assert_eq!(
actual, actual,
adjust_canonicalization(expected.canonicalize().unwrap_or(expected)) adjust_canonicalization(expected.canonicalize().unwrap_or(expected))