Skip to content

Commit

Permalink
compose: Copy in additional files before postprocessing
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Jonathan Dieter authored and cgwalters committed Sep 26, 2017
1 parent 39cbf04 commit 73f46bf
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
3 changes: 0 additions & 3 deletions src/app/rpmostree-compose-builtin-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 11 additions & 10 deletions src/libpriv/rpmostree-postprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down
6 changes: 0 additions & 6 deletions src/libpriv/rpmostree-postprocess.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
12 changes: 12 additions & 0 deletions tests/compose-tests/test-misc-tweaks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 73f46bf

Please sign in to comment.