Fix race condition when two processes create the same link in /nix/store/.links
This commit is contained in:
parent
6763084ae5
commit
108e14bb18
1 changed files with 4 additions and 4 deletions
|
@ -102,11 +102,11 @@ void LocalStore::optimisePath_(OptimiseStats & stats, const Path & path)
|
||||||
/* Nope, create a hard link in the links directory. */
|
/* Nope, create a hard link in the links directory. */
|
||||||
makeMutable(path);
|
makeMutable(path);
|
||||||
MakeImmutable mk1(path);
|
MakeImmutable mk1(path);
|
||||||
|
if (link(path.c_str(), linkPath.c_str()) == 0) return;
|
||||||
if (link(path.c_str(), linkPath.c_str()) == -1)
|
if (errno != EEXIST)
|
||||||
throw SysError(format("cannot link `%1%' to `%2%'") % linkPath % path);
|
throw SysError(format("cannot link `%1%' to `%2%'") % linkPath % path);
|
||||||
|
/* Fall through if another process created ‘linkPath’ before
|
||||||
return;
|
we did. */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Yes! We've seen a file with the same contents. Replace the
|
/* Yes! We've seen a file with the same contents. Replace the
|
||||||
|
|
Loading…
Reference in a new issue