From a4b202f9dab60810772300a07a5f43e27ca865f5 Mon Sep 17 00:00:00 2001 From: Jason Shirk Date: Thu, 9 Apr 2020 11:43:16 -0700 Subject: [PATCH] Canonicalize to regular paths instead of UNC paths on Windows --- CHANGELOG.md | 1 + Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/db.rs | 8 +++----- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21c099a..5e23105 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `zoxide remove` now throws an error if there was no match in the database. - Interactive mode in `zoxide` no longer throws an error if `fzf` exits gracefully. +- Canonicalize to regular paths instead of UNC paths on Windows. ## [0.3.1] - 2020-04-03 diff --git a/Cargo.lock b/Cargo.lock index 67655d4..e9aee75 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -136,6 +136,11 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "dunce" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "getrandom" version = "0.1.14" @@ -432,6 +437,7 @@ dependencies = [ "bstr 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "dunce 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)", "structopt 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -456,6 +462,7 @@ dependencies = [ "checksum crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" "checksum dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "13aea89a5c93364a98e9b37b2fa237effbb694d5cfe01c5b70941f7eb087d5e3" "checksum dirs-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "afa0b23de8fd801745c471deffa6e12d248f962c9fd4b4c33787b055599bde7b" +"checksum dunce 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0ad6bf6a88548d1126045c413548df1453d9be094a8ab9fd59bf1fdd338da4f" "checksum getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" "checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" "checksum hermit-abi 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "725cf19794cf90aa94e65050cb4191ff5d8fa87a498383774c47b332e3af952e" diff --git a/Cargo.toml b/Cargo.toml index a731381..5b69452 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ anyhow = "1.0.28" bincode = "1.2.1" clap = "2.33.0" dirs = "2.0.2" +dunce = "1.0.0" serde = { version = "1.0.106", features = ["derive"] } structopt = "0.3.12" uuid = { version = "0.8.1", features = ["v4"] } diff --git a/src/db.rs b/src/db.rs index df33498..3068ac0 100644 --- a/src/db.rs +++ b/src/db.rs @@ -144,7 +144,7 @@ impl DB { continue; } }; - let path_abs = match Path::new(path_str).canonicalize() { + let path_abs = match dunce::canonicalize(path_str) { Ok(path) => path, Err(e) => { eprintln!("invalid path '{}' at line {}: {}", path_str, line_number, e); @@ -185,9 +185,7 @@ impl DB { } pub fn add>(&mut self, path: P, max_age: Rank, now: Epoch) -> Result<()> { - let path_abs = path - .as_ref() - .canonicalize() + let path_abs = dunce::canonicalize(&path) .with_context(|| anyhow!("could not access directory: {}", path.as_ref().display()))?; match self.data.dirs.iter_mut().find(|dir| dir.path == path_abs) { @@ -257,7 +255,7 @@ impl DB { } pub fn remove>(&mut self, path: P) -> Result<()> { - if let Ok(path_abs) = path.as_ref().canonicalize() { + if let Ok(path_abs) = dunce::canonicalize(&path) { self.remove_exact(path_abs) .or_else(|_| self.remove_exact(path)) } else {