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