Test whether a path is a mount point
(path)
| 189 | # (Does this work for all UNIXes? Is it even guaranteed to work by Posix?) |
| 190 | |
| 191 | def ismount(path): |
| 192 | """Test whether a path is a mount point""" |
| 193 | try: |
| 194 | s1 = os.lstat(path) |
| 195 | except (OSError, ValueError): |
| 196 | # It doesn't exist -- so not a mount point. :-) |
| 197 | return False |
| 198 | else: |
| 199 | # A symlink can never be a mount point |
| 200 | if stat.S_ISLNK(s1.st_mode): |
| 201 | return False |
| 202 | |
| 203 | path = os.fspath(path) |
| 204 | if isinstance(path, bytes): |
| 205 | parent = join(path, b'..') |
| 206 | else: |
| 207 | parent = join(path, '..') |
| 208 | try: |
| 209 | s2 = os.lstat(parent) |
| 210 | except OSError: |
| 211 | parent = realpath(parent) |
| 212 | try: |
| 213 | s2 = os.lstat(parent) |
| 214 | except OSError: |
| 215 | return False |
| 216 | |
| 217 | # path/.. on a different device as path or the same i-node as path |
| 218 | return s1.st_dev != s2.st_dev or s1.st_ino == s2.st_ino |
| 219 | |
| 220 | |
| 221 | # Expand paths beginning with '~' or '~user'. |