diff options
-rw-r--r-- | src/libnix/store.cc | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/libnix/store.cc b/src/libnix/store.cc index e32f403b6ca7..c83316cf6ad5 100644 --- a/src/libnix/store.cc +++ b/src/libnix/store.cc @@ -302,16 +302,21 @@ void addTextToStore(const Path & dstPath, const string & s) { if (!isValidPath(dstPath)) { - /* !!! locking? -> parallel writes are probably idempotent */ + PathSet lockPaths; + lockPaths.insert(dstPath); + PathLocks outputLock(lockPaths); + + if (!isValidPath(dstPath)) { - AutoCloseFD fd = open(dstPath.c_str(), O_CREAT | O_EXCL | O_WRONLY, 0666); - if (fd == -1) throw SysError(format("creating store file `%1%'") % dstPath); + AutoCloseFD fd = open(dstPath.c_str(), O_CREAT | O_EXCL | O_WRONLY, 0666); + if (fd == -1) throw SysError(format("creating store file `%1%'") % dstPath); - writeFull(fd, (unsigned char *) s.c_str(), s.size()); + writeFull(fd, (unsigned char *) s.c_str(), s.size()); - Transaction txn(nixDB); - registerValidPath(txn, dstPath); - txn.commit(); + Transaction txn(nixDB); + registerValidPath(txn, dstPath); + txn.commit(); + } } } |