| 34 | |
| 35 | |
| 36 | class CacheManager: |
| 37 | CACHE_DIR = "cache" |
| 38 | FILES_DIR = "files" |
| 39 | FS_DIR = "fs" |
| 40 | |
| 41 | def __init__(self, repo): |
| 42 | self._repo = repo |
| 43 | self.config = config = repo.config["cache"] |
| 44 | self._odb = {} |
| 45 | |
| 46 | local = config.get("local") |
| 47 | default = self.default_local_cache_dir |
| 48 | |
| 49 | if local: |
| 50 | settings = {"name": local} |
| 51 | elif "dir" not in config and not default: |
| 52 | settings = None |
| 53 | else: |
| 54 | from dvc.config_schema import LOCAL_COMMON |
| 55 | |
| 56 | url = config.get("dir") or default |
| 57 | settings = {"url": url} |
| 58 | for opt in LOCAL_COMMON: |
| 59 | if opt in config: |
| 60 | settings[str(opt)] = config.get(opt) |
| 61 | |
| 62 | kwargs = {} |
| 63 | if not isinstance(repo.fs, GitFileSystem): |
| 64 | kwargs["fs"] = repo.fs |
| 65 | |
| 66 | odb = _get_odb( |
| 67 | repo, |
| 68 | settings, |
| 69 | prefix=(self.FILES_DIR, DEFAULT_ALGORITHM), |
| 70 | **kwargs, |
| 71 | ) |
| 72 | self._odb["repo"] = odb |
| 73 | self._odb[Schemes.LOCAL] = odb |
| 74 | legacy_odb = _get_odb(repo, settings, hash_name="md5-dos2unix", **kwargs) |
| 75 | self._odb["legacy"] = legacy_odb |
| 76 | |
| 77 | @property |
| 78 | def fs_cache(self): |
| 79 | """Filesystem-based cache. |
| 80 | |
| 81 | Currently used as a temporary location to download files that we don't |
| 82 | yet have a regular oid (e.g. md5) for. |
| 83 | """ |
| 84 | from dvc_data.index import FileStorage |
| 85 | |
| 86 | return FileStorage( |
| 87 | key=(), |
| 88 | fs=self.local.fs, |
| 89 | path=self.local.fs.join(self.local_cache_dir, self.FS_DIR), |
| 90 | ) |
| 91 | |
| 92 | def _init_odb(self, schemes): |
| 93 | for scheme in schemes: |
no outgoing calls