diff --git a/Cargo.lock b/Cargo.lock index 0a57aa5be0..697148c70e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1485,6 +1485,7 @@ dependencies = [ "clap", "dialoguer", "directories-next", + "dunce", "flate2", "hex", "humantime-serde", diff --git a/src/canisters/frontend/ic-asset/src/sync.rs b/src/canisters/frontend/ic-asset/src/sync.rs index 2962c2f75d..e892225c8a 100644 --- a/src/canisters/frontend/ic-asset/src/sync.rs +++ b/src/canisters/frontend/ic-asset/src/sync.rs @@ -239,7 +239,7 @@ pub(crate) fn gather_asset_descriptors( let entries = WalkDir::new(&dir) .into_iter() .filter_entry(|entry| { - if let Ok(canonical_path) = &entry.path().canonicalize() { + if let Ok(canonical_path) = &dfx_core::fs::canonicalize(entry.path()) { let config = configuration .get_asset_config(canonical_path) .unwrap_or_default(); diff --git a/src/dfx-core/Cargo.toml b/src/dfx-core/Cargo.toml index f1b9fef3f3..c55966067d 100644 --- a/src/dfx-core/Cargo.toml +++ b/src/dfx-core/Cargo.toml @@ -17,6 +17,7 @@ candid = { workspace = true, features = ["random"] } clap = { workspace = true, features = ["string"] } dialoguer = "0.10.0" directories-next.workspace = true +dunce = "1.0" flate2 = { workspace = true, default-features = false, features = ["zlib-ng"] } hex = { workspace = true, features = ["serde"] } humantime-serde = "1.1.1" diff --git a/src/dfx-core/src/fs/mod.rs b/src/dfx-core/src/fs/mod.rs index 83eb3d412c..adddaf3d49 100644 --- a/src/dfx-core/src/fs/mod.rs +++ b/src/dfx-core/src/fs/mod.rs @@ -11,7 +11,7 @@ use std::fs::{Metadata, Permissions, ReadDir}; use std::path::{Path, PathBuf}; pub fn canonicalize(path: &Path) -> Result { - path.canonicalize() + dunce::canonicalize(path) .map_err(|err| FsError::new(CanonicalizePathFailed(path.to_path_buf(), err))) } diff --git a/src/dfx/src/lib/builders/mod.rs b/src/dfx/src/lib/builders/mod.rs index 231192b513..1fe50f1cef 100644 --- a/src/dfx/src/lib/builders/mod.rs +++ b/src/dfx/src/lib/builders/mod.rs @@ -104,12 +104,13 @@ pub trait CanisterBuilder { .context("`output` must not be None")?; if generate_output_dir.exists() { - let generate_output_dir = generate_output_dir.canonicalize().with_context(|| { - format!( - "Failed to canonicalize output dir {}.", - generate_output_dir.to_string_lossy() - ) - })?; + let generate_output_dir = dfx_core::fs::canonicalize(generate_output_dir) + .with_context(|| { + format!( + "Failed to canonicalize output dir {}.", + generate_output_dir.to_string_lossy() + ) + })?; if !generate_output_dir.starts_with(info.get_workspace_root()) { bail!( "Directory at '{}' is outside the workspace root.", @@ -321,9 +322,7 @@ fn ensure_trailing_newline(s: String) -> String { pub fn run_command(args: Vec, vars: &[Env<'_>], cwd: &Path) -> DfxResult<()> { let (command_name, arguments) = args.split_first().unwrap(); - let canonicalized = cwd - .join(command_name) - .canonicalize() + let canonicalized = dfx_core::fs::canonicalize(&cwd.join(command_name)) .or_else(|_| which::which(command_name)) .map_err(|_| anyhow!("Cannot find command or file {command_name}"))?; let mut cmd = Command::new(&canonicalized); diff --git a/src/dfx/src/lib/canister_info/assets.rs b/src/dfx/src/lib/canister_info/assets.rs index bde5259d7f..e00e675cbf 100644 --- a/src/dfx/src/lib/canister_info/assets.rs +++ b/src/dfx/src/lib/canister_info/assets.rs @@ -34,7 +34,7 @@ impl AssetsCanisterInfo { let input_root = &self.input_root; let source_paths: Vec = source_paths.iter().map(|x| input_root.join(x)).collect(); for source_path in &source_paths { - let canonical = source_path.canonicalize().with_context(|| { + let canonical = dfx_core::fs::canonicalize(source_path).with_context(|| { format!( "Unable to determine canonical location of asset source path {}", source_path.to_string_lossy() diff --git a/src/dfx/src/lib/operations/canister/install_canister.rs b/src/dfx/src/lib/operations/canister/install_canister.rs index 1bd13cd42b..3f94596cec 100644 --- a/src/dfx/src/lib/operations/canister/install_canister.rs +++ b/src/dfx/src/lib/operations/canister/install_canister.rs @@ -414,9 +414,7 @@ fn run_post_install_task( let cwd = canister.get_workspace_root(); let words = shell_words::split(task) .with_context(|| format!("Error interpreting post-install task `{task}`"))?; - let canonicalized = cwd - .join(&words[0]) - .canonicalize() + let canonicalized = dfx_core::fs::canonicalize(&cwd.join(&words[0])) .or_else(|_| which::which(&words[0])) .map_err(|_| anyhow!("Cannot find command or file {}", &words[0]))?; let mut command = Command::new(&canonicalized);