From 802cace05f918cd44d38215841fdec6b931d0fb7 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 29 Jan 2014 14:37:44 -0500 Subject: [PATCH] Unify rpm-ostree into one binary And start making an internal library. --- Makefile-rpm-ostree.am | 9 +- src/rpm-ostree.c | 30 +++--- ...s-and-commit.c => rpmostree-postprocess.c} | 100 ++++-------------- src/rpmostree-postprocess.h | 31 ++++++ 4 files changed, 71 insertions(+), 99 deletions(-) rename src/{rpm-ostree-postprocess-and-commit.c => rpmostree-postprocess.c} (89%) create mode 100644 src/rpmostree-postprocess.h diff --git a/Makefile-rpm-ostree.am b/Makefile-rpm-ostree.am index 43b2c307..815b3535 100644 --- a/Makefile-rpm-ostree.am +++ b/Makefile-rpm-ostree.am @@ -17,10 +17,13 @@ privlib_SCRIPTS = src/rpmqa-sorted src/repoquery-sorted -bin_PROGRAMS += rpm-ostree rpm-ostree-postprocess-and-commit +bin_PROGRAMS += rpm-ostree -rpm_ostree_SOURCES = src/rpm-ostree.c -rpm_ostree_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/libgsystem -DPKGLIBDIR=\"$(pkglibdir)\" $(PKGDEP_OSTREE_CFLAGS) +rpm_ostree_SOURCES = src/rpm-ostree.c \ + src/rpmostree-postprocess.h \ + src/rpmostree-postprocess.c \ + $(NULL) +rpm_ostree_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/libgsystem -I$(srcdir)/src -DPKGLIBDIR=\"$(pkglibdir)\" $(PKGDEP_OSTREE_CFLAGS) rpm_ostree_LDADD = $(AM_LDFLAGS) $(PKGDEP_OSTREE_LIBS) libgsystem.la rpm_ostree_postprocess_and_commit_SOURCES = src/rpm-ostree-postprocess-and-commit.c diff --git a/src/rpm-ostree.c b/src/rpm-ostree.c index 55551ce2..c661fa79 100644 --- a/src/rpm-ostree.c +++ b/src/rpm-ostree.c @@ -23,7 +23,8 @@ #include #include -#include +#include "rpmostree-postprocess.h" + #include "libgsystem.h" static char **opt_enable_repos; @@ -384,6 +385,7 @@ main (int argc, gs_unref_object GFile *yumcachedir = NULL; gs_unref_object GFile *yumcache_lookaside = NULL; gs_unref_object GFile *yumroot_varcache = NULL; + gs_unref_object OstreeRepo *repo = NULL; gs_unref_ptrarray GPtrArray *all_packages = NULL; g_option_context_add_main_entries (context, option_entries, NULL); @@ -602,24 +604,18 @@ main (int argc, goto out; { + gs_unref_object GFile *repo_path = g_file_new_for_path ("repo"); + repo = ostree_repo_new (repo_path); } - - { - /* OSTree commit messages aren't really useful. */ - const char *commit_message = ""; - if (!gs_subprocess_simple_run_sync (NULL, - GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT, - cancellable, - error, - "rpm-ostree-postprocess-and-commit", - "--repo=repo", - "-m", commit_message, - gs_file_get_path_cached (yumroot), - ref, - NULL)) - goto out; - } + + if (!ostree_repo_open (repo, cancellable, error)) + goto out; + if (!rpmostree_postprocess_and_commit (yumroot, repo, + ref, NULL, + cancellable, error)) + goto out; + if (!gs_file_rename (rpmtextlist_path_new, rpmtextlist_path, cancellable, error)) goto out; diff --git a/src/rpm-ostree-postprocess-and-commit.c b/src/rpmostree-postprocess.c similarity index 89% rename from src/rpm-ostree-postprocess-and-commit.c rename to src/rpmostree-postprocess.c index 0939950e..417a44ef 100644 --- a/src/rpm-ostree-postprocess-and-commit.c +++ b/src/rpmostree-postprocess.c @@ -22,20 +22,9 @@ #include "string.h" -#include +#include "rpmostree-postprocess.h" #include "libgsystem.h" -static char *opt_repo_path; -static char *opt_message; -static char *opt_gpg_sign_keyid; - -static GOptionEntry option_entries[] = { - { "repo", 'r', 0, G_OPTION_ARG_STRING, &opt_repo_path, "Path to OSTree repository", "REPO" }, - { "message", 'm', 0, G_OPTION_ARG_STRING, &opt_message, "Commit message", "MESSAGE" }, - { "gpg-sign", 0, 0, G_OPTION_ARG_STRING, &opt_gpg_sign_keyid, "Sign commit using GPG key", "KEYID" }, - { NULL } -}; - static gboolean move_to_dir (GFile *src, GFile *dest_dir, @@ -576,45 +565,26 @@ create_rootfs_from_yumroot_content (GFile *targetroot, return ret; } -int -main (int argc, char **argv) +gboolean +rpmostree_postprocess_and_commit (GFile *rootfs, + OstreeRepo *repo, + const char *refname, + const char *gpg_keyid, + GCancellable *cancellable, + GError **error) { - GError *local_error = NULL; - GError **error = &local_error; - const char *rootfs_path; - GCancellable *cancellable = NULL; - gs_free char *rootfs_tmp_path = NULL; - gs_free char *parent_revision = NULL; - gs_free char *new_revision = NULL; - gs_unref_object GFile *rootfs_tmp = NULL; - gs_unref_object GFile *rootfs = NULL; + gboolean ret = FALSE; gs_unref_object GFile *root_tree = NULL; + gs_unref_object GFile *rootfs_tmp = NULL; gs_unref_object OstreeMutableTree *mtree = NULL; OstreeRepoCommitModifier *commit_modifier = NULL; - gs_unref_object OstreeRepo *repo = NULL; - const char *refname; - GOptionContext *context = g_option_context_new ("- Commit the result of an RPM installroot to OSTree repository"); + gs_free char *parent_revision = NULL; + gs_free char *new_revision = NULL; - g_option_context_add_main_entries (context, option_entries, NULL); - - if (!g_option_context_parse (context, &argc, &argv, error)) - goto out; - - if (argc < 2) - { - g_printerr ("usage: %s ROOTFS_PATH REFNAME\n", argv[0]); - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Option processing failed"); - goto out; - } - - rootfs_path = argv[1]; - refname = argv[2]; - - rootfs = g_file_new_for_path (rootfs_path); - - rootfs_tmp_path = g_strconcat (rootfs_path, ".tmp", NULL); - rootfs_tmp = g_file_new_for_path (rootfs_tmp_path); + { + gs_free char *rootfs_tmp_path = g_strconcat (gs_file_get_path_cached (rootfs), ".tmp", NULL); + rootfs_tmp = g_file_new_for_path (rootfs_tmp_path); + } if (!gs_shutil_rm_rf (rootfs_tmp, cancellable, error)) goto out; @@ -627,19 +597,6 @@ main (int argc, char **argv) if (!gs_file_rename (rootfs_tmp, rootfs, cancellable, error)) goto out; - if (opt_repo_path) - { - gs_unref_object GFile *repo_path = g_file_new_for_path (opt_repo_path); - repo = ostree_repo_new (repo_path); - } - else - { - repo = ostree_repo_new_default (); - } - - if (!ostree_repo_open (repo, cancellable, error)) - goto out; - // To make SELinux work, we need to do the labeling right before this. // This really needs some sort of API, so we can apply the xattrs as // we're committing into the repo, rather than having to label the @@ -659,14 +616,14 @@ main (int argc, char **argv) if (!ostree_repo_resolve_rev (repo, refname, TRUE, &parent_revision, error)) goto out; - if (!ostree_repo_write_commit (repo, parent_revision, "", opt_message, + if (!ostree_repo_write_commit (repo, parent_revision, "", "", NULL, (OstreeRepoFile*)root_tree, &new_revision, cancellable, error)) goto out; - if (opt_gpg_sign_keyid) + if (gpg_keyid) { - if (!ostree_repo_sign_commit (repo, new_revision, opt_gpg_sign_keyid, NULL, + if (!ostree_repo_sign_commit (repo, new_revision, gpg_keyid, NULL, cancellable, error)) goto out; } @@ -683,22 +640,7 @@ main (int argc, char **argv) else g_print ("Preserved %s\n", gs_file_get_path_cached (rootfs)); + ret = TRUE; out: - if (local_error != NULL) - { - int is_tty = isatty (1); - const char *prefix = ""; - const char *suffix = ""; - if (is_tty) - { - prefix = "\x1b[31m\x1b[1m"; /* red, bold */ - suffix = "\x1b[22m\x1b[0m"; /* bold off, color reset */ - } - g_printerr ("%serror: %s%s\n", prefix, suffix, local_error->message); - g_error_free (local_error); - return 2; - } - else - return 0; + return ret; } - diff --git a/src/rpmostree-postprocess.h b/src/rpmostree-postprocess.h new file mode 100644 index 00000000..707ca54f --- /dev/null +++ b/src/rpmostree-postprocess.h @@ -0,0 +1,31 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * + * Copyright (C) 2013,2014 Colin Walters + * + * 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 + +gboolean +rpmostree_postprocess_and_commit (GFile *rootfs, + OstreeRepo *repo, + const char *refname, + const char *gpg_keyid, + GCancellable *cancellable, + GError **error);