MCPcopy Create free account
hub / github.com/AlayaLab/Hive / move_cache

Function move_cache

models/flowsep/diffusers/utils/hub_utils.py:175–194  ·  view source on GitHub ↗
(old_cache_dir: Optional[str] = None, new_cache_dir: Optional[str] = None)

Source from the content-addressed store, hash-verified

173
174
175def move_cache(old_cache_dir: Optional[str] = None, new_cache_dir: Optional[str] = None) -> None:
176 if new_cache_dir is None:
177 new_cache_dir = DIFFUSERS_CACHE
178 if old_cache_dir is None:
179 old_cache_dir = old_diffusers_cache
180
181 old_cache_dir = Path(old_cache_dir).expanduser()
182 new_cache_dir = Path(new_cache_dir).expanduser()
183 for old_blob_path in old_cache_dir.glob("**/blobs/*"):
184 if old_blob_path.is_file() and not old_blob_path.is_symlink():
185 new_blob_path = new_cache_dir / old_blob_path.relative_to(old_cache_dir)
186 new_blob_path.parent.mkdir(parents=True, exist_ok=True)
187 os.replace(old_blob_path, new_blob_path)
188 try:
189 os.symlink(new_blob_path, old_blob_path)
190 except OSError:
191 logger.warning(
192 "Could not create symlink between old cache and new cache. If you use an older version of diffusers again, files will be re-downloaded."
193 )
194 # At this point, old_cache_dir contains symlinks to the new cache (it can still be used).
195
196
197cache_version_file = os.path.join(DIFFUSERS_CACHE, "version_diffusers_cache.txt")

Callers 1

hub_utils.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected