Skip to content

Commit

Permalink
repo: site_cache_dir: separate subdir from root_dir (#10273)
Browse files Browse the repository at this point in the history
* repo: site_cache_dir: separate subdir from root_dir

Currently we join scm root_dir with subrepo root dir to have something that would represent that subrepo, but that directory might not exist in reality as we might be using a bare git repo. So we should just treat those as separate things.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update __init__.py

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
efiop and pre-commit-ci[bot] authored Feb 1, 2024
1 parent f42468b commit 0bb2f3d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions dvc/repo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,12 +608,12 @@ def site_cache_dir(self) -> str:

cache_dir = self.config["core"].get("site_cache_dir") or site_cache_dir()

subdir = None
if isinstance(self.fs, GitFileSystem):
relparts: tuple[str, ...] = ()
if self.root_dir != "/":
# subrepo
relparts = self.fs.relparts(self.root_dir, "/")
root_dir = os.path.join(self.scm.root_dir, *relparts)
subdir = self.root_dir
root_dir = self.scm.root_dir
else:
root_dir = self.root_dir

Expand All @@ -629,14 +629,16 @@ def site_cache_dir(self) -> str:
# components were changed (useful to prevent newer dvc versions from
# using older broken cache). Please reset this back to 0 if other parts
# of the token components are changed.
salt = 2
salt = 0

# NOTE: This helps us avoid accidentally reusing cache for repositories
# that just happened to be at the same path as old deleted ones.
btime = self._btime or getattr(os.stat(root_dir), "st_birthtime", None)

md5 = hashlib.md5( # noqa: S324
str((root_dir, btime, getpass.getuser(), version_tuple[0], salt)).encode()
str(
(root_dir, subdir, btime, getpass.getuser(), version_tuple[0], salt)
).encode()
)
repo_token = md5.hexdigest()
return os.path.join(repos_dir, repo_token)
Expand Down

0 comments on commit 0bb2f3d

Please sign in to comment.