Check if a URL has been downloaded and cached successfully. Args: cache_dir: Base cache directory url: URL to check expected_filename: If provided, also verify this file exists Returns: Path to the cached artifact directory if complete, None otherwise
(
cache_dir: Path, url: str, expected_filename: Optional[str] = None
)
| 183 | |
| 184 | |
| 185 | def check_cached_download( |
| 186 | cache_dir: Path, url: str, expected_filename: Optional[str] = None |
| 187 | ) -> Optional[Path]: |
| 188 | """ |
| 189 | Check if a URL has been downloaded and cached successfully. |
| 190 | |
| 191 | Args: |
| 192 | cache_dir: Base cache directory |
| 193 | url: URL to check |
| 194 | expected_filename: If provided, also verify this file exists |
| 195 | |
| 196 | Returns: |
| 197 | Path to the cached artifact directory if complete, None otherwise |
| 198 | """ |
| 199 | artifact_dir = get_cache_artifact_dir(cache_dir, url) |
| 200 | breadcrumb_path = get_breadcrumb_path(cache_dir, url) |
| 201 | |
| 202 | # Check if breadcrumb indicates completion |
| 203 | if not is_download_complete(breadcrumb_path): |
| 204 | return None |
| 205 | |
| 206 | # Check if artifact directory exists |
| 207 | if not artifact_dir.exists(): |
| 208 | logger.warning( |
| 209 | f"Breadcrumb exists but artifact directory missing: {artifact_dir}" |
| 210 | ) |
| 211 | return None |
| 212 | |
| 213 | # If expected filename provided, verify it exists |
| 214 | if expected_filename: |
| 215 | expected_path = artifact_dir / expected_filename |
| 216 | if not expected_path.exists(): |
| 217 | logger.warning(f"Expected file missing: {expected_path}") |
| 218 | return None |
| 219 | |
| 220 | return artifact_dir |
no test coverage detected