Skip to content

Commit

Permalink
lib/pull: Honor require-static-deltas for scratch deltas
Browse files Browse the repository at this point in the history
If a scratch delta exists and the caller has required static deltas, use
it instead of the heuristic about existing commits.
  • Loading branch information
dbnicholson committed Feb 13, 2020
1 parent ad9f5f3 commit aeaca9b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/libostree/ostree-repo-pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
12 changes: 11 additions & 1 deletion tests/pull-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit aeaca9b

Please sign in to comment.