[CI] Speed up dependency install: dual-ABI Rust ext cache and prevalidation pruning (#33619)
This commit is contained in:
@@ -2,13 +2,14 @@
|
||||
"""
|
||||
Clean up stale HuggingFace cache artifacts from previous failed downloads.
|
||||
|
||||
This script removes incomplete marker files, temporary files, and lock files
|
||||
from the HuggingFace cache directory. These artifacts can accumulate from
|
||||
interrupted or failed downloads and may interfere with future downloads.
|
||||
This script removes incomplete marker files and temporary files from the
|
||||
HuggingFace cache directory. These artifacts can accumulate from interrupted
|
||||
or failed downloads and may interfere with future downloads.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
@@ -46,16 +47,26 @@ def find_stale_artifacts(cache_dir: str) -> List[Path]:
|
||||
if not cache_path.exists():
|
||||
return []
|
||||
|
||||
# Patterns for stale files to clean up
|
||||
# Not "**/*.lock": another container may hold a download lock for 30+ min;
|
||||
# unlinking it gives the next acquirer a fresh inode and both proceed.
|
||||
patterns = [
|
||||
"**/*.incomplete", # Incomplete download markers
|
||||
"**/*.tmp", # Temporary files
|
||||
"**/*.lock", # Lock files from interrupted downloads
|
||||
]
|
||||
|
||||
# Another container may still be appending to its blobs/*.incomplete.
|
||||
min_stale_age_seconds = 2 * 60 * 60
|
||||
|
||||
stale_files = []
|
||||
now = time.time()
|
||||
for pattern in patterns:
|
||||
stale_files.extend(cache_path.glob(pattern))
|
||||
for path in cache_path.glob(pattern):
|
||||
try:
|
||||
if now - path.stat().st_mtime < min_stale_age_seconds:
|
||||
continue
|
||||
except OSError:
|
||||
continue # vanished mid-scan
|
||||
stale_files.append(path)
|
||||
|
||||
return stale_files
|
||||
|
||||
|
||||
Reference in New Issue
Block a user