Open a file descriptor to a directory.
(path)
| 607 | |
| 608 | @contextlib.contextmanager |
| 609 | def open_dir_fd(path): |
| 610 | """Open a file descriptor to a directory.""" |
| 611 | assert os.path.isdir(path) |
| 612 | flags = os.O_RDONLY |
| 613 | if hasattr(os, "O_DIRECTORY"): |
| 614 | flags |= os.O_DIRECTORY |
| 615 | dir_fd = os.open(path, flags) |
| 616 | try: |
| 617 | yield dir_fd |
| 618 | finally: |
| 619 | os.close(dir_fd) |
| 620 | |
| 621 | |
| 622 | def fs_is_case_insensitive(directory): |