diff options
author | 2022-11-24 14:34:18 +0800 | |
---|---|---|
committer | 2022-11-24 14:34:18 +0800 | |
commit | a0c91a3d13109789bbcbeacc83a4005b11db0aa9 (patch) | |
tree | 02be0845d52b2c336cd0b49c0067a3b0cd168587 | |
parent | Correct MemFS test class name (diff) |
Improve error handling for libmount
-rw-r--r-- | snekbox/libmount.py | 6 |
1 files changed, 6 insertions, 0 deletions
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() |