mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-25 23:36:16 +02:00
Merge pull request #5082 from manveru/fix-git-init-race
fix git init race condition
This commit is contained in:
commit
47e96bb533
1 changed files with 8 additions and 1 deletions
|
@ -4,6 +4,7 @@
|
||||||
#include "tarfile.hh"
|
#include "tarfile.hh"
|
||||||
#include "store-api.hh"
|
#include "store-api.hh"
|
||||||
#include "url-parts.hh"
|
#include "url-parts.hh"
|
||||||
|
#include "pathlocks.hh"
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
@ -317,11 +318,17 @@ struct GitInputScheme : InputScheme
|
||||||
Path cacheDir = getCacheDir() + "/nix/gitv3/" + hashString(htSHA256, actualUrl).to_string(Base32, false);
|
Path cacheDir = getCacheDir() + "/nix/gitv3/" + hashString(htSHA256, actualUrl).to_string(Base32, false);
|
||||||
repoDir = cacheDir;
|
repoDir = cacheDir;
|
||||||
|
|
||||||
|
Path cacheDirLock = cacheDir + ".lock";
|
||||||
|
createDirs(dirOf(cacheDir));
|
||||||
|
AutoCloseFD lock = openLockFile(cacheDirLock, true);
|
||||||
|
lockFile(lock.get(), ltWrite, true);
|
||||||
|
|
||||||
if (!pathExists(cacheDir)) {
|
if (!pathExists(cacheDir)) {
|
||||||
createDirs(dirOf(cacheDir));
|
|
||||||
runProgram("git", true, { "init", "--bare", repoDir });
|
runProgram("git", true, { "init", "--bare", repoDir });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteLockFile(cacheDirLock, lock.get());
|
||||||
|
|
||||||
Path localRefFile =
|
Path localRefFile =
|
||||||
input.getRef()->compare(0, 5, "refs/") == 0
|
input.getRef()->compare(0, 5, "refs/") == 0
|
||||||
? cacheDir + "/" + *input.getRef()
|
? cacheDir + "/" + *input.getRef()
|
||||||
|
|
Loading…
Reference in a new issue