about summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-08-05T22·17-0400
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-08-05T22·17-0400
commit108e14bb189fd0fb291d3494f9f3915070a7052e (patch)
tree6b216028b05174e69ff5adea75182dec618b1619 /src/libstore
parent6763084ae53fc0228d50ab94bbbced89c1b14f1c (diff)
Fix race condition when two processes create the same link in /nix/store/.links
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/optimise-store.cc8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/libstore/optimise-store.cc b/src/libstore/optimise-store.cc
index c05447f4a27f..b9b878d2a45b 100644
--- a/src/libstore/optimise-store.cc
+++ b/src/libstore/optimise-store.cc
@@ -102,11 +102,11 @@ void LocalStore::optimisePath_(OptimiseStats & stats, const Path & path)
         /* Nope, create a hard link in the links directory. */
         makeMutable(path);
         MakeImmutable mk1(path);
-
-        if (link(path.c_str(), linkPath.c_str()) == -1)
+        if (link(path.c_str(), linkPath.c_str()) == 0) return;
+        if (errno != EEXIST)
             throw SysError(format("cannot link `%1%' to `%2%'") % linkPath % path);
-
-        return;
+        /* Fall through if another process created ‘linkPath’ before
+           we did. */
     }
 
     /* Yes!  We've seen a file with the same contents.  Replace the