libpriv: Rename "unpacker" to "importer", split off "unpacker-core"

In the jigdo path we don't actually want to import the OIRPM literally
into ostree.  I considered adding jigdo logic into `rpmostree-unpacker.c`
but it'd be a mess as the functionality is quite logically separate
from importing.

So split off an `unpacker-core.c` file which has the bare libarchive+RPM
helpers, and rename `RpmOstreeUnpacker` to `RpmOstreeImporter`.

Closes: #1110
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-11-17 16:57:05 -05:00 committed by Atomic Bot
parent 3c0da8864b
commit 366826132a
11 changed files with 245 additions and 174 deletions

View File

@ -43,8 +43,10 @@ librpmostreepriv_la_SOURCES = \
src/libpriv/rpmostree-cleanup.h \
src/libpriv/rpmostree-rpm-util.c \
src/libpriv/rpmostree-rpm-util.h \
src/libpriv/rpmostree-unpacker.c \
src/libpriv/rpmostree-unpacker.h \
src/libpriv/rpmostree-importer.c \
src/libpriv/rpmostree-importer.h \
src/libpriv/rpmostree-unpacker-core.c \
src/libpriv/rpmostree-unpacker-core.h \
src/libpriv/rpmostree-output.c \
src/libpriv/rpmostree-output.h \
src/libpriv/rpmostree-kargs-process.c \

View File

@ -34,7 +34,6 @@
#include "rpmostree-libbuiltin.h"
#include "rpmostree-postprocess.h"
#include "rpmostree-rpm-util.h"
#include "rpmostree-unpacker.h"
#include "libglnx.h"

View File

