aboutsummaryrefslogtreecommitdiff
path: root/src/libutil
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/logging.cc8
-rw-r--r--src/libutil/logging.hh3
-rw-r--r--src/libutil/lru-cache.hh8
-rw-r--r--src/libutil/serialise.cc3
-rw-r--r--src/libutil/util.cc7
-rw-r--r--src/libutil/util.hh3
6 files changed, 25 insertions, 7 deletions
diff --git a/src/libutil/logging.cc b/src/libutil/logging.cc
index 27a631a37..c1cff5cf9 100644
--- a/src/libutil/logging.cc
+++ b/src/libutil/logging.cc
@@ -221,4 +221,12 @@ bool handleJSONLogMessage(const std::string & msg,
return true;
}
+Activity::~Activity() {
+ try {
+ logger.stopActivity(id);
+ } catch (...) {
+ ignoreException();
+ }
+}
+
}
diff --git a/src/libutil/logging.hh b/src/libutil/logging.hh
index 677aa4dae..ca768d555 100644
--- a/src/libutil/logging.hh
+++ b/src/libutil/logging.hh
@@ -94,8 +94,7 @@ struct Activity
Activity(const Activity & act) = delete;
- ~Activity()
- { logger.stopActivity(id); }
+ ~Activity();
void progress(uint64_t done = 0, uint64_t expected = 0, uint64_t running = 0, uint64_t failed = 0) const
{ result(resProgress, done, expected, running, failed); }
diff --git a/src/libutil/lru-cache.hh b/src/libutil/lru-cache.hh
index 3cb5d5088..9b8290e63 100644
--- a/src/libutil/lru-cache.hh
+++ b/src/libutil/lru-cache.hh
@@ -2,6 +2,7 @@
#include <map>
#include <list>
+#include <experimental/optional>
namespace nix {
@@ -63,18 +64,17 @@ public:
/* Look up an item in the cache. If it exists, it becomes the most
recently used item. */
- // FIXME: use boost::optional?
- Value * get(const Key & key)
+ std::experimental::optional<Value> get(const Key & key)
{
auto i = data.find(key);
- if (i == data.end()) return 0;
+ if (i == data.end()) return {};
/* Move this item to the back of the LRU list. */
lru.erase(i->second.first.it);
auto j = lru.insert(lru.end(), i);
i->second.first.it = j;
- return &i->second.second;
+ return i->second.second;
}
size_t size()
diff --git a/src/libutil/serialise.cc b/src/libutil/serialise.cc
index 950e6362a..9e2a502af 100644
--- a/src/libutil/serialise.cc
+++ b/src/libutil/serialise.cc
@@ -67,7 +67,8 @@ void FdSink::write(const unsigned char * data, size_t len)
try {
writeFull(fd, data, len);
} catch (SysError & e) {
- _good = true;
+ _good = false;
+ throw;
}
}
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 341dedfdf..2391e14a9 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -73,6 +73,13 @@ std::map<std::string, std::string> getEnv()
}
+void clearEnv()
+{
+ for (auto & name : getEnv())
+ unsetenv(name.first.c_str());
+}
+
+
Path absPath(Path path, Path dir)
{
if (path[0] != '/') {
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index 47e02bc89..c5c537ee6 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -32,6 +32,9 @@ string getEnv(const string & key, const string & def = "");
/* Get the entire environment. */
std::map<std::string, std::string> getEnv();
+/* Clear the environment. */
+void clearEnv();
+
/* Return an absolutized path, resolving paths relative to the
specified directory, or the current directory otherwise. The path
is also canonicalised. */