From 00e474e2ff4247f09974b1a2f812a2331958549c Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lallement Date: Thu, 15 Nov 2018 12:08:07 +0100 Subject: [PATCH] Make snap functions idempotent _snap_preseed and snap_prepare_assertions can be called several times with the same snap and will only provision it once. --- live-build/functions | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/live-build/functions b/live-build/functions index c3fe2a35..9f910bcb 100644 --- a/live-build/functions +++ b/live-build/functions @@ -411,6 +411,12 @@ _snap_preseed() { # Download the snap & assertion local snap_download_failed=0 + + # Preseed a snap only once + if [ -f ${snaps_dir}/${SNAP_NAME}_[0-9]*.snap ]; then + return + fi + chroot $CHROOT_ROOT sh -c " set -x; cd /var/lib/snapd/seed; @@ -456,6 +462,10 @@ snap_prepare_assertions() { local account_key_assertion="$assertions_dir/account-key" local account_assertion="$assertions_dir/account" + if [ -d "$assertions_dir" ]; then + return + fi + mkdir -p "$assertions_dir" mkdir -p "$snaps_dir" @@ -500,15 +510,10 @@ snap_prepare() { # used for the image's model assertion local CUSTOM_BRAND_MODEL=${2:-generic:generic-classic} - local seed_dir="$CHROOT_ROOT/var/lib/snapd/seed" - local snaps_dir="$seed_dir/snaps" - snap_prepare_assertions "$CHROOT_ROOT" "$CUSTOM_BRAND_MODEL" # Download the core snap - if ! [ -f $snaps_dir/core_[0-9]*.snap ] ; then - _snap_preseed $CHROOT_ROOT core stable - fi + _snap_preseed $CHROOT_ROOT core stable } snap_preseed() {