about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--.gitignore13
-rw-r--r--src/libexpr/names.cc4
-rw-r--r--src/libexpr/names.hh4
-rw-r--r--src/libexpr/primops.cc22
-rw-r--r--src/libstore/download.cc2
-rw-r--r--src/libstore/http-binary-cache-store.cc2
-rw-r--r--src/libutil/archive.cc2
-rw-r--r--src/libutil/regex.cc50
-rw-r--r--src/libutil/regex.hh29
-rwxr-xr-xsrc/nix-build/nix-build.cc10
-rw-r--r--tests/common.sh.in2
-rw-r--r--tests/simple.sh2
12 files changed, 32 insertions, 110 deletions
diff --git a/.gitignore b/.gitignore
index 04dd791964f2..9b4ae6e151cd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -34,14 +34,7 @@ Makefile.config
 
 # /scripts/
 /scripts/nix-profile.sh
-/scripts/nix-switch
-/scripts/nix-collect-garbage
-/scripts/nix-prefetch-url
 /scripts/nix-copy-closure
-/scripts/NixConfig.pm
-/scripts/NixManifest.pm
-/scripts/download-from-binary-cache.pl
-/scripts/find-runtime-roots.pl
 /scripts/build-remote.pl
 /scripts/nix-reduce-build
 /scripts/nix-http-export.cgi
@@ -58,6 +51,8 @@ Makefile.config
 /src/libstore/schema.sql.hh
 /src/libstore/sandbox-defaults.sb
 
+/src/nix/nix
+
 # /src/nix-env/
 /src/nix-env/nix-env
 
@@ -67,9 +62,13 @@ Makefile.config
 # /src/nix-store/
 /src/nix-store/nix-store
 
+/src/nix-prefetch-url/nix-prefetch-url
+
 # /src/nix-daemon/
 /src/nix-daemon/nix-daemon
 
+/src/nix-collect-garbage/nix-collect-garbage
+
 # /src/nix-channel/
 /src/nix-channel/nix-channel
 
