From d2e963f7a39cebcc4c937f9060763386d72ce4db Mon Sep 17 00:00:00 2001
From: Eelco Dolstra <e.dolstra@tudelft.nl>
Date: Mon, 4 Aug 2003 07:09:36 +0000
Subject: * Path locking in addToStore() and expandPath().

---
 src/normalise.cc |  2 +-
 src/store.cc     | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

(limited to 'src')

diff --git a/src/normalise.cc b/src/normalise.cc
index 074eda2960..3f138a53ea 100644
--- a/src/normalise.cc
+++ b/src/normalise.cc
@@ -86,7 +86,7 @@ FSId normaliseFState(FSId id, FSIdSet pending)
 
     /* Obtain locks on all output paths.  The locks are automatically
        released when we exit this function or Nix crashes. */
-    PathLocks outputLock(pathsFromOutPaths(outPaths));
+    PathLocks outputLocks(pathsFromOutPaths(outPaths));
 
     /* Now check again whether there is a successor.  This is because
        another process may have started building in parallel.  After
diff --git a/src/store.cc b/src/store.cc
index 2411a737fa..8a3db12ba9 100644
--- a/src/store.cc
+++ b/src/store.cc
@@ -7,6 +7,7 @@
 #include "globals.hh"
 #include "db.hh"
 #include "archive.hh"
+#include "pathlocks.hh"
 #include "normalise.hh"
 
 
@@ -211,10 +212,19 @@ string expandId(const FSId & id, const string & target,
             if (target.empty())
                 return path;
             else {
+                /* Acquire a lock on the target path. */
+                Strings lockPaths;
+                lockPaths.push_back(target);
+                PathLocks outputLock(lockPaths);
+
+                /* Copy. */
                 copyPath(path, target);
+
+                /* Register the target path. */
                 Transaction txn(nixDB);
                 registerPath(txn, target, id);
                 txn.commit();
+
                 return target;
             }
         }
@@ -265,7 +275,12 @@ void addToStore(string srcPath, string & dstPath, FSId & id,
     } catch (...) {
     }
     
+    Strings lockPaths;
+    lockPaths.push_back(dstPath);
+    PathLocks outputLock(lockPaths);
+
     copyPath(srcPath, dstPath);
+
     Transaction txn(nixDB);
     registerPath(txn, dstPath, id);
     txn.commit();
-- 
cgit 1.4.1