Skip to content

Commit 335ad32

Browse files
committed
call pre/post fetch and update hooks for FreeBSD BASEDIR symlink creation
1 parent 17c615b commit 335ad32

File tree

1 file changed

+44
-10
lines changed

1 file changed

+44
-10
lines changed

libioc/ResourceUpdater.py

+44-10
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,7 @@ def fetch(
317317
f"Fetching updates for release '{self.release.name}'"
318318
)
319319

320-
symlink_src = self.release.root_path
321-
if "p0" in [x.snapshot_name for x in self.release.version_snapshots]:
322-
# use p0 snapshot if available
323-
symlink_src += "/.zfs/snapshot/p0"
324-
os.symlink(symlink_src, self._base_release_symlink_location)
320+
self._pre_fetch()
325321

326322
try:
327323
self._create_download_dir()
@@ -334,7 +330,7 @@ def fetch(
334330
yield releaseUpdateDownloadEvent.fail(e)
335331
raise
336332
finally:
337-
os.unlink(self._base_release_symlink_location)
333+
self._post_fetch()
338334
yield releaseUpdateDownloadEvent.end()
339335

340336
def _snapshot_release_after_update(self) -> None:
@@ -411,10 +407,8 @@ def _update_jail(
411407
yield executeResourceUpdateEvent.begin()
412408

413409
skipped = False
410+
self._pre_update()
414411

415-
lnk = f"{self.resource.root_path}{self._base_release_symlink_location}"
416-
self.resource._require_relative_path(lnk)
417-
os.symlink("/", lnk)
418412
try:
419413
self._create_jail_update_dir()
420414
for event in libioc.Jail.JailGenerator.fork_exec(
@@ -454,7 +448,7 @@ def _update_jail(
454448
force=True,
455449
event_scope=executeResourceUpdateEvent.scope
456450
)
457-
os.unlink(lnk)
451+
self._post_update()
458452

459453
if skipped is True:
460454
yield executeResourceUpdateEvent.skip("already up to date")
@@ -464,6 +458,22 @@ def _update_jail(
464458
self.logger.verbose(f"Resource '{self.resource.name}' updated")
465459
yield True # ToDo: yield False if nothing was updated
466460

461+
def _pre_fetch(self) -> None:
462+
"""Execute before executing the fetch command."""
463+
pass
464+
465+
def _post_fetch(self) -> None:
466+
"""Execute after executing the fetch command."""
467+
pass
468+
469+
def _pre_update(self) -> None:
470+
"""Execute before executing the update command."""
471+
pass
472+
473+
def _post_update(self) -> None:
474+
"""Execute after executing the update command."""
475+
pass
476+
467477

468478
class HardenedBSD(Updater):
469479
"""Updater for HardenedBSD."""
@@ -667,6 +677,30 @@ def patch_version(self) -> int:
667677
f"{self.resource.root_path}/bin/freebsd-version"
668678
)["patch"])
669679

680+
def _pre_fetch(self) -> None:
681+
"""Execute before executing the fetch command."""
682+
symlink_src = self.release.root_path
683+
if "p0" in [x.snapshot_name for x in self.release.version_snapshots]:
684+
# use p0 snapshot if available
685+
symlink_src += "/.zfs/snapshot/p0"
686+
os.symlink(symlink_src, self._base_release_symlink_location)
687+
688+
def _post_fetch(self) -> None:
689+
"""Execute after executing the fetch command."""
690+
os.unlink(self._base_release_symlink_location)
691+
692+
def _pre_update(self) -> None:
693+
"""Execute before executing the update command."""
694+
lnk = f"{self.resource.root_path}{self._base_release_symlink_location}"
695+
self.resource._require_relative_path(lnk)
696+
os.symlink("/", lnk)
697+
698+
def _post_update(self) -> None:
699+
"""Execute after executing the update command."""
700+
lnk = f"{self.resource.root_path}{self._base_release_symlink_location}"
701+
self.resource._require_relative_path(f"{lnk}/..")
702+
os.unlink(lnk)
703+
670704

671705
def get_launchable_update_resource( # noqa: T484
672706
host: 'libioc.Host.HostGenerator',

0 commit comments

Comments
 (0)