From 0bb2f3d10c11f87fa259ca5ce9be5c2bc4b05763 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Thu, 1 Feb 2024 09:32:22 +0200 Subject: [PATCH] repo: site_cache_dir: separate subdir from root_dir (#10273) * 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> --- dvc/repo/__init__.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/dvc/repo/__init__.py b/dvc/repo/__init__.py index d752b499e..c10965f43 100644 --- a/dvc/repo/__init__.py +++ b/dvc/repo/__init__.py @@ -608,12 +608,12 @@ class Repo: 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 @@ -629,14 +629,16 @@ class Repo: # 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)