Attempt to create the given directory and sub-directories exist. Returns True if successful or if it already exists.
(cache_dir: Path)
| 1155 | |
| 1156 | |
| 1157 | def try_makedirs(cache_dir: Path) -> bool: |
| 1158 | """Attempt to create the given directory and sub-directories exist. |
| 1159 | |
| 1160 | Returns True if successful or if it already exists. |
| 1161 | """ |
| 1162 | try: |
| 1163 | os.makedirs(cache_dir, exist_ok=True) |
| 1164 | except (FileNotFoundError, NotADirectoryError, FileExistsError): |
| 1165 | # One of the path components was not a directory: |
| 1166 | # - we're in a zip file |
| 1167 | # - it is a file |
| 1168 | return False |
| 1169 | except PermissionError: |
| 1170 | return False |
| 1171 | except OSError as e: |
| 1172 | # as of now, EROFS doesn't have an equivalent OSError-subclass |
| 1173 | # |
| 1174 | # squashfuse_ll returns ENOSYS "OSError: [Errno 38] Function not |
| 1175 | # implemented" for a read-only error |
| 1176 | if e.errno in {errno.EROFS, errno.ENOSYS}: |
| 1177 | return False |
| 1178 | raise |
| 1179 | return True |
| 1180 | |
| 1181 | |
| 1182 | def get_cache_dir(file_path: Path) -> Path: |
no outgoing calls