diff --git a/src/libpriv/rpmostree-postprocess.c b/src/libpriv/rpmostree-postprocess.c index ac4f74a5c7..9b7ac1821c 100644 --- a/src/libpriv/rpmostree-postprocess.c +++ b/src/libpriv/rpmostree-postprocess.c @@ -1273,6 +1273,17 @@ rpmostree_copy_additional_files (int rootfs_dfd, dest += strspn (dest, "/"); if (!*dest) return glnx_throw (error, "Invalid destination in add-files"); + /* At this point on the filesystem level, the /etc content is already in + * /usr/etc. But let's be nice and allow people to use add-files into /etc + * and have it appear in /usr/etc; in most cases we want /usr/etc to just + * be a libostree implementation detail. + */ + g_autofree char *dest_owned = NULL; + if (g_str_has_prefix (dest, "etc/")) + { + dest_owned = g_strconcat ("usr/", dest, NULL); + dest = dest_owned; + } g_print ("Adding file '%s'\n", dest); diff --git a/tests/compose-tests/test-misc-tweaks.sh b/tests/compose-tests/test-misc-tweaks.sh index c91ee8bca1..f07f9407a2 100755 --- a/tests/compose-tests/test-misc-tweaks.sh +++ b/tests/compose-tests/test-misc-tweaks.sh @@ -13,11 +13,15 @@ pysetjsonmember "default_target" '"multi-user.target"' pyappendjsonmember "packages" '["tuned"]' pysetjsonmember "units" '["tuned.service"]' # And test adding/removing files -pysetjsonmember "add-files" '[["foo.txt", "/usr/etc/foo.txt"]]' +pysetjsonmember "add-files" '[["foo.txt", "/usr/etc/foo.txt"], + ["baz.txt", "/usr/share/baz.txt"], + ["bar.txt", "/etc/bar.txt"]]' pysetjsonmember "remove-files" '["etc/hosts"]' pysetjsonmember "remove-from-packages" '[["setup", "/etc/hosts\..*"]]' rnd=$RANDOM echo $rnd > composedata/foo.txt +echo bar > composedata/bar.txt +echo baz > composedata/baz.txt # Test tmp-is-dir pysetjsonmember "tmp-is-dir" 'True' @@ -44,6 +48,10 @@ 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 +ostree --repo=${repobuild} cat ${treeref} /usr/etc/bar.txt > out.txt +assert_file_has_content out.txt bar +ostree --repo=${repobuild} cat ${treeref} /usr/share/baz.txt > out.txt +assert_file_has_content out.txt baz echo "ok add-files" ostree --repo=${repobuild} ls ${treeref} /usr/etc > out.txt