lockfile: Be robust to non-seconds-since-epoch repodata

We should really have safety comments around our use of `.unwrap()`.
This Google kubernetes rpm-md repo appears to use seconds-since-epoch.
We could try to detect that, probably best done in libdnf.

I think it'd be better to get them to match the informal schema
for this actually though instead.

For now let's just log an error and not crash.

Closes: https://github.com/coreos/rpm-ostree/issues/2600
This commit is contained in:
Colin Walters 2021-02-19 18:25:02 +00:00 committed by OpenShift Merge Robot
parent f882d6ddff
commit 49c55089d2

View File

@ -273,12 +273,21 @@ mod ffi {
let repo_ref = unsafe { &mut *rpmmd_repo };
let id = dnf_repo_get_id(repo_ref).unwrap();
let generated = dnf_repo_get_timestamp_generated(repo_ref).unwrap();
lockfile_repos.insert(
id,
LockfileRepoMetadata {
generated: Utc.timestamp(generated.try_into().unwrap(), 0),
},
);
let generated: i64 = match generated.try_into() {
Ok(t) => t,
Err(e) => {
eprintln!("Invalid rpm-md repo {} timestamp: {}: {}", id, generated, e);
0
}
};
let generated = match Utc.timestamp_opt(generated, 0) {
chrono::offset::LocalResult::Single(t) => t,
_ => {
eprintln!("Invalid rpm-md repo {} timestamp: {}", id, generated);
Utc.timestamp(0, 0)
}
};
lockfile_repos.insert(id, LockfileRepoMetadata { generated });
}
int_glib_error(