lib/commit: Implement "adoption" with CONSUME flag

For checkouts that are on the same device, for regular files we can simply
"adopt" existing files. This is useful in the "build from subtrees" pattern that
happens with e.g. `rpm-ostree install` as well as flatpak and gnome-continuous.

New files are things like an updated `ldconfig` cache, etc. And particularly for
`rpm-ostree` we always regenerate the rpmdb, which for e.g. this workstation is
`61MB`.

We probably should have done this from the start, and instead had a `--copy`
flag to commit, but obviously we have to be backwards compatible.

There's more to do here - the biggest gap is probably for `bare-user` repos,
which are often used with things like `rpm-ostree compose tree` for host
systems. But we can do that later.

Closes: #1272
Approved by: jlebon
This commit is contained in:
Colin Walters authored and Atomic Bot committed 2017-10-16 18:22:09 +00:00
1 parent 729790bedc
commit 16c31a9b58
2 files changed
+222 -30

No files matched your search

+27 -1
View File
@@ -19,7 +19,7 @@
set -euo pipefail
echo "1..$((76 + ${extra_basic_tests:-0}))"
echo "1..$((77 + ${extra_basic_tests:-0}))"
CHECKOUT_U_ARG=""
CHECKOUT_H_ARGS="-H"
@@ -186,8 +186,34 @@ assert_not_has_dir $test_tmpdir/checkout-test2-l
$OSTREE fsck
# Some of the later tests are sensitive to state
$OSTREE reset test2 test2^
$OSTREE prune --refs-only
echo "ok consume (nom nom nom)"
# Test adopt
cd ${test_tmpdir}
rm checkout-test2-l -rf
$OSTREE checkout ${CHECKOUT_H_ARGS} test2 $test_tmpdir/checkout-test2-l
echo 'a file to consume 🍔' > $test_tmpdir/checkout-test2-l/eatme.txt
# Save a link to it for device/inode comparison
ln $test_tmpdir/checkout-test2-l/eatme.txt $test_tmpdir/eatme-savedlink.txt
$OSTREE commit ${COMMIT_ARGS} --link-checkout-speedup --consume -b test2 --tree=dir=$test_tmpdir/checkout-test2-l
$OSTREE fsck
# Adoption isn't implemented for bare-user yet
eatme_objpath=$(ostree_file_path_to_object_path repo test2 /eatme.txt)
if grep -q '^mode=bare$' repo/config || is_bare_user_only_repo repo; then
assert_files_hardlinked ${test_tmpdir}/eatme-savedlink.txt ${eatme_objpath}
else
if files_are_hardlinked ${test_tmpdir}/eatme-savedlink.txt ${eatme_objpath}; then
fatal "bare-user adopted?"
fi
fi
assert_not_has_dir $test_tmpdir/checkout-test2-l
# Some of the later tests are sensitive to state
$OSTREE reset test2 test2^
$OSTREE prune --refs-only
rm -f ${test_tmpdir}/eatme-savedlink.txt
echo "ok adopt"
cd ${test_tmpdir}
$OSTREE commit ${COMMIT_ARGS} -b test2-no-parent -s '' $test_tmpdir/checkout-test2-4
assert_streq $($OSTREE log test2-no-parent |grep '^commit' | wc -l) "1"