about summary refs log tree commit diff
path: root/src/nix/search.cc
diff options
context:
space:
mode:
authorShea Levy <shea@shealevy.com>2018-03-14T00·43-0600
committerGitHub <noreply@github.com>2018-03-14T00·43-0600
commit56f2ed00813f49e2834076787f98438a976eebb1 (patch)
treeea268ddc8d183563ea03d1b9f209f48efbbe5998 /src/nix/search.cc
parent7afdc8d4a100d26cd09f7d63c0fe915b4d6a53c9 (diff)
parentc577186f5916c90193368492f1c4180a1386febc (diff)
Merge pull request #1906 from dtzWill/fix/nix-search
nix search: tests and fix #1893 and part of #1892
Diffstat (limited to 'src/nix/search.cc')
-rw-r--r--src/nix/search.cc7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/nix/search.cc b/src/nix/search.cc
index 0fbd3b6c073a..5ccf1b7cf529 100644
--- a/src/nix/search.cc
+++ b/src/nix/search.cc
@@ -78,6 +78,11 @@ struct CmdSearch : SourceExprCommand, MixJSON
     {
         settings.readOnlyMode = true;
 
+        // Empty search string should match all packages
+        // Use "^" here instead of ".*" due to differences in resulting highlighting
+        // (see #1893 -- libc++ claims empty search string is not in POSIX grammar)
+        if (re.empty()) re = "^";
+
         std::regex regex(re, std::regex::extended | std::regex::icase);
 
         auto state = getEvalState();
@@ -234,7 +239,7 @@ struct CmdSearch : SourceExprCommand, MixJSON
                     throw Error("error writing to %s", tmpFile);
             }
 
-            if (rename(tmpFile.c_str(), jsonCacheFileName.c_str()) == -1)
+            if (writeCache && rename(tmpFile.c_str(), jsonCacheFileName.c_str()) == -1)
                 throw SysError("cannot rename '%s' to '%s'", tmpFile, jsonCacheFileName);
         }