MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / move_cache

Function move_cache

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

Source from the content-addressed store, hash-verified

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