From b73f308b8d99157dae77e8b931427e95d781d2dc Mon Sep 17 00:00:00 2001 From: Jonathan Dieter Date: Mon, 18 Sep 2017 18:10:52 +0300 Subject: [PATCH] Copy in additional files before postprocessing Sometimes it's useful to have access to the additional files when running the post script, so this re-orders the compose process to copy the additional files in before the post script runs Signed-off-by: Jonathan Dieter --- src/app/rpmostree-compose-builtin-tree.c | 3 --- src/libpriv/rpmostree-postprocess.c | 21 +++++++++++---------- src/libpriv/rpmostree-postprocess.h | 6 ------ tests/compose-tests/test-misc-tweaks.sh | 12 ++++++++++++ 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/app/rpmostree-compose-builtin-tree.c b/src/app/rpmostree-compose-builtin-tree.c index e308b6c945..28cb97b0e7 100644 --- a/src/app/rpmostree-compose-builtin-tree.c +++ b/src/app/rpmostree-compose-builtin-tree.c @@ -934,9 +934,6 @@ impl_compose_tree (const char *treefile_pathstr, cancellable, error)) return glnx_prefix_error (error, "Preparing rootfs for commit"); - if (!rpmostree_copy_additional_files (rootfs_fd, self->treefile_context_dirs->pdata[0], treefile, cancellable, error)) - return FALSE; - g_autoptr(GFile) treefile_dirpath = g_file_get_parent (self->treefile); if (!rpmostree_check_passwd (self->repo, rootfs_fd, treefile_dirpath, treefile, self->previous_checksum, diff --git a/src/libpriv/rpmostree-postprocess.c b/src/libpriv/rpmostree-postprocess.c index c87139f280..1fcc981769 100644 --- a/src/libpriv/rpmostree-postprocess.c +++ b/src/libpriv/rpmostree-postprocess.c @@ -1221,18 +1221,15 @@ rpmostree_rootfs_postprocess_common (int rootfs_fd, return TRUE; } -/** - * rpmostree_copy_additional_files: - * - * Copy external files, if specified in the configuration file, from +/* Copy external files, if specified in the configuration file, from * the context directory to the rootfs. */ -gboolean -rpmostree_copy_additional_files (int rootfs_dfd, - GFile *context_directory, - JsonObject *treefile, - GCancellable *cancellable, - GError **error) +static gboolean +copy_additional_files (int rootfs_dfd, + GFile *context_directory, + JsonObject *treefile, + GCancellable *cancellable, + GError **error) { guint len; JsonArray *add = NULL; @@ -1559,6 +1556,10 @@ rpmostree_treefile_postprocessing (int rootfs_fd, } } + /* Copy in additional files before postprocessing */ + if (!copy_additional_files (rootfs_fd, context_directory, treefile, cancellable, error)) + return FALSE; + const char *postprocess_script = NULL; if (!_rpmostree_jsonutil_object_get_optional_string_member (treefile, "postprocess-script", &postprocess_script, error)) diff --git a/src/libpriv/rpmostree-postprocess.h b/src/libpriv/rpmostree-postprocess.h index a653c44d8f..6a8288dc80 100644 --- a/src/libpriv/rpmostree-postprocess.h +++ b/src/libpriv/rpmostree-postprocess.h @@ -78,9 +78,3 @@ rpmostree_commit (int rootfs_dfd, char **out_new_revision, GCancellable *cancellable, GError **error); -gboolean -rpmostree_copy_additional_files (int rootfs_dfd, - GFile *context_directory, - JsonObject *treefile, - GCancellable *cancellable, - GError **error); diff --git a/tests/compose-tests/test-misc-tweaks.sh b/tests/compose-tests/test-misc-tweaks.sh index c91ee8bca1..745560efd8 100755 --- a/tests/compose-tests/test-misc-tweaks.sh +++ b/tests/compose-tests/test-misc-tweaks.sh @@ -14,6 +14,15 @@ pyappendjsonmember "packages" '["tuned"]' pysetjsonmember "units" '["tuned.service"]' # And test adding/removing files pysetjsonmember "add-files" '[["foo.txt", "/usr/etc/foo.txt"]]' +pysetjsonmember "postprocess-script" \"$PWD/postprocess.sh\" +cat > postprocess.sh << EOF +#!/bin/bash +set -xeuo pipefail +echo misc-tweaks-postprocess-done > /usr/share/misc-tweaks-postprocess-done.txt +cp -a /usr/etc/foo.txt /usr/share/misc-tweaks-foo.txt +EOF +chmod a+x postprocess.sh + pysetjsonmember "remove-files" '["etc/hosts"]' pysetjsonmember "remove-from-packages" '[["setup", "/etc/hosts\..*"]]' rnd=$RANDOM @@ -44,6 +53,9 @@ echo "ok enable units" # Tests for files ostree --repo=${repobuild} cat ${treeref} /usr/etc/foo.txt > out.txt assert_file_has_content out.txt $rnd +# https://github.com/projectatomic/rpm-ostree/pull/997 +ostree --repo=${repobuild} cat ${treeref} /usr/share/misc-tweaks-foo.txt > out.txt +assert_file_has_content out.txt $rnd echo "ok add-files" ostree --repo=${repobuild} ls ${treeref} /usr/etc > out.txt