From 7df115241f2b9e14032198a9b69ba96f0566636d Mon Sep 17 00:00:00 2001 From: "Owen W. Taylor" Date: Mon, 6 Jan 2025 13:36:47 -0500 Subject: [PATCH] fixup! Support Flatpak preinstallation as part of a DNF install Fixes from comments on https://github.com/rhinstaller/anaconda/pull/6056 --- .../payload/flatpak/flatpak_manager.py | 22 ++++--------------- .../payloads/payload/flatpak/source.py | 10 ++++++--- pyanaconda/modules/payloads/payloads.py | 1 - .../payloads/source/flatpak/flatpak.py | 17 ++++++++++++++ pyanaconda/timezone.py | 2 +- 5 files changed, 29 insertions(+), 23 deletions(-) diff --git a/pyanaconda/modules/payloads/payload/flatpak/flatpak_manager.py b/pyanaconda/modules/payloads/payload/flatpak/flatpak_manager.py index bdba735a688..5e677e0c4b3 100644 --- a/pyanaconda/modules/payloads/payload/flatpak/flatpak_manager.py +++ b/pyanaconda/modules/payloads/payload/flatpak/flatpak_manager.py @@ -19,7 +19,6 @@ # -import os from typing import List, Optional import gi @@ -43,21 +42,6 @@ from gi.repository.Flatpak import Installation, Transaction, TransactionOperationType -# We need Flatpak to read configuration files from the target and write -# to the target system installation. Since we use the Flatpak API -# in process, we need to do this by modifying the environment before -# we start any threads. Setting these variables will be harmless if -# we aren't actually using Flatpak. - -# pylint: disable=environment-modify -os.environ["FLATPAK_DOWNLOAD_TMPDIR"] = os.path.join(conf.target.system_root, "var/tmp") -# pylint: disable=environment-modify -os.environ["FLATPAK_CONFIG_DIR"] = os.path.join(conf.target.system_root, "etc/flatpak") -# pylint: disable=environment-modify -os.environ["FLATPAK_OS_CONFIG_DIR"] = os.path.join(conf.target.system_root, "usr/share/flatpak") -# pylint: disable=environment-modify -os.environ["FLATPAK_SYSTEM_DIR"] = os.path.join(conf.target.system_root, "var/lib/flatpak") - log = get_module_logger(__name__) @@ -156,7 +140,8 @@ def calculate_size(self, progress: Optional[ProgressReporter]): self._download_size, self._install_size = \ self._get_source().calculate_size(self._flatpak_refs) except NoSourceError as e: - log.info("Flatpak source not available, skipping: %s", e) + log.error("Flatpak source not available, skipping installing %s: %s", + ", ".join(self._flatpak_refs), e) self._skip_installation = True @property @@ -184,7 +169,8 @@ def download(self, progress: ProgressReporter): self._download_location, progress) except NoSourceError as e: - log.info("Flatpak source not available, skipping: %s", e) + log.error("Flatpak source not available, skipping installing %s: %s", + ", ".join(self._flatpak_refs), e) self._skip_installation = True def install(self, progress: ProgressReporter): diff --git a/pyanaconda/modules/payloads/payload/flatpak/source.py b/pyanaconda/modules/payloads/payload/flatpak/source.py index 51d02bf8d5d..635ee8e8911 100644 --- a/pyanaconda/modules/payloads/payload/flatpak/source.py +++ b/pyanaconda/modules/payloads/payload/flatpak/source.py @@ -115,6 +115,7 @@ def calculate_size(self, refs: List[str]) -> Tuple[int, int]: :param refs: list of Flatpak references :returns: download size, installed size """ + ... @abstractmethod def download(self, refs: List[str], download_location: str, @@ -133,6 +134,7 @@ def download(self, refs: List[str], download_location: str, :param progress: used to report progress of the download :returns sideload location, including the transport (e.g. oci:), or None """ + ... @property @abstractmethod @@ -296,7 +298,7 @@ def _images(self) -> List[StaticSourceImage]: url = self._url + "/index.json" response = downloader(url) if response.status_code == 404: - raise NoSourceError("No source found at {}".format(url)) + raise NoSourceError("No Flatpak source found at {}".format(url)) response.raise_for_status() index_json = response.json() @@ -310,7 +312,8 @@ def _images(self) -> List[StaticSourceImage]: return result def _blob_url(self, digest): - assert digest.startswith("sha256:") + if not digest.startswith("sha256:"): + raise RuntimeError("Only SHA-256 digests are supported") return self._url + "/blobs/sha256/" + digest[7:] def _get_blob(self, downloader, digest) -> bytes: @@ -325,7 +328,8 @@ def _get_blob(self, downloader, digest) -> bytes: return result def _download_blob(self, downloader, download_location, digest, stream=False): - assert digest.startswith("sha256:") + if not digest.startswith("sha256:"): + raise RuntimeError("Only SHA-256 digests are supported") blobs_dir = os.path.join(download_location, "blobs/sha256/") os.makedirs(blobs_dir, exist_ok=True) diff --git a/pyanaconda/modules/payloads/payloads.py b/pyanaconda/modules/payloads/payloads.py index 29d169d995c..0106812d1c9 100644 --- a/pyanaconda/modules/payloads/payloads.py +++ b/pyanaconda/modules/payloads/payloads.py @@ -96,7 +96,6 @@ def activate_payload(self, payload): if self._active_payload.needs_flatpak_side_payload(): payload = self.create_payload(PayloadType.FLATPAK) - assert isinstance(payload, FlatpakModule) self._flatpak_side_payload = payload else: self._flatpak_side_payload = None diff --git a/pyanaconda/modules/payloads/source/flatpak/flatpak.py b/pyanaconda/modules/payloads/source/flatpak/flatpak.py index affb8bde534..a9bb150b818 100644 --- a/pyanaconda/modules/payloads/source/flatpak/flatpak.py +++ b/pyanaconda/modules/payloads/source/flatpak/flatpak.py @@ -17,6 +17,8 @@ # License and may only be used or replicated with the express permission of # Red Hat, Inc. # +import os + from pyanaconda.anaconda_loggers import get_module_logger from pyanaconda.core.configuration.anaconda import conf from pyanaconda.core.i18n import _ @@ -32,6 +34,21 @@ ) from pyanaconda.modules.payloads.source.source_base import PayloadSourceBase +# We need Flatpak to read configuration files from the target and write +# to the target system installation. Since we use the Flatpak API +# in process, we need to do this by modifying the environment before +# we start any threads. Setting these variables will be harmless if +# we aren't actually using Flatpak. + +# pylint: disable=environment-modify +os.environ["FLATPAK_DOWNLOAD_TMPDIR"] = os.path.join(conf.target.system_root, "var/tmp") +# pylint: disable=environment-modify +os.environ["FLATPAK_CONFIG_DIR"] = os.path.join(conf.target.system_root, "etc/flatpak") +# pylint: disable=environment-modify +os.environ["FLATPAK_OS_CONFIG_DIR"] = os.path.join(conf.target.system_root, "usr/share/flatpak") +# pylint: disable=environment-modify +os.environ["FLATPAK_SYSTEM_DIR"] = os.path.join(conf.target.system_root, "var/lib/flatpak") + log = get_module_logger(__name__) __all__ = ["FlatpakSourceModule"] diff --git a/pyanaconda/timezone.py b/pyanaconda/timezone.py index 4013a69ad8a..779016a592d 100644 --- a/pyanaconda/timezone.py +++ b/pyanaconda/timezone.py @@ -24,11 +24,11 @@ import datetime import time +import zoneinfo from collections import OrderedDict from functools import cache import langtable -import zoneinfo from blivet import arch from pyanaconda.anaconda_loggers import get_module_logger