diff options
Diffstat (limited to 'src/mlia/utils/filesystem.py')
-rw-r--r-- | src/mlia/utils/filesystem.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/mlia/utils/filesystem.py b/src/mlia/utils/filesystem.py index f92629b..f8e8962 100644 --- a/src/mlia/utils/filesystem.py +++ b/src/mlia/utils/filesystem.py @@ -14,6 +14,8 @@ from tempfile import TemporaryDirectory from typing import Generator from typing import Iterable +USER_ONLY_PERM_MASK = 0o700 + def get_mlia_resources() -> Path: """Get the path to the resources directory.""" @@ -96,6 +98,17 @@ def copy_all(*paths: Path, dest: Path) -> None: shutil.copytree(path, dest, dirs_exist_ok=True) +def recreate_directory(dir_path: Path, mode: int = USER_ONLY_PERM_MASK) -> None: + """Recreate directory.""" + if dir_path.exists(): + if not dir_path.is_dir(): + raise ValueError(f"Path {dir_path} is not a directory.") + + shutil.rmtree(dir_path) + + dir_path.mkdir(exist_ok=True, mode=mode) + + @contextmanager def working_directory( working_dir: Path, create_dir: bool = False |