@ -34,7 +34,7 @@
#include "rpmostree-core.h"
#include "rpmostree-libbuiltin.h"
#include "rpmostree-rpm-util.h"
#include "rpmostree-unpacker.h"
#include "rpmostree-importer.h"
#include "rpmostree-postprocess.h"
#include "libglnx.h"
@ -56,8 +56,8 @@ rpmostree_ex_builtin_unpack (int argc,
{
int exit_status = EXIT_FAILURE;
g_autoptr(GOptionContext) context = g_option_context_new ("REPO RPM");
RpmOstreeUnpackerFlags flags = 0;
glnx_unref_object RpmOstreeUnpacker *unpacker = NULL;
RpmOstreeImporterFlags flags = 0;
glnx_unref_object RpmOstreeImporter *unpacker = NULL;
const char *target;
const char *rpmpath;
glnx_unref_object OstreeRepo *ostree_repo = NULL;
@ -85,7 +85,7 @@ rpmostree_ex_builtin_unpack (int argc,
if (!ostree_repo)
goto out;
unpacker = rpmostree_unpacker_new_at (AT_FDCWD, rpmpath, NULL, flags, error);
unpacker = rpmostree_importer_new_at (AT_FDCWD, rpmpath, NULL, flags, error);
if (!unpacker)
goto out;
@ -101,10 +101,10 @@ rpmostree_ex_builtin_unpack (int argc,
}
{
const char *branch = rpmostree_unpacker_get_ostree_branch (unpacker);
const char *branch = rpmostree_importer_get_ostree_branch (unpacker);
g_autofree char *checksum = NULL;
if (!rpmostree_unpacker_unpack_to_ostree (unpacker, ostree_repo, sepolicy,
if (!rpmostree_importer_run (unpacker, ostree_repo, sepolicy,
&checksum, cancellable, error))
goto out;

View File

@ -33,7 +33,6 @@
#include "rpmostree-postprocess.h"
#include "rpmostree-output.h"
#include "rpmostree-scripts.h"
#include "rpmostree-unpacker.h"
#include "ostree-repo.h"

View File

@ -31,7 +31,7 @@
#include "rpmostree-util.h"
#include "rpmostree-output.h"
#include "rpmostree-core.h"
#include "rpmostree-unpacker.h"
#include "rpmostree-importer.h"
#include "rpmostreed-utils.h"
#include "rpmostree-kargs-process.h"
@ -494,16 +494,16 @@ import_local_rpm (OstreeRepo *parent,
if (policy == NULL)
return FALSE;
g_autoptr(RpmOstreeUnpacker) unpacker = rpmostree_unpacker_new_fd (fd, NULL, 0, error);
g_autoptr(RpmOstreeImporter) unpacker = rpmostree_importer_new_fd (fd, NULL, 0, error);
if (unpacker == NULL)
return FALSE;
if (!rpmostree_unpacker_unpack_to_ostree (unpacker, pkgcache_repo, policy,
if (!rpmostree_importer_run (unpacker, pkgcache_repo, policy,
NULL, cancellable, error))
return FALSE;
g_autofree char *nevra = rpmostree_unpacker_get_nevra (unpacker);
*sha256_nevra = g_strconcat (rpmostree_unpacker_get_header_sha256 (unpacker),
g_autofree char *nevra = rpmostree_importer_get_nevra (unpacker);
*sha256_nevra = g_strconcat (rpmostree_importer_get_header_sha256 (unpacker),
":", nevra, NULL);
return TRUE;

View File

@ -37,7 +37,7 @@
#include "rpmostree-rpm-util.h"
#include "rpmostree-passwd-util.h"
#include "rpmostree-scripts.h"
#include "rpmostree-unpacker.h"
#include "rpmostree-importer.h"
#include "rpmostree-output.h"
#define RPMOSTREE_MESSAGE_COMMIT_STATS SD_ID128_MAKE(e6,37,2e,38,41,21,42,a9,bc,13,b6,32,b3,f8,93,44)
@ -1997,16 +1997,16 @@ import_one_package (RpmOstreeContext *self,
int flags = 0;
if (g_str_equal (pkg_name, "filesystem") ||
g_str_equal (pkg_name, "rootfiles"))
flags |= RPMOSTREE_UNPACKER_FLAGS_SKIP_EXTRANEOUS;
flags |= RPMOSTREE_IMPORTER_FLAGS_SKIP_EXTRANEOUS;
{ gboolean docs;
g_assert (g_variant_dict_lookup (self->spec->dict, "documentation", "b", &docs));
if (!docs)
flags |= RPMOSTREE_UNPACKER_FLAGS_NODOCS;
flags |= RPMOSTREE_IMPORTER_FLAGS_NODOCS;
}
/* TODO - tweak the unpacker flags for containers */
g_autoptr(RpmOstreeUnpacker) unpacker = rpmostree_unpacker_new_at (AT_FDCWD, pkg_path, pkg, flags, error);
g_autoptr(RpmOstreeImporter) unpacker = rpmostree_importer_new_at (AT_FDCWD, pkg_path, pkg, flags, error);
if (!unpacker)
return FALSE;
@ -2023,7 +2023,7 @@ import_one_package (RpmOstreeContext *self,
OstreeRepo *ostreerepo = get_pkgcache_repo (self);
g_autofree char *ostree_commit = NULL;
if (!rpmostree_unpacker_unpack_to_ostree (unpacker, ostreerepo, sepolicy,
if (!rpmostree_importer_run (unpacker, ostreerepo, sepolicy,
&ostree_commit, cancellable, error))
return glnx_prefix_error (error, "Unpacking %s",
dnf_package_get_nevra (pkg));
@ -2592,7 +2592,7 @@ get_package_metainfo (RpmOstreeContext *self,
if (!glnx_openat_rdonly (self->tmpdir.fd, path, TRUE, &metadata_fd, error))
return FALSE;
return rpmostree_unpacker_read_metainfo (metadata_fd, out_header, NULL,
return rpmostree_importer_read_metainfo (metadata_fd, out_header, NULL,
out_fi, error);
}

View File

@ -32,7 +32,8 @@
#include <pwd.h>
#include <grp.h>
#include <gio/gunixinputstream.h>
#include "rpmostree-unpacker.h"
#include "rpmostree-unpacker-core.h"
#include "rpmostree-importer.h"
#include "rpmostree-core.h"
#include "rpmostree-rpm-util.h"
#include <rpm/rpmlib.h>
@ -46,9 +47,9 @@
#include <string.h>
#include <stdlib.h>
typedef GObjectClass RpmOstreeUnpackerClass;
typedef GObjectClass RpmOstreeImporterClass;
struct RpmOstreeUnpacker
struct RpmOstreeImporter
{
GObject parent_instance;
struct archive *archive;
@ -60,7 +61,7 @@ struct RpmOstreeUnpacker
GHashTable *rpmfi_overrides;
GHashTable *doc_files;
GString *tmpfiles_d;
RpmOstreeUnpackerFlags flags;
RpmOstreeImporterFlags flags;
gboolean unpacking_as_nonroot;
DnfPackage *pkg;
char *hdr_sha256;
@ -68,20 +69,12 @@ struct RpmOstreeUnpacker
char *ostree_branch;
};
G_DEFINE_TYPE(RpmOstreeUnpacker, rpmostree_unpacker, G_TYPE_OBJECT)
G_DEFINE_TYPE(RpmOstreeImporter, rpmostree_importer, G_TYPE_OBJECT)
static void
propagate_libarchive_error (GError **error,
struct archive *a)
rpmostree_importer_finalize (GObject *object)
{
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
archive_error_string (a));
}
static void
rpmostree_unpacker_finalize (GObject *object)
{
RpmOstreeUnpacker *self = (RpmOstreeUnpacker*)object;
RpmOstreeImporter *self = (RpmOstreeImporter*)object;
if (self->hdr)
headerFree (self->hdr);
if (self->archive)
@ -98,85 +91,27 @@ rpmostree_unpacker_finalize (GObject *object)
g_free (self->hdr_sha256);
G_OBJECT_CLASS (rpmostree_unpacker_parent_class)->finalize (object);
G_OBJECT_CLASS (rpmostree_importer_parent_class)->finalize (object);
}
static void
rpmostree_unpacker_class_init (RpmOstreeUnpackerClass *klass)
rpmostree_importer_class_init (RpmOstreeImporterClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = rpmostree_unpacker_finalize;
gobject_class->finalize = rpmostree_importer_finalize;
}
static void
rpmostree_unpacker_init (RpmOstreeUnpacker *self)
rpmostree_importer_init (RpmOstreeImporter *self)
{
self->rpmfi_overrides = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, NULL);
self->tmpfiles_d = g_string_new ("");
}
typedef int(*archive_setup_func)(struct archive *);
/**
* rpmostree_rpm2cpio:
* @fd: An open file descriptor for an RPM package
* @error: GError
*
* Parse CPIO content of @fd via libarchive. Note that the CPIO data
* does not capture all relevant filesystem content; for example,
* filesystem capabilities are part of a separate header, etc.
*/
static struct archive *
rpm2cpio (int fd, GError **error)
{
gboolean success = FALSE;
struct archive *ret = NULL;
guint i;
ret = archive_read_new ();
g_assert (ret);
/* We only do the subset necessary for RPM */
{ archive_setup_func archive_setup_funcs[] =
{ archive_read_support_filter_rpm,
archive_read_support_filter_lzma,
archive_read_support_filter_gzip,
archive_read_support_filter_xz,
archive_read_support_filter_bzip2,
archive_read_support_format_cpio };
for (i = 0; i < G_N_ELEMENTS (archive_setup_funcs); i++)
{
if (archive_setup_funcs[i](ret) != ARCHIVE_OK)
{
propagate_libarchive_error (error, ret);
goto out;
}
}
}
if (archive_read_open_fd (ret, fd, 10240) != ARCHIVE_OK)
{
propagate_libarchive_error (error, ret);
goto out;
}
success = TRUE;
out:
if (success)
return g_steal_pointer (&ret);
else
{
if (ret)
(void) archive_read_free (ret);
return NULL;
}
}
gboolean
rpmostree_unpacker_read_metainfo (int fd,
rpmostree_importer_read_metainfo (int fd,
Header *out_header,
gsize *out_cpio_offset,
rpmfi *out_fi,
@ -246,7 +181,7 @@ rpmostree_unpacker_read_metainfo (int fd,
}
static void
build_rpmfi_overrides (RpmOstreeUnpacker *self)
build_rpmfi_overrides (RpmOstreeImporter *self)
{
int i;
@ -281,7 +216,7 @@ build_rpmfi_overrides (RpmOstreeUnpacker *self)
}
/*
* rpmostree_unpacker_new_fd:
* rpmostree_importer_new_fd:
* @fd: Fd
* @pkg: (optional): Package reference, used for metadata
* @flags: flags
@ -291,26 +226,26 @@ build_rpmfi_overrides (RpmOstreeUnpacker *self)
* 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,
RpmOstreeImporter *
rpmostree_importer_new_fd (int fd,
DnfPackage *pkg,
RpmOstreeUnpackerFlags flags,
RpmOstreeImporterFlags flags,
GError **error)
{
RpmOstreeUnpacker *ret = NULL;
RpmOstreeImporter *ret = NULL;
g_auto(Header) hdr = NULL;
rpmfi fi = NULL;
struct archive *archive;
gsize cpio_offset;
archive = rpm2cpio (fd, error);
archive = rpmostree_unpack_rpm2cpio (fd, error);
if (archive == NULL)
goto out;
if (!rpmostree_unpacker_read_metainfo (fd, &hdr, &cpio_offset, &fi, error))
if (!rpmostree_importer_read_metainfo (fd, &hdr, &cpio_offset, &fi, error))
goto out;
ret = g_object_new (RPMOSTREE_TYPE_UNPACKER, NULL);
ret = g_object_new (RPMOSTREE_TYPE_IMPORTER, NULL);
ret->fd = fd;
ret->fi = g_steal_pointer (&fi);
ret->archive = g_steal_pointer (&archive);
@ -320,7 +255,7 @@ rpmostree_unpacker_new_fd (int fd,
ret->cpio_offset = cpio_offset;
ret->pkg = pkg ? g_object_ref (pkg) : NULL;
if (flags & RPMOSTREE_UNPACKER_FLAGS_NODOCS)
if (flags & RPMOSTREE_IMPORTER_FLAGS_NODOCS)
ret->doc_files = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, NULL);
build_rpmfi_overrides (ret);
@ -334,7 +269,7 @@ rpmostree_unpacker_new_fd (int fd,
}
/*
* rpmostree_unpacker_new_at:
* rpmostree_importer_new_at:
* @dfd: Fd
* @path: Path
* @pkg: (optional): Package reference, used for metadata
@ -345,17 +280,17 @@ rpmostree_unpacker_new_fd (int fd,
* 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,
RpmOstreeImporter *
rpmostree_importer_new_at (int dfd, const char *path,
DnfPackage *pkg,
RpmOstreeUnpackerFlags flags,
RpmOstreeImporterFlags flags,
GError **error)
{
glnx_autofd int fd = -1;
if (!glnx_openat_rdonly (dfd, path, TRUE, &fd, error))
return FALSE;
RpmOstreeUnpacker *ret = rpmostree_unpacker_new_fd (fd, pkg, flags, error);
RpmOstreeImporter *ret = rpmostree_importer_new_fd (fd, pkg, flags, error);
if (ret == NULL)
return NULL;
@ -366,7 +301,7 @@ rpmostree_unpacker_new_at (int dfd, const char *path,
}
static void
get_rpmfi_override (RpmOstreeUnpacker *self,
get_rpmfi_override (RpmOstreeImporter *self,
const char *path,
const char **out_user,
const char **out_group,
@ -390,7 +325,7 @@ get_rpmfi_override (RpmOstreeUnpacker *self,
}
const char *
rpmostree_unpacker_get_ostree_branch (RpmOstreeUnpacker *self)
rpmostree_importer_get_ostree_branch (RpmOstreeImporter *self)
{
if (!self->ostree_branch)
self->ostree_branch = rpmostree_get_cache_branch_header (self->hdr);
@ -399,7 +334,7 @@ rpmostree_unpacker_get_ostree_branch (RpmOstreeUnpacker *self)
}
static gboolean
get_lead_sig_header_as_bytes (RpmOstreeUnpacker *self,
get_lead_sig_header_as_bytes (RpmOstreeImporter *self,
GBytes **out_metadata,
GCancellable *cancellable,
GError **error)
@ -454,7 +389,7 @@ repo_metadata_for_package (DnfRepo *repo)
}
static gboolean
build_metadata_variant (RpmOstreeUnpacker *self,
build_metadata_variant (RpmOstreeImporter *self,
OstreeSePolicy *sepolicy,
GVariant **out_variant,
GCancellable *cancellable,
@ -493,7 +428,7 @@ build_metadata_variant (RpmOstreeUnpacker *self,
/* include basic NEVRA information so we don't have to write out and read back the header
* just to get e.g. the pkgname */
g_autofree char *nevra = rpmostree_unpacker_get_nevra (self);
g_autofree char *nevra = rpmostree_importer_get_nevra (self);
g_variant_builder_add (&metadata_builder, "{sv}", "rpmostree.nevra",
g_variant_new ("(sstsss)", nevra,
headerGetString (self->hdr, RPMTAG_NAME),
@ -553,7 +488,7 @@ build_metadata_variant (RpmOstreeUnpacker *self,
typedef struct
{
RpmOstreeUnpacker *self;
RpmOstreeImporter *self;
GError **error;
} cb_data;
@ -572,7 +507,7 @@ ensure_directories_user_writable (GFileInfo *file_info)
}
static void
append_tmpfiles_d (RpmOstreeUnpacker *self,
append_tmpfiles_d (RpmOstreeImporter *self,
const char *path,
GFileInfo *finfo,
const char *user,
@ -646,7 +581,7 @@ compose_filter_cb (OstreeRepo *repo,
GFileInfo *file_info,
gpointer user_data)
{
RpmOstreeUnpacker *self = ((cb_data*)user_data)->self;
RpmOstreeImporter *self = ((cb_data*)user_data)->self;
GError **error = ((cb_data*)user_data)->error;
const char *user = NULL;
@ -703,7 +638,7 @@ compose_filter_cb (OstreeRepo *repo,
/* And ensure the RPM installs into supported paths */
if (!path_is_ostree_compliant (path))
{
if ((self->flags & RPMOSTREE_UNPACKER_FLAGS_SKIP_EXTRANEOUS) == 0)
if ((self->flags & RPMOSTREE_IMPORTER_FLAGS_SKIP_EXTRANEOUS) == 0)
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Unsupported path: %s; See %s",
path, "https://github.com/projectatomic/rpm-ostree/issues/233");
@ -722,7 +657,7 @@ unprivileged_filter_cb (OstreeRepo *repo,
GFileInfo *file_info,
gpointer user_data)
{
RpmOstreeUnpacker *self = ((cb_data*)user_data)->self;
RpmOstreeImporter *self = ((cb_data*)user_data)->self;
/* Are we filtering out docs? Let's check that first */
if (self->doc_files && g_hash_table_contains (self->doc_files, path))
return OSTREE_REPO_COMMIT_FILTER_SKIP;
@ -751,7 +686,7 @@ xattr_cb (OstreeRepo *repo,
GFileInfo *file_info,
gpointer user_data)
{
RpmOstreeUnpacker *self = user_data;
RpmOstreeImporter *self = user_data;
const char *fcaps = NULL;
get_rpmfi_override (self, path, NULL, NULL, &fcaps);
@ -786,7 +721,7 @@ handle_translate_pathname (OstreeRepo *repo,
}
static gboolean
import_rpm_to_repo (RpmOstreeUnpacker *self,
import_rpm_to_repo (RpmOstreeImporter *self,
OstreeRepo *repo,
OstreeSePolicy *sepolicy,
char **out_csum,
@ -891,7 +826,7 @@ import_rpm_to_repo (RpmOstreeUnpacker *self,
}
gboolean
rpmostree_unpacker_unpack_to_ostree (RpmOstreeUnpacker *self,
rpmostree_importer_run (RpmOstreeImporter *self,
OstreeRepo *repo,
OstreeSePolicy *sepolicy,
char **out_csum,
@ -907,7 +842,7 @@ rpmostree_unpacker_unpack_to_ostree (RpmOstreeUnpacker *self,
if (!import_rpm_to_repo (self, repo, sepolicy, &csum, cancellable, error))
return FALSE;
const char *branch = rpmostree_unpacker_get_ostree_branch (self);
const char *branch = rpmostree_importer_get_ostree_branch (self);
ostree_repo_transaction_set_ref (repo, NULL, branch, csum);
if (!ostree_repo_commit_transaction (repo, NULL, cancellable, error))
@ -919,7 +854,7 @@ rpmostree_unpacker_unpack_to_ostree (RpmOstreeUnpacker *self,
}
char *
rpmostree_unpacker_get_nevra (RpmOstreeUnpacker *self)
rpmostree_importer_get_nevra (RpmOstreeImporter *self)
{
if (self->hdr == NULL)
return NULL;
@ -930,7 +865,7 @@ rpmostree_unpacker_get_nevra (RpmOstreeUnpacker *self)
}
const char *
rpmostree_unpacker_get_header_sha256 (RpmOstreeUnpacker *self)
rpmostree_importer_get_header_sha256 (RpmOstreeImporter *self)
{
return self->hdr_sha256;
}

View File

@ -26,51 +26,51 @@
#include <rpm/rpmlib.h>
#include <libdnf/libdnf.h>
typedef struct RpmOstreeUnpacker RpmOstreeUnpacker;
typedef struct RpmOstreeImporter RpmOstreeImporter;
#define RPMOSTREE_TYPE_UNPACKER (rpmostree_unpacker_get_type ())
#define RPMOSTREE_UNPACKER(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), RPMOSTREE_TYPE_UNPACKER, RpmOstreeUnpacker))
#define RPMOSTREE_IS_UNPACKER(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), RPMOSTREE_TYPE_UNPACKER))
#define RPMOSTREE_TYPE_IMPORTER (rpmostree_importer_get_type ())
#define RPMOSTREE_IMPORTER(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), RPMOSTREE_TYPE_IMPORTER, RpmOstreeImporter))
#define RPMOSTREE_IS_IMPORTER(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), RPMOSTREE_TYPE_IMPORTER))
GType rpmostree_unpacker_get_type (void);
GType rpmostree_importer_get_type (void);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (RpmOstreeUnpacker, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (RpmOstreeImporter, g_object_unref)
/**
* RpmOstreeUnpackerFlags:
* @RPMOSTREE_UNPACKER_FLAGS_SKIP_EXTRANEOUS: Skip files/directories outside of supported ostree-compliant paths rather than erroring out
* @RPMOSTREE_UNPACKER_FLAGS_NODOCS: Skip documentation files
* RpmOstreeImporterFlags:
* @RPMOSTREE_IMPORTER_FLAGS_SKIP_EXTRANEOUS: Skip files/directories outside of supported ostree-compliant paths rather than erroring out
* @RPMOSTREE_IMPORTER_FLAGS_NODOCS: Skip documentation files
*/
typedef enum {
RPMOSTREE_UNPACKER_FLAGS_SKIP_EXTRANEOUS = (1 << 0),
RPMOSTREE_UNPACKER_FLAGS_NODOCS = (1 << 1),
} RpmOstreeUnpackerFlags;
RPMOSTREE_IMPORTER_FLAGS_SKIP_EXTRANEOUS = (1 << 0),
RPMOSTREE_IMPORTER_FLAGS_NODOCS = (1 << 1),
} RpmOstreeImporterFlags;
RpmOstreeUnpacker*
rpmostree_unpacker_new_fd (int fd,
RpmOstreeImporter*
rpmostree_importer_new_fd (int fd,
DnfPackage *pkg,
RpmOstreeUnpackerFlags flags,
RpmOstreeImporterFlags flags,
GError **error);
RpmOstreeUnpacker*
rpmostree_unpacker_new_at (int dfd,
RpmOstreeImporter*
rpmostree_importer_new_at (int dfd,
const char *path,
DnfPackage *pkg, /* for metadata */
RpmOstreeUnpackerFlags flags,
RpmOstreeImporterFlags flags,
GError **error);
gboolean
rpmostree_unpacker_read_metainfo (int fd,
rpmostree_importer_read_metainfo (int fd,
Header *out_header,
gsize *out_cpio_offset,
rpmfi *out_fi,
GError **error);
const char*
rpmostree_unpacker_get_ostree_branch (RpmOstreeUnpacker *unpacker);
rpmostree_importer_get_ostree_branch (RpmOstreeImporter *unpacker);
gboolean
rpmostree_unpacker_unpack_to_ostree (RpmOstreeUnpacker *unpacker,
rpmostree_importer_run (RpmOstreeImporter *unpacker,
OstreeRepo *repo,
OstreeSePolicy *sepolicy,
char **out_commit,
@ -78,7 +78,7 @@ rpmostree_unpacker_unpack_to_ostree (RpmOstreeUnpacker *unpacker,
GError **error);
char *
rpmostree_unpacker_get_nevra (RpmOstreeUnpacker *self);
rpmostree_importer_get_nevra (RpmOstreeImporter *self);
const char *
rpmostree_unpacker_get_header_sha256 (RpmOstreeUnpacker *self);
rpmostree_importer_get_header_sha256 (RpmOstreeImporter *self);

View File

@ -0,0 +1,105 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 2015 Red Hat, Inc.
*
* Licensed under the GNU Lesser General Public License Version 2.1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* Core routines wrapping libarchive unpacking of an RPM.
*/
#include "config.h"
#include <pwd.h>
#include <grp.h>
#include <gio/gunixinputstream.h>
#include "rpmostree-unpacker-core.h"
#include "rpmostree-core.h"
#include "rpmostree-rpm-util.h"
#include <rpm/rpmlib.h>
#include <rpm/rpmlog.h>
#include <rpm/rpmfi.h>
#include <rpm/rpmts.h>
#include <string.h>
#include <stdlib.h>
static void
propagate_libarchive_error (GError **error,
struct archive *a)
{
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
archive_error_string (a));
}
typedef int(*archive_setup_func)(struct archive *);
/**
* rpmostree_unpack_rpm2cpio:
* @fd: An open file descriptor for an RPM package
* @error: GError
*
* Parse CPIO content of @fd via libarchive. Note that the CPIO data
* does not capture all relevant filesystem content; for example,
* filesystem capabilities are part of a separate header, etc.
*/
struct archive *
rpmostree_unpack_rpm2cpio (int fd, GError **error)
{
gboolean success = FALSE;
struct archive *ret = NULL;
guint i;
ret = archive_read_new ();
g_assert (ret);
/* We only do the subset necessary for RPM */
{ archive_setup_func archive_setup_funcs[] =
{ archive_read_support_filter_rpm,
archive_read_support_filter_lzma,
archive_read_support_filter_gzip,
archive_read_support_filter_xz,
archive_read_support_filter_bzip2,
archive_read_support_format_cpio };
for (i = 0; i < G_N_ELEMENTS (archive_setup_funcs); i++)
{
if (archive_setup_funcs[i](ret) != ARCHIVE_OK)
{
propagate_libarchive_error (error, ret);
goto out;
}
}
}
if (archive_read_open_fd (ret, fd, 10240) != ARCHIVE_OK)
{
propagate_libarchive_error (error, ret);
goto out;
}
success = TRUE;
out:
if (success)
return g_steal_pointer (&ret);
else
{
if (ret)
(void) archive_read_free (ret);
return NULL;
}
}

View File

@ -0,0 +1,31 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 2015 Colin Walters <walters@verbum.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2 of the licence or (at
* your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*/
#pragma once
#include <ostree.h>
#include "libglnx.h"
#include <rpm/rpmlib.h>
#include <libdnf/libdnf.h>
#include <archive.h>
#include <archive_entry.h>
struct archive * rpmostree_unpack_rpm2cpio (int fd, GError **error);

View File

@ -8,7 +8,7 @@
#include "libglnx.h"
#include "rpmostree-util.h"
#include "rpmostree-core.h"
#include "rpmostree-unpacker.h"
#include "rpmostree-importer.h"
#include "libtest.h"
static void
@ -135,13 +135,13 @@ test_variant_to_nevra(void)
g_assert_no_error (error);
g_assert (ret);
g_autoptr(RpmOstreeUnpacker) unpacker = NULL;
g_autoptr(RpmOstreeImporter) importer = NULL;
g_autofree char *foo_rpm = g_strdup_printf ("yumrepo/packages/%s/%s.rpm", arch, nevra);
unpacker = rpmostree_unpacker_new_at (AT_FDCWD, foo_rpm, NULL, 0, &error);
importer = rpmostree_importer_new_at (AT_FDCWD, foo_rpm, NULL, 0, &error);
g_assert_no_error (error);
g_assert (unpacker);
g_assert (importer);
ret = rpmostree_unpacker_unpack_to_ostree (unpacker, repo, NULL, NULL, NULL, &error);
ret = rpmostree_importer_run (importer, repo, NULL, NULL, NULL, &error);
g_assert_no_error (error);
g_assert (ret);
@ -176,7 +176,7 @@ main (int argc,
g_test_add_func ("/utils/varsubst", test_varsubst_string);
g_test_add_func ("/utils/cachebranch_to_nevra", test_cache_branch_to_nevra);
g_test_add_func ("/unpacker/variant_to_nevra", test_variant_to_nevra);
g_test_add_func ("/importer/variant_to_nevra", test_variant_to_nevra);
return g_test_run ();
}