From aeaca9b89638754409c739a6f35d8261c036f05f Mon Sep 17 00:00:00 2001 From: Dan Nicholson Date: Thu, 13 Feb 2020 10:59:01 -0700 Subject: [PATCH] lib/pull: Honor require-static-deltas for scratch deltas If a scratch delta exists and the caller has required static deltas, use it instead of the heuristic about existing commits. --- src/libostree/ostree-repo-pull.c | 12 +++++++----- tests/pull-test.sh | 12 +++++++++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/libostree/ostree-repo-pull.c b/src/libostree/ostree-repo-pull.c index 419a6e791e..3f21b357f8 100644 --- a/src/libostree/ostree-repo-pull.c +++ b/src/libostree/ostree-repo-pull.c @@ -2690,12 +2690,14 @@ get_best_static_delta_start_for (OtPullData *pull_data, memcpy (out_result->from_revision, newest_candidate, OSTREE_SHA256_STRING_LEN+1); } - /* If a from-scratch delta is available, we don’t want to use it if the ref - * or any of its ancestors already exists locally and is not partial. In - * that case only some of the objects in the new commit may be needed, so - * doing an object pull is likely more bandwidth efficient. + /* If a from-scratch delta is available and deltas aren't required, we don’t + * want to use it if the ref or any of its ancestors already exists locally + * and is not partial. In that case only some of the objects in the new + * commit may be needed, so doing an object pull is likely more bandwidth + * efficient. */ - if (out_result->result == DELTA_SEARCH_RESULT_SCRATCH) + if (out_result->result == DELTA_SEARCH_RESULT_SCRATCH && + !pull_data->require_static_deltas) { g_autofree char *rev = g_strdup (cur_revision); diff --git a/tests/pull-test.sh b/tests/pull-test.sh index 0c91156742..c9ddeae43d 100644 --- a/tests/pull-test.sh +++ b/tests/pull-test.sh @@ -54,7 +54,7 @@ function verify_initial_contents() { assert_file_has_content baz/cow '^moo$' } -num_tests=38 +num_tests=39 # 3 tests needs GPG support num_gpg_tests=3 if has_gpgme; then @@ -705,5 +705,15 @@ ${CMD_PREFIX} ostree --repo=repo pull origin scratch@${rev2} ${CMD_PREFIX} ostree --repo=repo pull origin scratch echo "ok scratch delta (normal parent)" +# Pull with a normal parent but require static deltas. This should fail +# because it tries to pull the scratch delta. +repo_init --no-gpg-verify +${CMD_PREFIX} ostree --repo=repo pull origin scratch@${rev2} +if ${CMD_PREFIX} ostree --repo=repo pull --require-static-deltas origin scratch 2>err.txt; then + assert_not_reached "pull of corrupt scratch delta unexpectedly succeeded" +fi +assert_file_has_content err.txt "Invalid checksum for static delta" +echo "ok scratch delta (require static deltas with normal parent)" + # Clean up the deltas so we don't leave a corrupt one around rm ostree-srv/gnomerepo/deltas -rf