diff --git a/src/libexpr/names.cc b/src/libexpr/names.cc
index 7bca9b6550be..6d78d2116121 100644
--- a/src/libexpr/names.cc
+++ b/src/libexpr/names.cc
@@ -33,8 +33,8 @@ DrvName::DrvName(const string & s) : hits(0)
 bool DrvName::matches(DrvName & n)
 {
     if (name != "*") {
-        if (!regex) regex = std::shared_ptr<Regex>(new Regex(name));
-        if (!regex->matches(n.name)) return false;
+        if (!regex) regex = std::unique_ptr<std::regex>(new std::regex(name, std::regex::extended));
+        if (!std::regex_match(n.name, *regex)) return false;
     }
     if (version != "" && version != n.version) return false;
     return true;
diff --git a/src/libexpr/names.hh b/src/libexpr/names.hh
index 4b3dcddf70d7..9667fc96fd0f 100644
--- a/src/libexpr/names.hh
+++ b/src/libexpr/names.hh
@@ -3,7 +3,7 @@
 #include <memory>
 
 #include "types.hh"
-#include "regex.hh"
+#include <regex>
 
 namespace nix {
 
@@ -19,7 +19,7 @@ struct DrvName
     bool matches(DrvName & n);
 
 private:
-    std::shared_ptr<Regex> regex;
+    std::unique_ptr<std::regex> regex;
 };
 
 typedef list<DrvName> DrvNames;
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 377fb8c75eb4..5ba9830423b0 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -18,6 +18,7 @@
 
 #include <algorithm>
 #include <cstring>
+#include <regex>
 #include <dlfcn.h>
 
 
@@ -1618,25 +1619,26 @@ static void prim_hashString(EvalState & state, const Pos & pos, Value * * args,
    ‘null’ or a list containing substring matches. */
 static void prim_match(EvalState & state, const Pos & pos, Value * * args, Value & v)
 {
-    Regex regex(state.forceStringNoCtx(*args[0], pos), true);
+    std::regex regex(state.forceStringNoCtx(*args[0], pos), std::regex::extended);
 
     PathSet context;
-    string s = state.forceString(*args[1], context, pos);
+    const std::string str = state.forceString(*args[1], context, pos);
+
 
-    Regex::Subs subs;
-    if (!regex.matches(s, subs)) {
+    std::smatch match;
+    if (!std::regex_match(str, match, regex)) {
         mkNull(v);
         return;
     }
 
-    unsigned int len = subs.empty() ? 0 : subs.rbegin()->first + 1;
+    // the first match is the whole string
+    const size_t len = match.size() - 1;
     state.mkList(v, len);
-    for (unsigned int n = 0; n < len; ++n) {
-        auto i = subs.find(n);
-        if (i == subs.end())
-            mkNull(*(v.listElems()[n] = state.allocValue()));
+    for (size_t i = 0; i < len; ++i) {
+        if (!match[i+1].matched)
+            mkNull(*(v.listElems()[i] = state.allocValue()));
         else
-            mkString(*(v.listElems()[n] = state.allocValue()), i->second);
+            mkString(*(v.listElems()[i] = state.allocValue()), match[i + 1].str().c_str());
     }
 }
 
diff --git a/src/libstore/download.cc b/src/libstore/download.cc
index 317ec37d16af..c01ba63ef3c2 100644
--- a/src/libstore/download.cc
+++ b/src/libstore/download.cc
@@ -340,7 +340,7 @@ struct CurlDownloader : public Downloader
     {
         std::map<CURL *, std::shared_ptr<DownloadItem>> items;
 
-        bool quit;
+        bool quit = false;
 
         std::chrono::steady_clock::time_point nextWakeup;
 
diff --git a/src/libstore/http-binary-cache-store.cc b/src/libstore/http-binary-cache-store.cc
index 74ae7a4d198a..9d31f77c921f 100644
--- a/src/libstore/http-binary-cache-store.cc
+++ b/src/libstore/http-binary-cache-store.cc
@@ -71,7 +71,7 @@ protected:
 
     void getFile(const std::string & path,
         std::function<void(std::shared_ptr<std::string>)> success,
-        std::function<void(std::exception_ptr exc)> failure)
+        std::function<void(std::exception_ptr exc)> failure) override
     {
         DownloadRequest request(cacheUri + "/" + path);
         request.showProgress = DownloadRequest::no;
diff --git a/src/libutil/archive.cc b/src/libutil/archive.cc
index b9b26c5f5f98..fbba7f853f95 100644
--- a/src/libutil/archive.cc
+++ b/src/libutil/archive.cc
@@ -1,5 +1,3 @@
-#define _XOPEN_SOURCE 600
-
 #include "config.h"
 
 #include <cerrno>
diff --git a/src/libutil/regex.cc b/src/libutil/regex.cc
deleted file mode 100644
index 84274b3e1da9..000000000000
--- a/src/libutil/regex.cc
+++ /dev/null
@@ -1,50 +0,0 @@
-#include "regex.hh"
-#include "types.hh"
-
-#include <algorithm>
-
-namespace nix {
-
-Regex::Regex(const string & pattern, bool subs)
-{
-    /* Patterns must match the entire string. */
-    int err = regcomp(&preg, ("^(" + pattern + ")$").c_str(), (subs ? 0 : REG_NOSUB) | REG_EXTENDED);
-    if (err) throw RegexError(format("compiling pattern ‘%1%’: %2%") % pattern % showError(err));
-    nrParens = subs ? std::count(pattern.begin(), pattern.end(), '(') : 0;
-}
-
-Regex::~Regex()
-{
-    regfree(&preg);
-}
-
-bool Regex::matches(const string & s)
-{
-    int err = regexec(&preg, s.c_str(), 0, 0, 0);
-    if (err == 0) return true;
-    else if (err == REG_NOMATCH) return false;
-    throw Error(format("matching string ‘%1%’: %2%") % s % showError(err));
-}
-
-bool Regex::matches(const string & s, Subs & subs)
-{
-    regmatch_t pmatch[nrParens + 2];
-    int err = regexec(&preg, s.c_str(), nrParens + 2, pmatch, 0);
-    if (err == 0) {
-        for (unsigned int n = 2; n < nrParens + 2; ++n)
-            if (pmatch[n].rm_eo != -1)
-                subs[n - 2] = string(s, pmatch[n].rm_so, pmatch[n].rm_eo - pmatch[n].rm_so);
-        return true;
-    }
-    else if (err == REG_NOMATCH) return false;
-    throw Error(format("matching string ‘%1%’: %2%") % s % showError(err));
-}
-
-string Regex::showError(int err)
-{
-    char buf[256];
-    regerror(err, &preg, buf, sizeof(buf));
-    return string(buf);
-}
-
-}
diff --git a/src/libutil/regex.hh b/src/libutil/regex.hh
deleted file mode 100644
index 53e31f4edc4a..000000000000
--- a/src/libutil/regex.hh
+++ /dev/null
@@ -1,29 +0,0 @@
-#pragma once
-
-#include "types.hh"
-
-#include <sys/types.h>
-#include <regex.h>
-
-#include <map>
-
-namespace nix {
-
-MakeError(RegexError, Error)
-
-class Regex
-{
-public:
-    Regex(const string & pattern, bool subs = false);
-    ~Regex();
-    bool matches(const string & s);
-    typedef std::map<unsigned int, string> Subs;
-    bool matches(const string & s, Subs & subs);
-
-private:
-    unsigned nrParens;
-    regex_t preg;
-    string showError(int err);
-};
-
-}
diff --git a/src/nix-build/nix-build.cc b/src/nix-build/nix-build.cc
index b209464b8279..08c6793577a4 100755
--- a/src/nix-build/nix-build.cc
+++ b/src/nix-build/nix-build.cc
@@ -16,6 +16,8 @@
 
 using namespace nix;
 
+extern char * * environ;
+
 /* Recreate the effect of the perl shellwords function, breaking up a
  * string into arguments like a shell word, including escapes
  */
@@ -448,9 +450,10 @@ int main(int argc, char ** argv)
                     ? Strings{"bash", "--rcfile", rcfile}
                     : Strings{"bash", rcfile};
 
-                execvpe(getEnv("NIX_BUILD_SHELL", "bash").c_str(),
-                        stringsToCharPtrs(args).data(),
-                        stringsToCharPtrs(envStrs).data());
+                environ = stringsToCharPtrs(envStrs).data();
+
+                execvp(getEnv("NIX_BUILD_SHELL", "bash").c_str(),
+                    stringsToCharPtrs(args).data());
 
                 throw SysError("executing shell");
             }
@@ -507,4 +510,3 @@ int main(int argc, char ** argv)
         }
     });
 }
