From ad458326d8a2d9be7ae3e7a0ede1aab77c0c2041 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Tue, 29 Aug 2023 05:12:05 +0900 Subject: [PATCH] Use same-file crate instead of canonicalize --- Cargo.toml | 1 + src/main.rs | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b7c9fbd..0c449dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,7 @@ ctrlc = { version = "3.1.4", features = ["termination"] } fs-err = "2.5" is-terminal = "0.4" lexopt = "0.3" +same-file = "1.0.1" serde = { version = "1.0.103", features = ["derive"] } serde_json = "1" shell-escape = "0.1.5" diff --git a/src/main.rs b/src/main.rs index 9ad98b9..6ca5677 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,9 +13,10 @@ mod cargo; mod cli; mod restore; -use std::{env, path::PathBuf}; +use std::env; use anyhow::{bail, Context as _, Result}; +use camino::Utf8PathBuf; use fs_err as fs; use crate::{cargo::Workspace, cli::Args}; @@ -76,7 +77,7 @@ fn with( if is_root { bail!("--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 { @@ -145,7 +146,7 @@ fn remove_dev_deps(doc: &mut toml_edit::Document) { fn remove_private_crates( doc: &mut toml_edit::Document, metadata: &cargo_metadata::Metadata, - private_crates: &[PathBuf], + private_crates: &[&Utf8PathBuf], ) -> Result<()> { let table = doc.as_table_mut(); if let Some(workspace) = table.get_mut("workspace").and_then(toml_edit::Item::as_table_like_mut) @@ -155,9 +156,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; }