mirror of
https://github.com/NixOS/nix.git
synced 2025-12-03 15:40:59 +01:00
* Some wrapper classes to ensure that file descriptors / directory
handles are closed when they go out of scope.
This commit is contained in:
parent
c62433751d
commit
4a8948b7a6
6 changed files with 123 additions and 56 deletions
|
|
@ -304,14 +304,12 @@ void addTextToStore(const Path & dstPath, const string & s)
|
|||
|
||||
/* !!! locking? -> parallel writes are probably idempotent */
|
||||
|
||||
int 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 (write(fd, s.c_str(), s.size()) != (ssize_t) s.size())
|
||||
throw SysError(format("writing store file `%1%'") % dstPath);
|
||||
|
||||
close(fd); /* !!! close on exception */
|
||||
|
||||
Transaction txn(nixDB);
|
||||
registerValidPath(txn, dstPath);
|
||||
txn.commit();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue