repo: Add OSTREE_REPO_TEST_ERROR=invalid-cache env var
Add an invalid-cache test error flag to ensure that the code that checks for and recovers from a corrupted summary cache is hit. This helps make sure that the recovery path is actually used without resorting to G_MESSAGES_DEBUG. Closes: #1698 Approved by: cgwalters
This commit is contained in:
parent
1b5cb52da2
commit
4e6b13e8b6
|
|
@ -61,7 +61,8 @@ G_BEGIN_DECLS
|
||||||
#define OSTREE_COMMIT_TIMESTAMP "ostree.commit.timestamp"
|
#define OSTREE_COMMIT_TIMESTAMP "ostree.commit.timestamp"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
OSTREE_REPO_TEST_ERROR_PRE_COMMIT = (1 << 0)
|
OSTREE_REPO_TEST_ERROR_PRE_COMMIT = (1 << 0),
|
||||||
|
OSTREE_REPO_TEST_ERROR_INVALID_CACHE = (1 << 1),
|
||||||
} OstreeRepoTestErrorFlags;
|
} OstreeRepoTestErrorFlags;
|
||||||
|
|
||||||
struct OstreeRepoCommitModifier {
|
struct OstreeRepoCommitModifier {
|
||||||
|
|
|
||||||
|
|
@ -4037,10 +4037,20 @@ ostree_repo_pull_with_options (OstreeRepo *self,
|
||||||
if (summary_from_cache)
|
if (summary_from_cache)
|
||||||
{
|
{
|
||||||
/* The cached summary doesn't match, fetch a new one and verify again */
|
/* The cached summary doesn't match, fetch a new one and verify again */
|
||||||
|
if ((self->test_error_flags & OSTREE_REPO_TEST_ERROR_INVALID_CACHE) > 0)
|
||||||
|
{
|
||||||
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||||
|
"Remote %s cached summary invalid and "
|
||||||
|
"OSTREE_REPO_TEST_ERROR_INVALID_CACHE specified",
|
||||||
|
pull_data->remote_name);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
g_debug ("Remote %s cached summary invalid, pulling new version",
|
||||||
|
pull_data->remote_name);
|
||||||
|
|
||||||
summary_from_cache = FALSE;
|
summary_from_cache = FALSE;
|
||||||
g_clear_pointer (&bytes_summary, (GDestroyNotify)g_bytes_unref);
|
g_clear_pointer (&bytes_summary, (GDestroyNotify)g_bytes_unref);
|
||||||
g_debug ("Remote %s cached summary invalid, pulling new version",
|
|
||||||
pull_data->remote_name);
|
|
||||||
if (!_ostree_fetcher_mirrored_request_to_membuf (pull_data->fetcher,
|
if (!_ostree_fetcher_mirrored_request_to_membuf (pull_data->fetcher,
|
||||||
pull_data->meta_mirrorlist,
|
pull_data->meta_mirrorlist,
|
||||||
"summary",
|
"summary",
|
||||||
|
|
|
||||||
|
|
@ -1187,6 +1187,7 @@ ostree_repo_init (OstreeRepo *self)
|
||||||
static gsize gpgme_initialized;
|
static gsize gpgme_initialized;
|
||||||
const GDebugKey test_error_keys[] = {
|
const GDebugKey test_error_keys[] = {
|
||||||
{ "pre-commit", OSTREE_REPO_TEST_ERROR_PRE_COMMIT },
|
{ "pre-commit", OSTREE_REPO_TEST_ERROR_PRE_COMMIT },
|
||||||
|
{ "invalid-cache", OSTREE_REPO_TEST_ERROR_INVALID_CACHE },
|
||||||
};
|
};
|
||||||
|
|
||||||
if (g_once_init_enter (&gpgme_initialized))
|
if (g_once_init_enter (&gpgme_initialized))
|
||||||
|
|
|
||||||
|
|
@ -245,7 +245,19 @@ cmp repo/tmp/cache/summaries/origin.sig ${test_tmpdir}/ostree-srv/gnomerepo/summ
|
||||||
# cache before validating the signature. That would mean the cache would
|
# cache before validating the signature. That would mean the cache would
|
||||||
# have mismatched summary and signature and ostree would remain
|
# have mismatched summary and signature and ostree would remain
|
||||||
# deadlocked there until the remote published a new signature.
|
# deadlocked there until the remote published a new signature.
|
||||||
|
#
|
||||||
|
# First pull with OSTREE_REPO_TEST_ERROR=invalid-cache to see the
|
||||||
|
# invalid cache is detected. Then pull again to check if it can be
|
||||||
|
# recovered from.
|
||||||
cp ${test_tmpdir}/ostree-srv/gnomerepo/summary.2 repo/tmp/cache/summaries/origin
|
cp ${test_tmpdir}/ostree-srv/gnomerepo/summary.2 repo/tmp/cache/summaries/origin
|
||||||
|
if OSTREE_REPO_TEST_ERROR=invalid-cache ${OSTREE} --repo=repo pull origin main 2>err.txt; then
|
||||||
|
assert_not_reached "Should have hit OSTREE_REPO_TEST_ERROR_INVALID_CACHE"
|
||||||
|
fi
|
||||||
|
assert_file_has_content err.txt "OSTREE_REPO_TEST_ERROR_INVALID_CACHE"
|
||||||
|
assert_has_file repo/tmp/cache/summaries/origin
|
||||||
|
assert_has_file repo/tmp/cache/summaries/origin.sig
|
||||||
|
cmp repo/tmp/cache/summaries/origin ${test_tmpdir}/ostree-srv/gnomerepo/summary.2 >&2
|
||||||
|
cmp repo/tmp/cache/summaries/origin.sig ${test_tmpdir}/ostree-srv/gnomerepo/summary.sig.1 >&2
|
||||||
${OSTREE} --repo=repo pull origin main
|
${OSTREE} --repo=repo pull origin main
|
||||||
assert_has_file repo/tmp/cache/summaries/origin
|
assert_has_file repo/tmp/cache/summaries/origin
|
||||||
assert_has_file repo/tmp/cache/summaries/origin.sig
|
assert_has_file repo/tmp/cache/summaries/origin.sig
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue