Skip to content
Merged
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
20 changes: 15 additions & 5 deletions src/crates_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,39 +196,39 @@ impl CratesCache {
bar.set_message(name.to_string());
}
}
if entry.path_bytes().ends_with(b"crate_owners.csv") {
if entry_path_ends_with(&entry, "crate_owners.csv") {
let owners: Vec<CrateOwner> = read_csv_data(entry)?;
cache_updater.store_multi_map(
&mut self.crate_owners,
Self::CRATE_OWNERS_FS,
owners.as_slice(),
&|owner| owner.crate_id,
)?;
} else if entry.path_bytes().ends_with(b"crates.csv") {
} else if entry_path_ends_with(&entry, "crates.csv") {
let crates: Vec<Crate> = read_csv_data(entry)?;
cache_updater.store_map(
&mut self.crates,
Self::CRATES_FS,
crates.as_slice(),
&|crate_| crate_.name.clone(),
)?;
} else if entry.path_bytes().ends_with(b"users.csv") {
} else if entry_path_ends_with(&entry, "users.csv") {
let users: Vec<User> = read_csv_data(entry)?;
cache_updater.store_map(
&mut self.users,
Self::USERS_FS,
users.as_slice(),
&|user| user.id,
)?;
} else if entry.path_bytes().ends_with(b"teams.csv") {
} else if entry_path_ends_with(&entry, "teams.csv") {
let teams: Vec<Team> = read_csv_data(entry)?;
cache_updater.store_map(
&mut self.teams,
Self::TEAMS_FS,
teams.as_slice(),
&|team| team.id,
)?;
} else if entry.path_bytes().ends_with(b"metadata.json") {
} else if entry_path_ends_with(&entry, "metadata.json") {
let meta: Metadata = serde_json::from_reader(entry)?;
cache_updater.store(
&mut self.metadata,
Expand Down Expand Up @@ -374,6 +374,16 @@ impl CratesCache {
}
}

fn entry_path_ends_with<R: io::Read>(entry: &tar::Entry<R>, needle: &str) -> bool {
let Ok(path) = entry.path() else {
return false;
};
let Some(file_name) = path.file_name() else {
return false;
};
file_name == needle
}

fn read_csv_data<T: serde::de::DeserializeOwned>(
from: impl io::Read,
) -> Result<Vec<T>, csv::Error> {
Expand Down
Loading