about summary refs log tree commit diff
path: root/src/store.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-08-04T07·09+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-08-04T07·09+0000
commitd2e963f7a39cebcc4c937f9060763386d72ce4db (patch)
treed22f9d217de7e76a12ff4ebeadc14c62192946f3 /src/store.cc
parentc95b4ad2906ce4076f04e0969b7080c0589a8cea (diff)
* Path locking in addToStore() and expandPath().
Diffstat (limited to 'src/store.cc')
-rw-r--r--src/store.cc15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/store.cc b/src/store.cc
index 2411a737fab7..8a3db12ba93e 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();