From 99ed558a93216288e50b11132f2a00a74cc6bb7f Mon Sep 17 00:00:00 2001
From: Eelco Dolstra <eelco.dolstra@logicblox.com>
Date: Tue, 22 Jan 2013 22:07:25 +0100
Subject: [PATCH] Correctly handle missing logs

---
 src/nix-store/nix-store.cc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc
index 3e1946e8d..8d26fc784 100644
--- a/src/nix-store/nix-store.cc
+++ b/src/nix-store/nix-store.cc
@@ -460,7 +460,7 @@ static void opReadLog(Strings opFlags, Strings opArgs)
     foreach (Strings::iterator, i, opArgs) {
         Path path = useDeriver(followLinksToStorePath(*i));
 
-        for (int j = 0; j < 2; j++) {
+        for (int j = 0; j <= 2; j++) {
             if (j == 2) throw Error(format("build log of derivation `%1%' is not available") % path);
 
             string baseName = baseNameOf(path);
@@ -474,6 +474,7 @@ static void opReadLog(Strings opFlags, Strings opArgs)
                 /* !!! Make this run in O(1) memory. */
                 string log = readFile(logPath);
                 writeFull(STDOUT_FILENO, (const unsigned char *) log.data(), log.size());
+                break;
             }
 
             else if (pathExists(logBz2Path)) {
@@ -492,6 +493,7 @@ static void opReadLog(Strings opFlags, Strings opArgs)
                     writeFull(STDOUT_FILENO, buf, n);
                 } while (err != BZ_STREAM_END);
                 BZ2_bzReadClose(&err, bz);
+                break;
             }
         }
     }
-- 
GitLab