* Fix a race condition in addTextToStore().

This commit is contained in:
Eelco Dolstra 2003-10-23 10:51:55 +00:00
parent c4e7d324b8
commit 92eea8fc4e

View file

@ -302,7 +302,11 @@ void addTextToStore(const Path & dstPath, const string & s)
{ {
if (!isValidPath(dstPath)) { 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); AutoCloseFD fd = open(dstPath.c_str(), O_CREAT | O_EXCL | O_WRONLY, 0666);
if (fd == -1) throw SysError(format("creating store file `%1%'") % dstPath); if (fd == -1) throw SysError(format("creating store file `%1%'") % dstPath);
@ -313,6 +317,7 @@ void addTextToStore(const Path & dstPath, const string & s)
registerValidPath(txn, dstPath); registerValidPath(txn, dstPath);
txn.commit(); txn.commit();
} }
}
} }