Attempt to create the given directory and sub-directories exist. Returns True if successful or if it already exists.
(cache_dir: Path)
| 1099 | |
| 1100 | |
| 1101 | def try_makedirs(cache_dir: Path) -> bool: |
| 1102 | """Attempt to create the given directory and sub-directories exist. |
| 1103 | |
| 1104 | Returns True if successful or if it already exists. |
| 1105 | """ |
| 1106 | try: |
| 1107 | os.makedirs(cache_dir, exist_ok=True) |
| 1108 | except (FileNotFoundError, NotADirectoryError, FileExistsError): |
| 1109 | # One of the path components was not a directory: |
| 1110 | # - we're in a zip file |
| 1111 | # - it is a file |
| 1112 | return False |
| 1113 | except PermissionError: |
| 1114 | return False |
| 1115 | except OSError as e: |
| 1116 | # as of now, EROFS doesn't have an equivalent OSError-subclass |
| 1117 | if e.errno == errno.EROFS: |
| 1118 | return False |
| 1119 | raise |
| 1120 | return True |
| 1121 | |
| 1122 | |
| 1123 | def get_cache_dir(file_path: Path) -> Path: |
no outgoing calls