From ba1e9b16f4311216183f0c81c1981e63bcb56627 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 13 Mar 2024 12:50:28 -0400 Subject: [PATCH] checkout: Always replace existing content The combination of the "honor whiteout" and "union" flags are intended to basically be "merge trees like overlayfs does". But we were missing this case in order to support e.g. replacing a symlink with a directory. --- src/libostree/ostree-repo-checkout.c | 10 ++++++++++ tests/basic-test.sh | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/src/libostree/ostree-repo-checkout.c b/src/libostree/ostree-repo-checkout.c index f506545529..60ced404a0 100644 --- a/src/libostree/ostree-repo-checkout.c +++ b/src/libostree/ostree-repo-checkout.c @@ -1036,6 +1036,16 @@ checkout_tree_at_recurse (OstreeRepo *self, OstreeRepoCheckoutAtOptions *options contents_csum_v = NULL; /* iter_loop freed it */ } + /* In this mode, we're flattening in a manner similar to overlayfs, so ensure + * any content that was there before is gone. + */ + if (!is_opaque_whiteout && options->process_whiteouts + && options->overwrite_mode == OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_FILES) + { + if (!glnx_shutil_rm_rf_at (destination_parent_fd, destination_name, NULL, error)) + return FALSE; + } + /* First, make the directory. Push a new scope in case we end up using * setfscreatecon(). */ diff --git a/tests/basic-test.sh b/tests/basic-test.sh index 7905e6ee68..af7c2e0d28 100644 --- a/tests/basic-test.sh +++ b/tests/basic-test.sh @@ -1159,6 +1159,14 @@ if touch overlay/baz/.wh.cow && touch overlay/.wh.deeper && touch overlay/baz/an assert_has_file overlay-co/baz test -L overlay-co/anewdir + rm overlay-co overlay -rf + mkdir -p overlay/somelink + $OSTREE --repo=repo commit ${COMMIT_ARGS} -b overlay-symlink-convert --tree=dir=overlay + for branch in test2 overlay-symlink-convert; do + $OSTREE --repo=repo checkout --union --whiteouts ${branch} overlay-co + done + test -d overlay-co/somelink || fatal "should replace symlink with dir" + rm overlay-co overlay -rf echo "ok whiteouts enabled" # Now double check whiteouts are not processed without --whiteouts