From 9fe631246bd21f26addbbeb424d844103cc4608c Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Thu, 26 Jun 2025 21:30:19 +0200 Subject: [PATCH] tarball: Use `in_pkg_path` to simplify condition --- crates/crates_io_tarball/src/lib.rs | 34 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/crates/crates_io_tarball/src/lib.rs b/crates/crates_io_tarball/src/lib.rs index 1e822564828..43069670e5f 100644 --- a/crates/crates_io_tarball/src/lib.rs +++ b/crates/crates_io_tarball/src/lib.rs @@ -105,24 +105,22 @@ pub async fn process_tarball( // Let's go hunting for the VCS info and crate manifest. The only valid place for these is // in the package root in the tarball. - if entry_path.parent() == Some(pkg_root) { - let entry_file = entry_path.file_name().unwrap_or_default(); - if entry_file == ".cargo_vcs_info.json" { - let mut contents = String::new(); - entry.read_to_string(&mut contents).await?; - vcs_info = CargoVcsInfo::from_contents(&contents).ok(); - } else if entry_file.eq_ignore_ascii_case("cargo.toml") { - // Try to extract and read the Cargo.toml from the tarball, silently erroring if it - // cannot be read. - let owned_entry_path = entry_path.into_owned(); - let mut contents = String::new(); - entry.read_to_string(&mut contents).await?; - - let manifest = Manifest::from_str(&contents)?; - validate_manifest(&manifest)?; - - manifests.insert(owned_entry_path, manifest); - } + let in_pkg_path_str = in_pkg_path.to_string_lossy(); + if in_pkg_path_str == ".cargo_vcs_info.json" { + let mut contents = String::new(); + entry.read_to_string(&mut contents).await?; + vcs_info = CargoVcsInfo::from_contents(&contents).ok(); + } else if in_pkg_path_str.eq_ignore_ascii_case("cargo.toml") { + // Try to extract and read the Cargo.toml from the tarball, silently erroring if it + // cannot be read. + let owned_entry_path = entry_path.into_owned(); + let mut contents = String::new(); + entry.read_to_string(&mut contents).await?; + + let manifest = Manifest::from_str(&contents)?; + validate_manifest(&manifest)?; + + manifests.insert(owned_entry_path, manifest); } }