Skip to content

Commit

Permalink
base: Add proper state checking for pull-pack
Browse files Browse the repository at this point in the history
  • Loading branch information
avdgrinten committed Oct 31, 2024
1 parent 386fe80 commit b0bff4e
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions xbstrap/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1476,30 +1476,45 @@ def check_staging(self, settings):
return ItemState(missing=True)
return ItemState()

def check_if_packed(self, settings):
if self._cfg.use_xbps:
environ = os.environ.copy()
def _have_xbps_package(self):
environ = os.environ.copy()

arch = self.architecture
if self.architecture == "noarch":
# XXX(arsen): all architectures should be checked at all times
# when we come around to making multiarch
arch = list(self._cfg.site_architectures)[0]
arch = self.architecture
if self.architecture == "noarch":
# XXX(arsen): all architectures should be checked at all times
# when we come around to making multiarch
arch = list(self._cfg.site_architectures)[0]

_util.build_environ_paths(
environ, "PATH", prepend=[os.path.join(_util.find_home(), "bin")]
_util.build_environ_paths(
environ, "PATH", prepend=[os.path.join(_util.find_home(), "bin")]
)
environ["XBPS_ARCH"] = arch

try:
subprocess.check_call(
["xbps-query", "--repository=" + self._cfg.xbps_repository_dir, self.name],
env=environ,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
environ["XBPS_ARCH"] = arch
return True
except subprocess.CalledProcessError:
return False

try:
subprocess.check_call(
["xbps-query", "--repository=" + self._cfg.xbps_repository_dir, self.name],
env=environ,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
def check_if_packed(self, settings):
if self._cfg.use_xbps:
if self._have_xbps_package():
return ItemState()
except subprocess.CalledProcessError:
else:
return ItemState(missing=True)
else:
raise GenericError("Package management configuration does not support pack")

def check_if_pull_needed(self, settings):
if self._cfg.use_xbps:
if self._have_xbps_package():
return ItemState()
else:
return ItemState(missing=True)
else:
raise GenericError("Package management configuration does not support pack")
Expand Down Expand Up @@ -2957,7 +2972,7 @@ def _determine_state(self):
Action.INSTALL_PKG: lambda s, c: s.check_if_installed(c, sysroot=self.get_sysroot()),
Action.ARCHIVE_TOOL: lambda s, c: s.check_if_archived(c),
Action.ARCHIVE_PKG: lambda s, c: ItemState(missing=True),
Action.PULL_PKG_PACK: lambda s, c: ItemState(missing=True),
Action.PULL_PKG_PACK: lambda s, c: s.check_if_pull_needed(c),
Action.RUN: lambda s, c: ItemState(missing=True),
Action.RUN_PKG: lambda s, c: ItemState(missing=True),
Action.RUN_TOOL: lambda s, c: ItemState(missing=True),
Expand Down

0 comments on commit b0bff4e

Please sign in to comment.