From 3cac8734acb098488bd232bcee92099410d4d167 Mon Sep 17 00:00:00 2001 From: Will Dietz Date: Sun, 25 Feb 2018 16:32:36 -0600 Subject: nix search: fix bug where we wrote to cache when shouldn't, breaking This is exposed by the tests added previously, and resolves the error reported in #1892: "expected JSON value". --- src/nix/search.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nix/search.cc') diff --git a/src/nix/search.cc b/src/nix/search.cc index 87cdb2d7ed8a..1adde28cb3ca 100644 --- a/src/nix/search.cc +++ b/src/nix/search.cc @@ -237,7 +237,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); } } -- cgit 1.4.1 From 009cf9cd23e5b9198cf8977cca7c823b6b95ad5b Mon Sep 17 00:00:00 2001 From: Will Dietz Date: Sun, 25 Feb 2018 16:38:13 -0600 Subject: nix search: explicitly handle empty search string, fixes #1893 This is important since this is given as an example. Other patterns containing "empty search string" will still be handled differently on different platforms ("asdf|") but that's less of an issue. --- src/nix/search.cc | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/nix/search.cc') diff --git a/src/nix/search.cc b/src/nix/search.cc index 1adde28cb3ca..009dfae9cf40 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(); -- cgit 1.4.1