lib/unpacker: Add repo.timestamp to metadata

Related to: https://github.com/projectatomic/rpm-ostree/issues/774

We aren't yet trying to render this in any way on the client side, but let's
start capturing the timestamp data now so that we can make use of it later
in e.g. `rpm-ostree status -v`.

Closes: #1072
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-10-23 10:51:10 -04:00 committed by Atomic Bot
parent 63af4bbdda
commit cb9889204c
2 changed files with 16 additions and 4 deletions

View File

@ -413,8 +413,16 @@ get_lead_sig_header_as_bytes (RpmOstreeUnpacker *self,
return TRUE;
}
/* Generate per-package metadata; for now this is just the id of the repo
* where it originated, and the timestamp, which we can use for up-to-date
* checks. This is a bit like what the `yumdb` in /var/lib/yum
* does. See also
* https://github.com/rpm-software-management/libdnf/pull/199/
* https://github.com/projectatomic/rpm-ostree/issues/774
* https://github.com/projectatomic/rpm-ostree/pull/1072
*/
static GVariant *
repo_metadata_to_variant (DnfRepo *repo)
repo_metadata_for_package (DnfRepo *repo)
{
g_auto(GVariantBuilder) builder;
g_variant_builder_init (&builder, (GVariantType*)"a{sv}");
@ -424,6 +432,8 @@ repo_metadata_to_variant (DnfRepo *repo)
*/
g_variant_builder_add (&builder, "{sv}",
"id", g_variant_new_string (dnf_repo_get_id (repo)));
g_variant_builder_add (&builder, "{sv}",
"timestamp", g_variant_new_uint64 (dnf_repo_get_timestamp_generated (repo)));
return g_variant_builder_end (&builder);
}
@ -490,10 +500,10 @@ build_metadata_variant (RpmOstreeUnpacker *self,
g_variant_new_uint32 (1));
/* Originally we just had unpack_version = 1, let's add a minor version for
* compatible increments.
* compatible increments. Bumped 4 5 for timestamp.
*/
g_variant_builder_add (&metadata_builder, "{sv}", "rpmostree.unpack_minor_version",
g_variant_new_uint32 (4));
g_variant_new_uint32 (5));
if (self->pkg)
{
@ -501,7 +511,7 @@ build_metadata_variant (RpmOstreeUnpacker *self,
if (repo)
{
g_variant_builder_add (&metadata_builder, "{sv}", "rpmostree.repo",
repo_metadata_to_variant (repo));
repo_metadata_for_package (repo));
}
/* include a checksum of the RPM as a whole; the actual algo used depends

View File

@ -52,8 +52,10 @@ vm_build_rpm foo
vm_rpmostree pkg-add foo-1.0
vm_cmd ostree --repo=/sysroot/ostree/repo/extensions/rpmostree/pkgcache refs |grep /foo/> refs.txt
pkgref=$(head -1 refs.txt)
# Verify we have a mapping from pkg-in-ostree → rpmmd-repo info
vm_cmd ostree --repo=/sysroot/ostree/repo/extensions/rpmostree/pkgcache show --print-metadata-key rpmostree.repo ${pkgref} >refdata.txt
assert_file_has_content refdata.txt 'id.*test-repo'
assert_file_has_content refdata.txt 'timestamp'
rm -f refs.txt refdata.txt
# This will cover things like us failing to break hardlinks for the rpmdb,
# as well as rofiles-fuse