Skip to content

Commit bd853ad

Browse files
authored
Merge pull request #114 from smoelius/deleted-crates
Check entries' `path`s rather than `path_bytes`
2 parents 18db9ea + a2174cc commit bd853ad

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/crates_cache.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,39 +196,39 @@ impl CratesCache {
196196
bar.set_message(name.to_string());
197197
}
198198
}
199-
if entry.path_bytes().ends_with(b"crate_owners.csv") {
199+
if entry_path_ends_with(&entry, "crate_owners.csv") {
200200
let owners: Vec<CrateOwner> = read_csv_data(entry)?;
201201
cache_updater.store_multi_map(
202202
&mut self.crate_owners,
203203
Self::CRATE_OWNERS_FS,
204204
owners.as_slice(),
205205
&|owner| owner.crate_id,
206206
)?;
207-
} else if entry.path_bytes().ends_with(b"crates.csv") {
207+
} else if entry_path_ends_with(&entry, "crates.csv") {
208208
let crates: Vec<Crate> = read_csv_data(entry)?;
209209
cache_updater.store_map(
210210
&mut self.crates,
211211
Self::CRATES_FS,
212212
crates.as_slice(),
213213
&|crate_| crate_.name.clone(),
214214
)?;
215-
} else if entry.path_bytes().ends_with(b"users.csv") {
215+
} else if entry_path_ends_with(&entry, "users.csv") {
216216
let users: Vec<User> = read_csv_data(entry)?;
217217
cache_updater.store_map(
218218
&mut self.users,
219219
Self::USERS_FS,
220220
users.as_slice(),
221221
&|user| user.id,
222222
)?;
223-
} else if entry.path_bytes().ends_with(b"teams.csv") {
223+
} else if entry_path_ends_with(&entry, "teams.csv") {
224224
let teams: Vec<Team> = read_csv_data(entry)?;
225225
cache_updater.store_map(
226226
&mut self.teams,
227227
Self::TEAMS_FS,
228228
teams.as_slice(),
229229
&|team| team.id,
230230
)?;
231-
} else if entry.path_bytes().ends_with(b"metadata.json") {
231+
} else if entry_path_ends_with(&entry, "metadata.json") {
232232
let meta: Metadata = serde_json::from_reader(entry)?;
233233
cache_updater.store(
234234
&mut self.metadata,
@@ -374,6 +374,16 @@ impl CratesCache {
374374
}
375375
}
376376

377+
fn entry_path_ends_with<R: io::Read>(entry: &tar::Entry<R>, needle: &str) -> bool {
378+
let Ok(path) = entry.path() else {
379+
return false;
380+
};
381+
let Some(file_name) = path.file_name() else {
382+
return false;
383+
};
384+
file_name == needle
385+
}
386+
377387
fn read_csv_data<T: serde::de::DeserializeOwned>(
378388
from: impl io::Read,
379389
) -> Result<Vec<T>, csv::Error> {

0 commit comments

Comments
 (0)