about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2018-04-16T09·14+0200
committerEelco Dolstra <edolstra@gmail.com>2018-05-30T11·48+0200
commit3c2de9830dfa9e41927c666b7a7083c53886fb89 (patch)
tree766bce69e8c0e60ae2970c5639ace94bd4cd7702
parenta4c16188760fde2122df534f5db6b9ef26c9bc22 (diff)
RemoteStore::addToStore(): Ensure capacity is decreased on exceptions
-rw-r--r--src/libstore/remote-store.cc7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc
index 76b5660355ed..ea86ef052f53 100644
--- a/src/libstore/remote-store.cc
+++ b/src/libstore/remote-store.cc
@@ -7,6 +7,7 @@
 #include "globals.hh"
 #include "derivations.hh"
 #include "pool.hh"
+#include "finally.hh"
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -439,8 +440,10 @@ Path RemoteStore::addToStore(const string & name, const Path & _srcPath,
         conn->to.written = 0;
         conn->to.warn = true;
         connections->incCapacity();
-        dumpPath(srcPath, conn->to, filter);
-        connections->decCapacity();
+        {
+            Finally cleanup([&]() { connections->decCapacity(); });
+            dumpPath(srcPath, conn->to, filter);
+        }
         conn->to.warn = false;
         conn->processStderr();
     } catch (SysError & e) {