MCPcopy Create free account
hub / github.com/TencentARC/BrushNet / move_cache

Function move_cache

src/diffusers/utils/hub_utils.py:205–224  ·  view source on GitHub ↗
(old_cache_dir: Optional[str] = None, new_cache_dir: Optional[str] = None)

Source from the content-addressed store, hash-verified

203
204
205def move_cache(old_cache_dir: Optional[str] = None, new_cache_dir: Optional[str] = None) -> None:
206 if new_cache_dir is None:
207 new_cache_dir = HF_HUB_CACHE
208 if old_cache_dir is None:
209 old_cache_dir = old_diffusers_cache
210
211 old_cache_dir = Path(old_cache_dir).expanduser()
212 new_cache_dir = Path(new_cache_dir).expanduser()
213 for old_blob_path in old_cache_dir.glob("**/blobs/*"):
214 if old_blob_path.is_file() and not old_blob_path.is_symlink():
215 new_blob_path = new_cache_dir / old_blob_path.relative_to(old_cache_dir)
216 new_blob_path.parent.mkdir(parents=True, exist_ok=True)
217 os.replace(old_blob_path, new_blob_path)
218 try:
219 os.symlink(new_blob_path, old_blob_path)
220 except OSError:
221 logger.warning(
222 "Could not create symlink between old cache and new cache. If you use an older version of diffusers again, files will be re-downloaded."
223 )
224 # At this point, old_cache_dir contains symlinks to the new cache (it can still be used).
225
226
227cache_version_file = os.path.join(HF_HUB_CACHE, "version_diffusers_cache.txt")

Callers 1

hub_utils.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected