Skip to content

Fix check_for_file_and_add's check for conflict file #12135

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

Merged
merged 2 commits into from
May 15, 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
5 changes: 1 addition & 4 deletions src/cargo/ops/cargo_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,7 @@ fn check_for_file_and_add(
Err(_) => {
// The file exists somewhere outside of the package.
let file_name = file_path.file_name().unwrap();
if result
.iter()
.any(|ar| ar.rel_path.file_name().unwrap() == file_name)
{
if result.iter().any(|ar| ar.rel_path == file_name) {
ws.config().shell().warn(&format!(
"{} `{}` appears to be a path outside of the package, \
but there is already a file named `{}` in the root of the package. \
Expand Down
85 changes: 85 additions & 0 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2535,6 +2535,91 @@ See [..]
assert!(p.root().join("target/package/bar-0.0.1.crate").is_file());
}

#[cargo_test]
fn workspace_noconflict_readme() {
let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["bar"]
"#,
)
.file("README.md", "workspace readme")
.file(
"bar/Cargo.toml",
r#"
[package]
name = "bar"
version = "0.0.1"
repository = "https://github.com/bar/bar"
authors = []
license = "MIT"
description = "bar"
readme = "../README.md"
workspace = ".."
"#,
)
.file("bar/src/main.rs", "fn main() {}")
.file("bar/example/README.md", "# example readmdBar")
.build();

p.cargo("package")
.with_stderr(
"\
[PACKAGING] bar v0.0.1 ([CWD]/bar)
[VERIFYING] bar v0.0.1 ([CWD]/bar)
[COMPILING] bar v0.0.1 ([CWD]/[..])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[PACKAGED] [..] files, [..] ([..] compressed)
",
)
.run();
}

#[cargo_test]
fn workspace_conflict_readme() {
let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["bar"]
"#,
)
.file("README.md", "workspace readme")
.file(
"bar/Cargo.toml",
r#"
[package]
name = "bar"
version = "0.0.1"
repository = "https://github.com/bar/bar"
authors = []
license = "MIT"
description = "bar"
readme = "../README.md"
workspace = ".."
"#,
)
.file("bar/src/main.rs", "fn main() {}")
.file("bar/README.md", "# workspace member: Bar")
.build();

p.cargo("package")
.with_stderr(
"\
warning: readme `../README.md` appears to be a path outside of the package, but there is already a file named `README.md` in the root of the package. The archived crate will contain the copy in the root of the package. Update the readme to point to the path relative to the root of the package to remove this warning.
[PACKAGING] bar v0.0.1 ([CWD]/bar)
[VERIFYING] bar v0.0.1 ([CWD]/bar)
[COMPILING] bar v0.0.1 ([CWD]/[..])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[PACKAGED] [..] files, [..] ([..] compressed)
",
)
.run();
}

#[cargo_test]
fn workspace_overrides_resolver() {
let p = project()
Expand Down