From 689ef502f5b0655c9923ed77da2ae3504630f473 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Wed, 20 May 2020 22:27:37 +0100 Subject: refactor(3p/nix): Apply clang-tidy's readability-* fixes This applies the readability fixes listed here: https://clang.llvm.org/extra/clang-tidy/checks/list.html --- third_party/nix/src/libstore/remote-store.cc | 60 ++++++++++++++-------------- 1 file changed, 29 insertions(+), 31 deletions(-) (limited to 'third_party/nix/src/libstore/remote-store.cc') diff --git a/third_party/nix/src/libstore/remote-store.cc b/third_party/nix/src/libstore/remote-store.cc index 564ba444d242..c4215800da8d 100644 --- a/third_party/nix/src/libstore/remote-store.cc +++ b/third_party/nix/src/libstore/remote-store.cc @@ -81,9 +81,8 @@ UDSRemoteStore::UDSRemoteStore(std::string socket_path, const Params& params) std::string UDSRemoteStore::getUri() { if (path) { return std::string("unix://") + *path; - } else { - return "daemon"; } + return "daemon"; } ref UDSRemoteStore::openConnection() { @@ -155,7 +154,7 @@ void RemoteStore::initConnection(Connection& conn) { } if (GET_PROTOCOL_MINOR(conn.daemonVersion) >= 11) { - conn.to << false; + conn.to << 0u; } auto ex = conn.processStderr(); @@ -171,17 +170,18 @@ void RemoteStore::initConnection(Connection& conn) { } void RemoteStore::setOptions(Connection& conn) { - conn.to << wopSetOptions << settings.keepFailed - << settings.keepGoing + conn.to << wopSetOptions << static_cast(settings.keepFailed) + << static_cast(settings.keepGoing) // TODO(tazjin): Remove the verbosity stuff here. - << settings.tryFallback << compat::kInfo << settings.maxBuildJobs - << settings.maxSilentTime - << true + << static_cast(settings.tryFallback) << compat::kInfo + << settings.maxBuildJobs << settings.maxSilentTime + << 1u // TODO(tazjin): what behaviour does this toggle remotely? << (settings.verboseBuild ? compat::kError : compat::kVomit) << 0 // obsolete log type << 0 /* obsolete print build trace */ - << settings.buildCores << settings.useSubstitutes; + << settings.buildCores + << static_cast(settings.useSubstitutes); if (GET_PROTOCOL_MINOR(conn.daemonVersion) >= 12) { std::map overrides; @@ -221,7 +221,7 @@ struct ConnectionHandle { ConnectionHandle(ConnectionHandle&& h) : handle(std::move(h.handle)) {} ~ConnectionHandle() { - if (!daemonException && std::uncaught_exceptions()) { + if (!daemonException && (std::uncaught_exceptions() != 0)) { handle.markBad(); // TODO(tazjin): are these types of things supposed to be DEBUG? DLOG(INFO) << "closing daemon connection because of an exception"; @@ -247,7 +247,7 @@ bool RemoteStore::isValidPathUncached(const Path& path) { auto conn(getConnection()); conn->to << wopIsValidPath << path; conn.processStderr(); - return readInt(conn->from); + return readInt(conn->from) != 0u; } PathSet RemoteStore::queryValidPaths(const PathSet& paths, @@ -261,11 +261,10 @@ PathSet RemoteStore::queryValidPaths(const PathSet& paths, } } return res; - } else { - conn->to << wopQueryValidPaths << paths; - conn.processStderr(); - return readStorePaths(*this, conn->from); } + conn->to << wopQueryValidPaths << paths; + conn.processStderr(); + return readStorePaths(*this, conn->from); } PathSet RemoteStore::queryAllValidPaths() { @@ -282,16 +281,15 @@ PathSet RemoteStore::querySubstitutablePaths(const PathSet& paths) { for (auto& i : paths) { conn->to << wopHasSubstitutes << i; conn.processStderr(); - if (readInt(conn->from)) { + if (readInt(conn->from) != 0u) { res.insert(i); } } return res; - } else { - conn->to << wopQuerySubstitutablePaths << paths; - conn.processStderr(); - return readStorePaths(*this, conn->from); } + conn->to << wopQuerySubstitutablePaths << paths; + conn.processStderr(); + return readStorePaths(*this, conn->from); } void RemoteStore::querySubstitutablePathInfos(const PathSet& paths, @@ -312,7 +310,7 @@ void RemoteStore::querySubstitutablePathInfos(const PathSet& paths, continue; } info.deriver = readString(conn->from); - if (info.deriver != "") { + if (!info.deriver.empty()) { assertStorePath(info.deriver); } info.references = readStorePaths(*this, conn->from); @@ -329,7 +327,7 @@ void RemoteStore::querySubstitutablePathInfos(const PathSet& paths, Path path = readStorePath(*this, conn->from); SubstitutablePathInfo& info(infos[path]); info.deriver = readString(conn->from); - if (info.deriver != "") { + if (!info.deriver.empty()) { assertStorePath(info.deriver); } info.references = readStorePaths(*this, conn->from); @@ -366,7 +364,7 @@ void RemoteStore::queryPathInfoUncached( info = std::make_shared(); info->path = path; info->deriver = readString(conn->from); - if (info->deriver != "") { + if (!info->deriver.empty()) { assertStorePath(info->deriver); } info->narHash = Hash(readString(conn->from), htSHA256); @@ -464,7 +462,7 @@ void RemoteStore::addToStore(const ValidPathInfo& info, Source& source, Path RemoteStore::addToStore(const string& name, const Path& _srcPath, bool recursive, HashType hashAlgo, PathFilter& filter, RepairFlag repair) { - if (repair) { + if (repair != 0u) { throw Error( "repairing is not supported when building through the Nix daemon"); } @@ -506,7 +504,7 @@ Path RemoteStore::addToStore(const string& name, const Path& _srcPath, Path RemoteStore::addTextToStore(const string& name, const string& s, const PathSet& references, RepairFlag repair) { - if (repair) { + if (repair != 0u) { throw Error( "repairing is not supported when building through the Nix daemon"); } @@ -593,7 +591,7 @@ Roots RemoteStore::findRoots(bool censor) { conn.processStderr(); auto count = readNum(conn->from); Roots result; - while (count--) { + while ((count--) != 0u) { Path link = readString(conn->from); Path target = readStorePath(*this, conn->from); result[target].emplace(link); @@ -605,7 +603,7 @@ void RemoteStore::collectGarbage(const GCOptions& options, GCResults& results) { auto conn(getConnection()); conn->to << wopCollectGarbage << options.action << options.pathsToDelete - << options.ignoreLiveness + << static_cast(options.ignoreLiveness) << options.maxFreed /* removed options */ << 0 << 0 << 0; @@ -631,9 +629,9 @@ void RemoteStore::optimiseStore() { bool RemoteStore::verifyStore(bool checkContents, RepairFlag repair) { auto conn(getConnection()); - conn->to << wopVerifyStore << checkContents << repair; + conn->to << wopVerifyStore << static_cast(checkContents) << repair; conn.processStderr(); - return readInt(conn->from); + return readInt(conn->from) != 0u; } void RemoteStore::addSignatures(const Path& storePath, const StringSet& sigs) { @@ -694,14 +692,14 @@ std::exception_ptr RemoteStore::Connection::processStderr(Sink* sink, if (msg == STDERR_WRITE) { string s = readString(from); - if (!sink) { + if (sink == nullptr) { throw Error("no sink"); } (*sink)(s); } else if (msg == STDERR_READ) { - if (!source) { + if (source == nullptr) { throw Error("no source"); } auto len = readNum(from); -- cgit 1.4.1