Open each absolute component without following symlinks; caller closes.
(path)
| 51 | |
| 52 | |
| 53 | def _directory(path): |
| 54 | """Open each absolute component without following symlinks; caller closes.""" |
| 55 | path = os.path.abspath(path) |
| 56 | fd = os.open(os.sep, os.O_RDONLY | os.O_DIRECTORY) |
| 57 | try: |
| 58 | for part in path.split(os.sep): |
| 59 | if not part: |
| 60 | continue |
| 61 | next_fd = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, |
| 62 | dir_fd=fd) |
| 63 | os.close(fd) |
| 64 | fd = next_fd |
| 65 | return fd |
| 66 | except BaseException: |
| 67 | os.close(fd) |
| 68 | raise |
| 69 | |
| 70 | |
| 71 | def _regular(path): |