fix: lxc_exists_and_apt_not_old must be in a transaction (#1104)

cascading-pr from https://code.forgejo.org/forgejo/lxc-helpers/pulls/52

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- bug fixes
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/1104): <!--number 1104 --><!--line 0 --><!--description Zml4OiBseGNfZXhpc3RzX2FuZF9hcHRfbm90X29sZCBtdXN0IGJlIGluIGEgdHJhbnNhY3Rpb24=-->fix: lxc_exists_and_apt_not_old must be in a transaction<!--description-->
<!--end release-notes-assistant-->

Co-authored-by: cascading-pr <cascading-pr@example.com>
Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1104
Reviewed-by: limiting-factor <limiting-factor@noreply.code.forgejo.org>
Co-authored-by: cascading-pr <cascading-pr@noreply.code.forgejo.org>
Co-committed-by: cascading-pr <cascading-pr@noreply.code.forgejo.org>
This commit is contained in:
cascading-pr 2025-10-20 21:03:14 +00:00 committed by earl-warren
parent 44f4557005
commit 8034eaaabb
No known key found for this signature in database
GPG key ID: F128CBE6AB3A7201

View file

@ -385,11 +385,13 @@ function lxc_running() {
function lxc_build_template_release() {
local name="$(lxc_template_release)"
lxc_transaction_begin $name
if lxc_exists_and_apt_not_old $name; then
lxc_transaction_unlock
return
fi
lxc_transaction_begin $name
local draft=$(lxc_transaction_draft_name)
$LXC_SUDO lxc-create --name $draft --template debian -- --release=$LXC_CONTAINER_RELEASE
echo 'lxc.apparmor.profile = unconfined' | $LXC_SUDO tee -a $(lxc_config $draft)
@ -405,15 +407,16 @@ function lxc_build_template() {
local name="$1"
local newname="$2"
if lxc_exists_and_apt_not_old $newname; then
return
fi
if test "$name" = "$(lxc_template_release)"; then
lxc_build_template_release
fi
lxc_transaction_begin $name
if lxc_exists_and_apt_not_old $newname; then
lxc_transaction_unlock
return
fi
local draft=$(lxc_transaction_draft_name)
if ! $LXC_SUDO lxc-copy --name=$name --newname=$draft; then
echo lxc-copy --name=$name --newname=$draft failed