Skip to content

Commit

Permalink
Use same-file crate instead of canonicalize
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Aug 28, 2023
1 parent b8d6356 commit ad45832
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 15 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down

0 comments on commit ad45832

Please sign in to comment.