about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/expr.cc13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/expr.cc b/src/expr.cc
index 2ed3e678b39f..521dffc9c693 100644
--- a/src/expr.cc
+++ b/src/expr.cc
@@ -37,12 +37,15 @@ Path writeTerm(ATerm t, const string & suffix)
 
     Path path = canonPath(nixStore + "/" + 
         (string) h + suffix + ".nix");
-    if (!ATwriteToNamedTextFile(t, path.c_str()))
-        throw Error(format("cannot write aterm %1%") % path);
 
-    Transaction txn(nixDB);
-    registerValidPath(txn, path);
-    txn.commit();
+    if (!isValidPath(path)) {
+        if (!ATwriteToNamedTextFile(t, path.c_str()))
+            throw Error(format("cannot write aterm %1%") % path);
+
+        Transaction txn(nixDB);
+        registerValidPath(txn, path);
+        txn.commit();
+    }
 
     return path;
 }