Extracts the commit hash from a resolved filename toward a cache file.
(resolved_file: Optional[str], commit_hash: Optional[str] = None)
| 179 | |
| 180 | |
| 181 | def extract_commit_hash(resolved_file: Optional[str], commit_hash: Optional[str] = None): |
| 182 | """ |
| 183 | Extracts the commit hash from a resolved filename toward a cache file. |
| 184 | """ |
| 185 | if resolved_file is None or commit_hash is not None: |
| 186 | return commit_hash |
| 187 | resolved_file = str(Path(resolved_file).as_posix()) |
| 188 | search = re.search(r"snapshots/([^/]+)/", resolved_file) |
| 189 | if search is None: |
| 190 | return None |
| 191 | commit_hash = search.groups()[0] |
| 192 | return commit_hash if REGEX_COMMIT_HASH.match(commit_hash) else None |
| 193 | |
| 194 | |
| 195 | # Old default cache path, potentially to be migrated. |