-
diff --git a/tests/common.sh.in b/tests/common.sh.in
index 316d5f6896bb..4565a490adfd 100644
--- a/tests/common.sh.in
+++ b/tests/common.sh.in
@@ -2,7 +2,7 @@ set -e
 
 datadir="@datadir@"
 
-export TEST_ROOT=${TMPDIR:-/tmp}/nix-test
+export TEST_ROOT=$(realpath ${TMPDIR:-/tmp}/nix-test)
 export NIX_STORE_DIR
 if ! NIX_STORE_DIR=$(readlink -f $TEST_ROOT/store 2> /dev/null); then
     # Maybe the build directory is symlinked.
diff --git a/tests/simple.sh b/tests/simple.sh
index 8f9d782a6c81..37631b648c67 100644
--- a/tests/simple.sh
+++ b/tests/simple.sh
@@ -18,7 +18,7 @@ if test "$text" != "Hello World!"; then exit 1; fi
 nix-store --delete $outPath
 if test -e $outPath/hello; then false; fi
 
-outPath="$(NIX_REMOTE=local?store=/foo\&real=$TMPDIR/real-store nix-instantiate --readonly-mode hash-check.nix)"
+outPath="$(NIX_REMOTE=local?store=/foo\&real=$TEST_ROOT/real-store nix-instantiate --readonly-mode hash-check.nix)"
 if test "$outPath" != "/foo/lfy1s6ca46rm5r6w4gg9hc0axiakjcnm-dependencies.drv"; then
     echo "hashDerivationModulo appears broken, got $outPath"
     exit 1