From 3e102e2e0b7765b43e8a2e65ae8bbf83fc8fb689 Mon Sep 17 00:00:00 2001 From: iho Date: Wed, 11 Oct 2023 23:33:45 +0300 Subject: [PATCH] Use dunce --- Cargo.lock | 7 +++++++ cargo-near/Cargo.toml | 1 + cargo-near/src/util/mod.rs | 16 ++++++---------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 845860f6..70861865 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -656,6 +656,7 @@ dependencies = [ "color-eyre", "colored", "derive_more", + "dunce", "env_logger", "inquire", "interactive-clap", @@ -1312,6 +1313,12 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" +[[package]] +name = "dunce" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" + [[package]] name = "dyn-clone" version = "1.0.14" diff --git a/cargo-near/Cargo.toml b/cargo-near/Cargo.toml index 74774bfa..b26c3307 100644 --- a/cargo-near/Cargo.toml +++ b/cargo-near/Cargo.toml @@ -42,3 +42,4 @@ interactive-clap-derive = "0.2.5" near-cli-rs = { version = "0.5.2" } derive_more = "0.99.9" shell-words = "1.0.0" +dunce = "1" \ No newline at end of file diff --git a/cargo-near/src/util/mod.rs b/cargo-near/src/util/mod.rs index eeaa05a6..795f2b10 100644 --- a/cargo-near/src/util/mod.rs +++ b/cargo-near/src/util/mod.rs @@ -56,6 +56,7 @@ where if let Some(path) = working_dir { let path = path.as_ref(); + let path = force_canonicalize_dir(path).unwrap(); log::debug!("Setting cargo working dir to '{}'", path); cmd.current_dir(path); } @@ -238,19 +239,14 @@ pub(crate) fn compile_project( } } -const UNC_PREFIX: &str = r"\\?\"; /// Create the directory if it doesn't exist, and return the absolute path to it. pub(crate) fn force_canonicalize_dir(dir: &Utf8Path) -> color_eyre::eyre::Result { fs::create_dir_all(dir).wrap_err_with(|| format!("failed to create directory `{}`", dir))?; - dir.canonicalize_utf8() - .map(|path| { - if path.starts_with(UNC_PREFIX) { - path.strip_prefix(UNC_PREFIX).unwrap().to_path_buf() - } else { - path - } - }) - .wrap_err_with(|| format!("failed to access output directory `{}`", dir)) + let compatible_path = dunce::canonicalize(&dir); + match compatible_path { + Ok(path) => Ok(Utf8PathBuf::from_path_buf(path).unwrap()), + Err(err) => Err(err).wrap_err_with(|| format!("failed to canonicalize path: {} ", dir)), + } } /// Copy a file to a destination.