aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2021-11-16 12:55:12 +0100
committerGitHub <noreply@github.com>2021-11-16 12:55:12 +0100
commitec608e3def7bdd2bf41ac4d6f6c1575b6ee670f9 (patch)
tree38009e56b255ecf4ea2052723c9495234d39ec6a /src
parent6463eaca14ea813f39a3b3e4c5a15fa32fc30232 (diff)
parentb459a3e85600e1d3a326278a823ce0bdf71fcc21 (diff)
Merge pull request #5452 from Kha/git-extend-lock
git: extend cache dir lock over all mutating operations
Diffstat (limited to 'src')
-rw-r--r--src/libfetchers/git.cc8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc
index a3f4e42a3..544d2ffbf 100644
--- a/src/libfetchers/git.cc
+++ b/src/libfetchers/git.cc
@@ -324,17 +324,13 @@ struct GitInputScheme : InputScheme
Path cacheDir = getCacheDir() + "/nix/gitv3/" + hashString(htSHA256, actualUrl).to_string(Base32, false);
repoDir = cacheDir;
- Path cacheDirLock = cacheDir + ".lock";
createDirs(dirOf(cacheDir));
- AutoCloseFD lock = openLockFile(cacheDirLock, true);
- lockFile(lock.get(), ltWrite, true);
+ PathLocks cacheDirLock({cacheDir + ".lock"});
if (!pathExists(cacheDir)) {
runProgram("git", true, { "-c", "init.defaultBranch=" + gitInitialBranch, "init", "--bare", repoDir });
}
- deleteLockFile(cacheDirLock, lock.get());
-
Path localRefFile =
input.getRef()->compare(0, 5, "refs/") == 0
? cacheDir + "/" + *input.getRef()
@@ -399,6 +395,8 @@ struct GitInputScheme : InputScheme
if (!input.getRev())
input.attrs.insert_or_assign("rev", Hash::parseAny(chomp(readFile(localRefFile)), htSHA1).gitRev());
+
+ // cache dir lock is removed at scope end; we will only use read-only operations on specific revisions in the remainder
}
bool isShallow = chomp(runProgram("git", true, { "-C", repoDir, "rev-parse", "--is-shallow-repository" })) == "true";