From 88823182de32503277fe50fbeade49f8665f3a76 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Thu, 6 Jun 2024 16:45:11 +0200 Subject: [PATCH] crates_io_tarball: Ignore duplicate readme files cargo is currently producing crate files with multiple readme files under certain conditions. While this is a bug on cargo side, we should probably be liberal in this case and still accept the crate files. --- crates/crates_io_tarball/src/lib.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/crates_io_tarball/src/lib.rs b/crates/crates_io_tarball/src/lib.rs index d89426536ba..59d29d6543d 100644 --- a/crates/crates_io_tarball/src/lib.rs +++ b/crates/crates_io_tarball/src/lib.rs @@ -96,9 +96,11 @@ pub fn process_tarball( let lowercase_path = entry_path.as_os_str().to_ascii_lowercase(); if !paths.insert(lowercase_path) { - return Err(TarballError::DuplicatePath( - entry_path.display().to_string(), - )); + let path = entry_path.display().to_string(); + // see https://github.com/rust-lang/crates.io/pull/8788#issuecomment-2151695951 + if !path.to_ascii_lowercase().ends_with("/readme.md") { + return Err(TarballError::DuplicatePath(path)); + } } // Let's go hunting for the VCS info and crate manifest. The only valid place for these is @@ -334,4 +336,15 @@ mod tests { let err = assert_err!(process_tarball("foo-0.0.1", &*tarball, MAX_SIZE)); assert_snapshot!(err, @"duplicate path found: foo-0.0.1/FOO.rs") } + + #[test] + fn test_double_readme() { + let tarball = TarballBuilder::new() + .add_file("foo-0.0.1/Cargo.toml", MANIFEST) + .add_file("foo-0.0.1/Readme.md", b"") + .add_file("foo-0.0.1/README.md", b"") + .build(); + + assert_ok!(process_tarball("foo-0.0.1", &*tarball, MAX_SIZE)); + } }