Skip to content

Commit

Permalink
fixup! Support Flatpak preinstallation as part of a DNF install
Browse files Browse the repository at this point in the history
Fixes from comments on #6056
  • Loading branch information
owtaylor committed Jan 16, 2025
1 parent e193012 commit 7df1152
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 23 deletions.
22 changes: 4 additions & 18 deletions pyanaconda/modules/payloads/payload/flatpak/flatpak_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#


import os
from typing import List, Optional

import gi
Expand All @@ -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__)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
10 changes: 7 additions & 3 deletions pyanaconda/modules/payloads/payload/flatpak/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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:<path>), or None
"""
...

@property
@abstractmethod
Expand Down Expand Up @@ -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()

Expand All @@ -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:
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion pyanaconda/modules/payloads/payloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions pyanaconda/modules/payloads/source/flatpak/flatpak.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _
Expand All @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion pyanaconda/timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7df1152

Please sign in to comment.