daemon: Flush the sink upon 'exportPath' errors.

Prior to this change, errors such as wrong permissions on
/etc/guix/signing-key.sec would give:

  guix-daemon: nix/libutil/serialise.cc:15: virtual nix::BufferedSink::~BufferedSink(): Assertion `!bufPos' failed.

This patch correctly propagates the error to the client and thus changes
that to:

  error: build failed: file `/etc/guix/signing-key.sec' should be secret (inaccessible to everybody else)!

* nix/nix-daemon/nix-daemon.cc (performOp): Wrap 'exportPath' call in
'try' block.

Co-authored-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
Jan Nieuwenhuizen 2017-07-17 15:00:01 +02:00 committed by Ludovic Courtès
parent 7ad2a4f1d5
commit 2e009ae7cd
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
1 changed files with 9 additions and 1 deletions

View File

@ -436,7 +436,15 @@ static void performOp(bool trusted, unsigned int clientVersion,
bool sign = readInt(from) == 1;
startWork();
TunnelSink sink(to);
store->exportPath(path, sign, sink);
try {
store->exportPath(path, sign, sink);
}
catch (Error &e) {
/* Flush SINK beforehand or its destructor will rightfully trigger
an assertion failure. */
sink.flush();
throw e;
}
sink.flush();
stopWork();
writeInt(1, to);