Skip to content

Commit

Permalink
Strip UNC prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
iho committed Oct 11, 2023
1 parent a675e70 commit 4fde946
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions cargo-near/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ where
if let Some(path) = working_dir {
let path = path.as_ref();
log::debug!("Setting cargo working dir to '{}'", path);
#[cfg(target_os = "windows")]
{
let mut path = path.as_std_path().to_string_lossy().to_string();
// remove first 4 elements from path string
path.drain(..4);
let path = std::path::PathBuf::from(path);
}
cmd.current_dir(path);
}

Expand Down Expand Up @@ -245,10 +238,18 @@ 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<Utf8PathBuf> {
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))
}

Expand Down

0 comments on commit 4fde946

Please sign in to comment.