Skip to content

Commit

Permalink
fix crash on layered packages
Browse files Browse the repository at this point in the history
  • Loading branch information
antheas committed Dec 4, 2024
1 parent 9561b14 commit 4f1cdc6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
41 changes: 25 additions & 16 deletions src/hhd/plugins/bootc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def get_bootc_status():


def get_ref_from_status(status: dict | None):
return (status or {}).get("spec", {}).get("image", {}).get("image", "")
return (((status or {}).get("spec", None) or {}).get("image", None) or {}).get(
"image", ""
)


def get_branch(ref: str, branches: dict, fallback: bool = True):
Expand Down Expand Up @@ -126,12 +128,14 @@ def is_incompatible(status: dict):
if status.get("apiVersion", None) != "org.containers.bootc/v1":
return True

if ((status.get("status", None) or {}).get("booted", None) or {}).get(
"incompatible", False
):
return True
boot_incompatible = (
(status.get("status", None) or {}).get("booted", None) or {}
).get("incompatible", False)

return False
if staged := ((status.get("status", None) or {}).get("staged", None) or {}):
return staged.get("incompatible", False)

return boot_incompatible


class BootcPlugin(HHDPlugin):
Expand Down Expand Up @@ -177,14 +181,21 @@ def open(
def get_version(self, s):
assert self.status
return (
(self.status.get("status", {}).get(s, None) or {})
.get("image", {})
.get("version", "")
)
(self.status.get("status", {}).get(s, None) or {}).get("image", None) or {}
).get("version", "")

def _init(self, conf: Config):
self.status = get_bootc_status()
ref = self.status.get("spec", {}).get("image", {}).get("image", "")

if is_incompatible(self.status):
conf["updates.bootc.stage.mode"] = "incompatible"
self.state = "incompatible"
conf[f"updates.bootc.update"] = None
return

ref = ((self.status.get("spec", None) or {}).get("image", None) or {}).get(
"image", ""
)
img = ref
if "/" in img:
img = img[img.rfind("/") + 1 :]
Expand Down Expand Up @@ -222,7 +233,8 @@ def _init(self, conf: Config):
# Then that will be the default, provided there is a rollback
rollback = (
not staged
and self.status.get("spec", {}).get("bootOrder", None) == "rollback"
and (self.status.get("spec", None) or {}).get("bootOrder", None)
== "rollback"
)
s = self.get_version("rollback")
if s and rollback:
Expand Down Expand Up @@ -253,10 +265,7 @@ def _init(self, conf: Config):
else:
conf[f"updates.bootc.update"] = None

if is_incompatible(self.status):
conf["updates.bootc.stage.mode"] = "incompatible"
self.state = "incompatible"
elif (
if (
cached_version
and cached_img == img
and cached_version != self.get_version("staged")
Expand Down
9 changes: 5 additions & 4 deletions src/hhd/plugins/bootc/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,17 @@ children:
tags: [error]
title: Error
default: >
Due to layering or custom initramfs, you cannot use bootc.
Undo the customizations and try again.
Due to layering or custom initramfs, you cannot update from here.
You can undo those with the button below.
reset:
type: action
title: Run rpm-ostree reset
tag: [verify]
hint: >-
Disable the custom initramfs and remove layers.
Disable the custom initramfs and remove layers. Your personal
data will not be affected.
loading_cancellable:
type: container
children:
Expand Down

0 comments on commit 4f1cdc6

Please sign in to comment.