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".
This commit is contained in:
Will Dietz 2018-02-25 16:32:36 -06:00
parent 8282c60d74
commit 3cac8734ac

View file

@ -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);
}
}