| 1 | """Path probes that preserve browser-data permission failures.""" |
| 2 | |
| 3 | import stat |
| 4 | from pathlib import Path |
| 5 | |
| 6 | |
| 7 | def _mode(path: Path) -> int | None: |
| 8 | try: |
| 9 | return path.stat().st_mode |
| 10 | except PermissionError: |
| 11 | raise |
| 12 | except OSError: |
| 13 | return None |
| 14 | |
| 15 | |
| 16 | def path_exists(path: Path) -> bool: |
| 17 | return _mode(path) is not None |
| 18 | |
| 19 | |
| 20 | def path_is_file(path: Path) -> bool: |
| 21 | mode = _mode(path) |
| 22 | return mode is not None and stat.S_ISREG(mode) |
| 23 | |
| 24 | |
| 25 | def path_is_dir(path: Path) -> bool: |
| 26 | mode = _mode(path) |
| 27 | return mode is not None and stat.S_ISDIR(mode) |
| 28 |