From 25ba8db987094b141647b2d2e721095b61fac5c1 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 1 May 2018 16:36:03 -0400 Subject: [PATCH] lib/deploy: Throw an error if trying to stage when not ostree-booted There's no reason to do this. I didn't actually hit this problem, but it's a corner case that just occurred to me while working on the code. I think callers should be adapted to skip trying to use staging if there's no booted deployment. Closes: #1568 Approved by: jlebon --- src/libostree/ostree-sysroot-deploy.c | 4 ++++ tests/admin-test.sh | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c index ea9dcb29..6f6181d7 100644 --- a/src/libostree/ostree-sysroot-deploy.c +++ b/src/libostree/ostree-sysroot-deploy.c @@ -2658,6 +2658,10 @@ ostree_sysroot_stage_tree (OstreeSysroot *self, GCancellable *cancellable, GError **error) { + OstreeDeployment *booted_deployment = ostree_sysroot_get_booted_deployment (self); + if (booted_deployment == NULL) + return glnx_throw (error, "Cannot stage a deployment when not currently booted into an OSTree system"); + /* This is a bit of a hack. When adding a new service we have to end up getting * into the presets for downstream distros; see e.g. https://src.fedoraproject.org/rpms/ostree/pull-request/7 * diff --git a/tests/admin-test.sh b/tests/admin-test.sh index 6e3fd782..dd87cd11 100644 --- a/tests/admin-test.sh +++ b/tests/admin-test.sh @@ -21,7 +21,7 @@ set -euo pipefail -echo "1..$((23 + ${extra_admin_tests:-0}))" +echo "1..$((24 + ${extra_admin_tests:-0}))" function validate_bootloader() { cd ${test_tmpdir}; @@ -78,6 +78,12 @@ assert_ostree_deployment_refs 1/1/0 ${CMD_PREFIX} ostree admin status echo "ok layout" +if ${CMD_PREFIX} ostree admin deploy --stage --os=testos testos:testos/buildmaster/x86_64-runtime 2>err.txt; then + fatal "staged when not booted" +fi +assert_file_has_content_literal err.txt "Cannot stage a deployment when not currently booted into an OSTree system" +echo "ok staging does not work when not booted" + orig_mtime=$(stat -c '%.Y' sysroot/ostree/deploy) ${CMD_PREFIX} ostree admin deploy --os=testos testos:testos/buildmaster/x86_64-runtime new_mtime=$(stat -c '%.Y' sysroot/ostree/deploy)