From 1239baac61568e157373023ac8a6de22e699a55c Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Tue, 29 Aug 2023 05:13:00 +0900 Subject: [PATCH] Use same-file crate instead of canonicalize --- Cargo.toml | 1 + src/manifest.rs | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4921e46d..f1ef8526 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,7 @@ anyhow = "1.0.47" ctrlc = { version = "3.1.4", features = ["termination"] } is-terminal = "0.4" lexopt = "0.3" +same-file = "1.0.1" serde_json = "1" slab = "0.4.4" termcolor = "1.1" diff --git a/src/manifest.rs b/src/manifest.rs index 274aacc3..e8bb6e45 100644 --- a/src/manifest.rs +++ b/src/manifest.rs @@ -129,7 +129,7 @@ pub(crate) fn with(cx: &Context, f: impl FnOnce() -> Result<()>) -> Result<()> { "--no-private is not supported yet with workspace with private root crate" ); } - private_crates.push(manifest_path.canonicalize()?); + private_crates.push(manifest_path); } else if is_root && no_private { // } else if no_dev_deps { @@ -197,7 +197,7 @@ fn remove_dev_deps(doc: &mut toml_edit::Document) { fn remove_private_crates( doc: &mut toml_edit::Document, metadata: &metadata::Metadata, - private_crates: &[PathBuf], + private_crates: &[&PathBuf], ) -> Result<()> { let table = doc.as_table_mut(); if let Some(workspace) = table.get_mut("workspace").and_then(toml_edit::Item::as_table_like_mut) @@ -207,9 +207,17 @@ fn remove_private_crates( let mut i = 0; while i < members.len() { if let Some(member) = members.get(i).and_then(toml_edit::Value::as_str) { - let manifest_path = - metadata.workspace_root.join(member).join("Cargo.toml").canonicalize()?; - if private_crates.iter().any(|p| *p == manifest_path) { + let manifest_path = metadata.workspace_root.join(member).join("Cargo.toml"); + if private_crates + .iter() + .find_map(|p| { + same_file::is_same_file(p, &manifest_path) + .map(|v| if v { Some(()) } else { None }) + .transpose() + }) + .transpose()? + .is_some() + { members.remove(i); continue; }