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..fd1ff61 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" 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 22fd2ff..611dedb 100644 --- a/src/db.rs +++ b/src/db.rs @@ -1,6 +1,5 @@ use crate::config; use crate::dir::{Dir, Epoch, Rank}; -use crate::util; use anyhow::{anyhow, bail, Context, Result}; use serde::{Deserialize, Serialize}; @@ -145,7 +144,7 @@ impl DB { continue; } }; - let path_abs = match Path::new(path_str).canonicalize() { + let path_abs = match dunce::canonicalize(Path::new(path_str)) { Ok(path) => path, Err(e) => { eprintln!("invalid path '{}' at line {}: {}", path_str, line_number, e); @@ -186,10 +185,7 @@ impl DB { } pub fn add>(&mut self, path: P, max_age: Rank, now: Epoch) -> Result<()> { - let path_abs = path - .as_ref() - .canonicalize() - .and_then(|path| Ok(util::remove_verbatim_disk_in_path(path))) + 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) { @@ -259,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 { diff --git a/src/util.rs b/src/util.rs index 396e80c..89d7a51 100644 --- a/src/util.rs +++ b/src/util.rs @@ -7,7 +7,7 @@ use anyhow::{anyhow, bail, Context, Result}; use std::cmp::Reverse; use std::io::{Read, Write}; -use std::path::{Component, Path, PathBuf, Prefix}; +use std::path::Path; use std::process::{Command, Stdio}; use std::time::SystemTime; @@ -26,28 +26,6 @@ pub fn path_to_bytes>(path: &P) -> Result<&[u8]> { } } -#[cfg(not(windows))] -pub fn remove_verbatim_disk_in_path(path: PathBuf) -> PathBuf { - path -} - -#[cfg(windows)] -pub fn remove_verbatim_disk_in_path(path: PathBuf) -> PathBuf { - let mut new_path = PathBuf::new(); - for component in path.components() { - if let Component::Prefix(prefix) = component { - if let Prefix::VerbatimDisk(drive) = prefix.kind() { - new_path.push(format!("{}:", drive as char)); - continue; - } - } - - new_path.push(component); - } - - new_path -} - #[cfg(unix)] pub fn bytes_to_path(bytes: &[u8]) -> Result<&Path> { use std::ffi::OsStr;