diff options
author | Cooper Lees <me@cooperlees.com> | 2017-08-01 22:35:45 (GMT) |
---|---|---|
committer | Ćukasz Langa <lukasz@langa.pl> | 2017-08-01 22:35:45 (GMT) |
commit | 173ff4a58a6b337fe8a0eb44f211f33f278d3d5f (patch) | |
tree | da9aeb8baec584bd775ae42c82c9d090f85a1884 /Lib/pathlib.py | |
parent | 9eef9e805e950eb6bc9ded8c99c5d6abf1d681de (diff) | |
download | cpython-173ff4a58a6b337fe8a0eb44f211f33f278d3d5f.zip cpython-173ff4a58a6b337fe8a0eb44f211f33f278d3d5f.tar.gz cpython-173ff4a58a6b337fe8a0eb44f211f33f278d3d5f.tar.bz2 |
bpo-30897: Add is_mount() to pathlib.Path (#2669)
* Add in is_mount() call to pathlib.Path similiar to os.path.ismount(path)
* Add tests for is_mount()
Diffstat (limited to 'Lib/pathlib.py')
-rw-r--r-- | Lib/pathlib.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py index 0e65c61..c14ddd0 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -1329,6 +1329,27 @@ class Path(PurePath): # (see https://bitbucket.org/pitrou/pathlib/issue/12/) return False + def is_mount(self): + """ + Check if this path is a POSIX mount point + """ + # Need to exist and be a dir + if not self.exists() or not self.is_dir(): + return False + + parent = Path(self.parent) + try: + parent_dev = parent.stat().st_dev + except OSError: + return False + + dev = self.stat().st_dev + if dev != parent_dev: + return True + ino = self.stat().st_ino + parent_ino = parent.stat().st_ino + return ino == parent_ino + def is_symlink(self): """ Whether this path is a symbolic link. @@ -1416,3 +1437,6 @@ class WindowsPath(Path, PureWindowsPath): def group(self): raise NotImplementedError("Path.group() is unsupported on this system") + + def is_mount(self): + raise NotImplementedError("Path.is_mount() is unsupported on this system") |