-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rust/lockfile: Add more metadata to generated lockfiles #1938
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ use std::collections::{HashMap, BTreeMap}; | |
use std::iter::Extend; | ||
use std::path::Path; | ||
use std::io; | ||
use chrono::prelude::*; | ||
use std::convert::TryInto; | ||
|
||
use crate::utils; | ||
|
||
|
@@ -49,6 +51,18 @@ fn lockfile_parse_multiple<P: AsRef<Path>>(filenames: &[P]) -> Fallible<Lockfile | |
/// | ||
/// ``` | ||
/// { | ||
/// "metatada": { | ||
/// "generated": "<rfc3339-timestamp>", | ||
/// "rpmmd_repos": { | ||
/// "repo1": { | ||
/// "generated": "<rfc3339-timestamp>" | ||
/// }, | ||
/// "repo2": { | ||
/// "generated": "<rfc3339-timestamp>" | ||
/// }, | ||
/// ... | ||
/// } | ||
/// } | ||
/// "packages": { | ||
/// "name1": { | ||
/// "evra": "EVRA1", | ||
|
@@ -70,6 +84,19 @@ fn lockfile_parse_multiple<P: AsRef<Path>>(filenames: &[P]) -> Fallible<Lockfile | |
#[serde(deny_unknown_fields)] | ||
struct LockfileConfig { | ||
packages: BTreeMap<String, LockedPackage>, | ||
metadata: Option<LockfileConfigMetadata>, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
#[serde(deny_unknown_fields)] | ||
struct LockfileConfigMetadata { | ||
generated: Option<DateTime<Utc>>, | ||
rpmmd_repos: Option<BTreeMap<String, LockfileRepoMetadata>>, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
struct LockfileRepoMetadata { | ||
generated: DateTime<Utc>, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
|
@@ -197,13 +224,25 @@ mod ffi { | |
pub extern "C" fn ror_lockfile_write( | ||
filename: *const libc::c_char, | ||
packages: *mut glib_sys::GPtrArray, | ||
rpmmd_repos: *mut glib_sys::GPtrArray, | ||
gerror: *mut *mut glib_sys::GError, | ||
) -> libc::c_int { | ||
let filename = ffi_view_os_str(filename); | ||
let packages: Vec<*mut DnfPackage> = ffi_ptr_array_to_vec(packages); | ||
let rpmmd_repos: Vec<*mut DnfRepo> = ffi_ptr_array_to_vec(rpmmd_repos); | ||
|
||
// get current time, but scrub nanoseconds; it's overkill to serialize that | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if we instead something like reference the last time the file changed in git? Dunno. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Heh yeah, that's in fact exactly what I initially did (see the commit message in coreos/fedora-coreos-releng-automation@c932c34). Though there were concerns that it was too magic/implicit. |
||
let now = { | ||
let t = Utc::now(); | ||
Utc::today().and_hms_nano(t.hour(), t.minute(), t.second(), 0) | ||
}; | ||
|
||
let mut lockfile = LockfileConfig { | ||
packages: BTreeMap::new(), | ||
metadata: Some(LockfileConfigMetadata { | ||
generated: Some(now), | ||
rpmmd_repos: Some(BTreeMap::new()), | ||
}) | ||
}; | ||
|
||
for pkg in packages { | ||
|
@@ -226,6 +265,17 @@ mod ffi { | |
unsafe { glib_sys::g_free(chksum as *mut libc::c_void) }; | ||
} | ||
|
||
/* just take the ref here to be less verbose */ | ||
let lockfile_repos = lockfile.metadata.as_mut().unwrap().rpmmd_repos.as_mut().unwrap(); | ||
|
||
for rpmmd_repo in rpmmd_repos { | ||
let id = ffi_new_string(unsafe { dnf_repo_get_id(rpmmd_repo) }); | ||
let generated = unsafe { dnf_repo_get_timestamp_generated(rpmmd_repo) }; | ||
lockfile_repos.insert(id, LockfileRepoMetadata { | ||
generated: Utc.timestamp(generated.try_into().unwrap(), 0), | ||
}); | ||
} | ||
|
||
int_glib_error(utils::write_file(filename, |w| { | ||
serde_json::to_writer_pretty(w, &lockfile).map_err(failure::Error::from) | ||
}), gerror) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1455,3 +1455,19 @@ rpmostree_get_rojig_branch_pkg (DnfPackage *pkg) | |
dnf_package_get_evr (pkg), | ||
dnf_package_get_arch (pkg)); | ||
} | ||
|
||
GPtrArray* | ||
rpmostree_get_enabled_rpmmd_repos (DnfContext *dnfctx, | ||
DnfRepoEnabled enablement) | ||
{ | ||
g_autoptr(GPtrArray) ret = g_ptr_array_new (); | ||
GPtrArray *repos = dnf_context_get_repos (dnfctx); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One side note...from the current libdnf source I'm not sure this order is stable. They are pulled unordered from We should probably do something more like "sort by cost, then name" or something in libdnf? (We want this to be stable or otherwise we'll be reordering things in the JSON) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At least as far as the JSON output, we use a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah right, OK. |
||
|
||
for (guint i = 0; i < repos->len; i++) | ||
{ | ||
DnfRepo *repo = repos->pdata[i]; | ||
if (dnf_repo_get_enabled (repo) & enablement) | ||
g_ptr_array_add (ret, repo); | ||
} | ||
return g_steal_pointer (&ret); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As soon as this lands in cosa, it will force everyone to upgrade rpm-ostree. I think that's OK. Just noting.