From e3ec83a934159d16dacf940b22e80446a79c6595 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 19 Apr 2016 15:19:46 -0400 Subject: [PATCH] repo: Add OSTREE_BOOTID override envvar for debugging It's useful for test cases to be able to influence this. Conflicts: src/libostree/ostree-repo.c Closes: #170 Approved by: jlebon --- src/libostree/ostree-repo.c | 20 ++++++++++++++------ tests/basic-test.sh | 17 +++++++++++++++-- tests/libtest.sh | 6 ++++++ 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c index d44aeabe..a34e2ec1 100644 --- a/src/libostree/ostree-repo.c +++ b/src/libostree/ostree-repo.c @@ -2431,12 +2431,20 @@ ostree_repo_open (OstreeRepo *self, /* We use a per-boot identifier to keep track of which file contents * possibly haven't been sync'd to disk. */ - if (!g_file_get_contents ("/proc/sys/kernel/random/boot_id", - &self->boot_id, - NULL, - error)) - goto out; - g_strdelimit (self->boot_id, "\n", '\0'); + { const char *env_bootid = getenv ("OSTREE_BOOTID"); + + if (env_bootid != NULL) + self->boot_id = g_strdup (env_bootid); + else + { + if (!g_file_get_contents ("/proc/sys/kernel/random/boot_id", + &self->boot_id, + NULL, + error)) + goto out; + g_strdelimit (self->boot_id, "\n", '\0'); + } + } if (!glnx_opendirat (AT_FDCWD, gs_file_get_path_cached (self->repodir), TRUE, &self->repo_dir_fd, error)) diff --git a/tests/basic-test.sh b/tests/basic-test.sh index 2edb15d2..b2477955 100755 --- a/tests/basic-test.sh +++ b/tests/basic-test.sh @@ -400,11 +400,24 @@ echo "ok disable cache checkout" cd ${test_tmpdir} rm checkout-test2 -rf $OSTREE checkout test2 checkout-test2 -if env OSTREE_REPO_TEST_ERROR=pre-commit $OSTREE commit -b test2 -s '' $test_tmpdir/checkout-test2 2>err.txt; then +date > checkout-test2/date.txt +rm repo/tmp/* -rf +export TEST_BOOTID=3072029c-8b10-60d1-d31b-8422eeff9b42 +if env OSTREE_REPO_TEST_ERROR=pre-commit OSTREE_BOOTID=${TEST_BOOTID} \ + $OSTREE commit -b test2 -s '' $test_tmpdir/checkout-test2 2>err.txt; then assert_not_reached "Should have hit OSTREE_REPO_TEST_ERROR_PRE_COMMIT" fi assert_file_has_content err.txt OSTREE_REPO_TEST_ERROR_PRE_COMMIT -echo "ok test error pre commit" +found_staging=0 +for d in $(find repo/tmp/ -maxdepth 1 -type d); do + bn=$(basename $d) + if test ${bn##staging-} != ${bn}; then + assert_str_match "${bn}" "^staging-${TEST_BOOTID}-" + found_staging=1 + fi +done +assert_streq "${found_staging}" 1 +echo "ok test error pre commit/bootid" # Whiteouts cd ${test_tmpdir} diff --git a/tests/libtest.sh b/tests/libtest.sh index 0ce10a62..4d403a93 100755 --- a/tests/libtest.sh +++ b/tests/libtest.sh @@ -86,6 +86,12 @@ assert_streq () { test "$1" = "$2" || (echo 1>&2 "$1 != $2"; exit 1) } +assert_str_match () { + if ! echo "$1" | grep -E -q "$2"; then + (echo 1>&2 "$1 does not match regexp $2"; exit 1) + fi +} + assert_not_streq () { (! test "$1" = "$2") || (echo 1>&2 "$1 == $2"; exit 1) }