From 9b75387648250e31c86a3d05611be8f9f809986f Mon Sep 17 00:00:00 2001
From: Michael Hudson-Doyle <michael.hudson@canonical.com>
Date: Fri, 25 Aug 2023 15:15:02 +1200
Subject: [PATCH] update-source-catalog: work better when we want a variation
 to point at the base layer.

---
 debian/changelog      | 2 ++
 update-source-catalog | 8 +++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/debian/changelog b/debian/changelog
index 870a8340..750991c1 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,6 +1,8 @@
 livecd-rootfs (23.10.22) UNRELEASED; urgency=medium
 
   * Undo preseeding in reset_snapd_state.
+  * update-source-catalog: work better when we want a variation to point
+    at the base layer.
 
  -- Michael Hudson-Doyle <michael.hudson@ubuntu.com>  Fri, 25 Aug 2023 11:44:57 +1200
 
diff --git a/update-source-catalog b/update-source-catalog
index 0869dd39..fa1d17c1 100755
--- a/update-source-catalog
+++ b/update-source-catalog
@@ -37,12 +37,18 @@ for entry in output:
         if 'variations' not in template:
             print("Non unique id in source catalog but no variations!")
             sys.exit(1)
-        for k, variation in template['variations'].items():
+        for variation in template['variations'].values():
             variation['size'] = int(opts.size)
         entry.setdefault('variations', {}).update(template['variations'])
         break
 else:
     # No entry with this id found, so add a new one.
+
+    if template['variations']:
+        for variation in template['variations'].values():
+            if variation['path'] == opts.squashfs:
+                variation['size'] == int(opts.size)
+
     template['size'] = int(opts.size)
     template['path'] = opts.squashfs