Skip to content

Commit

Permalink
core: Add rpmostree.repo metadata to imported packages
Browse files Browse the repository at this point in the history
I'm watching rpm-software-management/libdnf#199 and I
really don't like it. We already have a place to put out-of-rpmdb metadata,
which is in the ostree commit for imported packages. No need to involve a
relational database for this (and further, one that would need to learn about
multiple ostrees).

We're not yet *using* this information in the UI, but we could; imagine
changing the `status` `Packages:` to show packages-per-repo or so.  We
could also expose an `rpm-ostree pkg-info foo`.

But for now, let's just start recording this.

Closes: #610
Approved by: jlebon
  • Loading branch information
cgwalters authored and rh-atomic-bot committed Feb 8, 2017
1 parent 283b915 commit a52cb7d
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/app/rpmostree-internals-builtin-unpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ rpmostree_internals_builtin_unpack (int argc,
if (opt_ostree_convention)
flags |= RPMOSTREE_UNPACKER_FLAGS_OSTREE_CONVENTION;

unpacker = rpmostree_unpacker_new_at (AT_FDCWD, rpmpath, flags, error);
unpacker = rpmostree_unpacker_new_at (AT_FDCWD, rpmpath, NULL, flags, error);
if (!unpacker)
goto out;

Expand Down
2 changes: 1 addition & 1 deletion src/libpriv/rpmostree-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,7 @@ import_one_package (RpmOstreeContext *self,
flags |= RPMOSTREE_UNPACKER_FLAGS_UNPRIVILEGED;

/* TODO - tweak the unpacker flags for containers */
unpacker = rpmostree_unpacker_new_at (AT_FDCWD, pkg_path, flags, error);
unpacker = rpmostree_unpacker_new_at (AT_FDCWD, pkg_path, pkg, flags, error);
if (!unpacker)
goto out;

Expand Down
67 changes: 64 additions & 3 deletions src/libpriv/rpmostree-unpacker.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ struct RpmOstreeUnpacker
GHashTable *rpmfi_overrides;
GString *tmpfiles_d;
RpmOstreeUnpackerFlags flags;
DnfPackage *pkg;

char *ostree_branch;
};
Expand Down Expand Up @@ -265,8 +266,22 @@ build_rpmfi_overrides (RpmOstreeUnpacker *self)
}
}

/*
* rpmostree_unpacker_new_fd:
* @fd: Fd
* @pkg: (optional): Package reference, used for metadata
* @flags: flags
* @error: error
*
* Create a new unpacker instance. The @pkg argument, if
* specified, will be inspected and metadata such as the
* origin repo will be added to the final commit.
*/
RpmOstreeUnpacker *
rpmostree_unpacker_new_fd (int fd, RpmOstreeUnpackerFlags flags, GError **error)
rpmostree_unpacker_new_fd (int fd,
DnfPackage *pkg,
RpmOstreeUnpackerFlags flags,
GError **error)
{
RpmOstreeUnpacker *ret = NULL;
_cleanup_rpmheader_ Header hdr = NULL;
Expand All @@ -288,6 +303,7 @@ rpmostree_unpacker_new_fd (int fd, RpmOstreeUnpackerFlags flags, GError **error)
ret->flags = flags;
ret->hdr = g_steal_pointer (&hdr);
ret->cpio_offset = cpio_offset;
ret->pkg = pkg ? g_object_ref (pkg) : NULL;

build_rpmfi_overrides (ret);

Expand All @@ -299,8 +315,23 @@ rpmostree_unpacker_new_fd (int fd, RpmOstreeUnpackerFlags flags, GError **error)
return ret;
}

/*
* rpmostree_unpacker_new_at:
* @dfd: Fd
* @path: Path
* @pkg: (optional): Package reference, used for metadata
* @flags: flags
* @error: error
*
* Create a new unpacker instance. The @pkg argument, if
* specified, will be inspected and metadata such as the
* origin repo will be added to the final commit.
*/
RpmOstreeUnpacker *
rpmostree_unpacker_new_at (int dfd, const char *path, RpmOstreeUnpackerFlags flags, GError **error)
rpmostree_unpacker_new_at (int dfd, const char *path,
DnfPackage *pkg,
RpmOstreeUnpackerFlags flags,
GError **error)
{
RpmOstreeUnpacker *ret = NULL;
glnx_fd_close int fd = -1;
Expand All @@ -313,7 +344,7 @@ rpmostree_unpacker_new_at (int dfd, const char *path, RpmOstreeUnpackerFlags fla
goto out;
}

ret = rpmostree_unpacker_new_fd (fd, flags, error);
ret = rpmostree_unpacker_new_fd (fd, pkg, flags, error);
if (ret == NULL)
goto out;

Expand Down Expand Up @@ -404,6 +435,21 @@ get_lead_sig_header_as_bytes (RpmOstreeUnpacker *self,
return ret;
}

static GVariant *
repo_metadata_to_variant (DnfRepo *repo)
{
g_auto(GVariantBuilder) builder;
g_variant_builder_init (&builder, (GVariantType*)"a{sv}");

/* For now, just the id...in the future maybe we'll add more, but this is
* enough to provide useful semantics.
*/
g_variant_builder_add (&builder, "{sv}",
"id", g_variant_new_string (dnf_repo_get_id (repo)));

return g_variant_builder_end (&builder);
}

static gboolean
build_metadata_variant (RpmOstreeUnpacker *self,
OstreeSePolicy *sepolicy,
Expand Down Expand Up @@ -440,6 +486,21 @@ build_metadata_variant (RpmOstreeUnpacker *self,
/* let's be nice to our future selves just in case */
g_variant_builder_add (&metadata_builder, "{sv}", "rpmostree.unpack_version",
g_variant_new_uint32 (1));
/* Originally we just had unpack_version = 1, let's add a minor version for
* compatible increments.
*/
g_variant_builder_add (&metadata_builder, "{sv}", "rpmostree.unpack_minor_version",
g_variant_new_uint32 (1));

if (self->pkg)
{
DnfRepo *repo = dnf_package_get_repo (self->pkg);
if (repo)
{
g_variant_builder_add (&metadata_builder, "{sv}", "rpmostree.repo",
repo_metadata_to_variant (repo));
}
}

*out_variant = g_variant_builder_end (&metadata_builder);
return TRUE;
Expand Down
3 changes: 3 additions & 0 deletions src/libpriv/rpmostree-unpacker.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "libglnx.h"
#include <rpm/rpmlib.h>
#include <libdnf/libdnf.h>

typedef struct RpmOstreeUnpacker RpmOstreeUnpacker;

Expand All @@ -45,12 +46,14 @@ typedef enum {

RpmOstreeUnpacker*
rpmostree_unpacker_new_fd (int fd,
DnfPackage *pkg,
RpmOstreeUnpackerFlags flags,
GError **error);

RpmOstreeUnpacker*
rpmostree_unpacker_new_at (int dfd,
const char *path,
DnfPackage *pkg, /* for metadata */
RpmOstreeUnpackerFlags flags,
GError **error);

Expand Down
5 changes: 5 additions & 0 deletions tests/vmcheck/test-layering-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ if vm_cmd "runuser -u bin rpm-ostree pkg-add foo-1.0"; then
fi

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)
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'
rm -f refs.txt refdata.txt
echo "ok pkg-add foo"

vm_reboot
Expand Down

0 comments on commit a52cb7d

Please sign in to comment.