From 432830a5c5912f0e860142283605dcde611848fd Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Tue, 21 Apr 2026 21:03:09 +0200 Subject: [PATCH] lib.FileContext.mkdir(): Add method Add .mkdir() to the API which should do the expected, and implement it in ExecContext and Local specializations. Signed-off-by: Jan Lindemann --- src/python/jw/pkg/lib/ExecContext.py | 4 ++++ src/python/jw/pkg/lib/FileContext.py | 6 ++++++ src/python/jw/pkg/lib/ec/Local.py | 3 +++ 3 files changed, 13 insertions(+) diff --git a/src/python/jw/pkg/lib/ExecContext.py b/src/python/jw/pkg/lib/ExecContext.py index a86a9754..8cd7a65e 100644 --- a/src/python/jw/pkg/lib/ExecContext.py +++ b/src/python/jw/pkg/lib/ExecContext.py @@ -504,6 +504,10 @@ class ExecContext(Base): cmd = ['mv', src, dst] await self.run(cmd, cmd_input=InputMode.NonInteractive) + async def _mkdir(self, name: str, mode: int) -> None: + cmd = ['mkdir', name, '-m', self.__mode_str(mode)] + await self.run(cmd, cmd_input=InputMode.NonInteractive) + async def _mktemp(self, tmpl: str, directory: bool) -> str: cmd = ['mktemp'] if directory: diff --git a/src/python/jw/pkg/lib/FileContext.py b/src/python/jw/pkg/lib/FileContext.py index 4fad41e7..76abe761 100644 --- a/src/python/jw/pkg/lib/FileContext.py +++ b/src/python/jw/pkg/lib/FileContext.py @@ -160,6 +160,12 @@ class FileContext(abc.ABC): async def rename(self, src: str, dst: str) -> None: return await self._rename(src, dst) + async def _mkdir(self, path: str, mode: int) -> None: + raise NotImplementedError(f'{self.log_path}: mkdir({path}) is not implemented') + + async def mkdir(self, path: str, mode: int=0o777) -> None: + return await self._mkdir(path, mode) + async def _mktemp(self, tmpl: str, directory: bool) -> None: raise NotImplementedError(f'{self.log_name}: mktemp("{path}") is not implemented') diff --git a/src/python/jw/pkg/lib/ec/Local.py b/src/python/jw/pkg/lib/ec/Local.py index 90154057..f150b2f8 100644 --- a/src/python/jw/pkg/lib/ec/Local.py +++ b/src/python/jw/pkg/lib/ec/Local.py @@ -155,6 +155,9 @@ class Local(Base): async def _rename(self, src: str, dst: str) -> None: os.rename(src, dst) + async def _mkdir(self, name: str, mode: int) -> None: + os.mkdir(name, mode) + async def _stat(self, path: str, follow_symlinks: bool) -> StatResult: return StatResult.from_os(os.stat(path, follow_symlinks=follow_symlinks))