Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use dunce crate to remove UNC prefix #110

Merged
merged 11 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cargo-near/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
12 changes: 9 additions & 3 deletions cargo-near/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ where
cmd.envs(env);

if let Some(path) = working_dir {
let path = path.as_ref();
let path = force_canonicalize_dir(path.as_ref())?;
log::debug!("Setting cargo working dir to '{}'", path);
cmd.current_dir(path);
}
Expand Down Expand Up @@ -241,8 +241,14 @@ pub(crate) fn compile_project(
/// 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()
.wrap_err_with(|| format!("failed to access output directory `{}`", dir))
// use canonicalize from `dunce` create instead of default one from std because it's compatible with Windows UNC paths
// and don't break cargo compilation on Windows
// https://github.com/rust-lang/rust/issues/42869
Utf8PathBuf::from_path_buf(
dunce::canonicalize(dir)
.wrap_err_with(|| format!("failed to canonicalize path: {} ", dir))?,
)
.map_err(|err| color_eyre::eyre::eyre!("failed to convert path {}", err.to_string_lossy()))
}

/// Copy a file to a destination.
Expand Down
Loading