From a0c91a3d13109789bbcbeacc83a4005b11db0aa9 Mon Sep 17 00:00:00 2001 From: ionite34 Date: Thu, 24 Nov 2022 14:34:18 +0800 Subject: Improve error handling for libmount --- snekbox/libmount.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'snekbox/libmount.py') diff --git a/snekbox/libmount.py b/snekbox/libmount.py index 52ea6b2..5300c5c 100644 --- a/snekbox/libmount.py +++ b/snekbox/libmount.py @@ -49,6 +49,9 @@ def mount(source: Path | str, target: Path | str, fs: str, **options: str | int) fs: Filesystem type. **options: Mount options. """ + if Path(target).is_mount(): + raise OSError(f"{target} is already a mount point") + kwargs = " ".join(f"{key}={value}" for key, value in options.items()) result: int = libc.mount( @@ -69,6 +72,9 @@ def unmount(target: Path | str, flags: UnmountFlags | int = UnmountFlags.MNT_DET target: Target directory. flags: Unmount flags. """ + if not Path(target).is_mount(): + raise OSError(f"{target} is not a mount point") + result: int = libc.umount2(str(target).encode(), int(flags)) if result < 0: errno = ctypes.get_errno() -- cgit v1.2.3