From 0f2cf531f705d370321843e5ba9135b2ebdb5d19 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 17 May 2020 16:31:57 +0100 Subject: style(3p/nix): Reformat project in Google C++ style Reformatted with: fd . -e hh -e cc | xargs clang-format -i --- third_party/nix/src/libstore/export-import.cc | 142 ++++++++++++-------------- 1 file changed, 68 insertions(+), 74 deletions(-) (limited to 'third_party/nix/src/libstore/export-import.cc') diff --git a/third_party/nix/src/libstore/export-import.cc b/third_party/nix/src/libstore/export-import.cc index ef3fea7c838b..b38b15c6f3bc 100644 --- a/third_party/nix/src/libstore/export-import.cc +++ b/third_party/nix/src/libstore/export-import.cc @@ -1,106 +1,100 @@ -#include "store-api.hh" +#include #include "archive.hh" +#include "store-api.hh" #include "worker-protocol.hh" -#include - namespace nix { -struct HashAndWriteSink : Sink -{ - Sink & writeSink; - HashSink hashSink; - HashAndWriteSink(Sink & writeSink) : writeSink(writeSink), hashSink(htSHA256) - { - } - virtual void operator () (const unsigned char * data, size_t len) - { - writeSink(data, len); - hashSink(data, len); - } - Hash currentHash() - { - return hashSink.currentHash().first; - } +struct HashAndWriteSink : Sink { + Sink& writeSink; + HashSink hashSink; + HashAndWriteSink(Sink& writeSink) + : writeSink(writeSink), hashSink(htSHA256) {} + virtual void operator()(const unsigned char* data, size_t len) { + writeSink(data, len); + hashSink(data, len); + } + Hash currentHash() { return hashSink.currentHash().first; } }; -void Store::exportPaths(const Paths & paths, Sink & sink) -{ - Paths sorted = topoSortPaths(PathSet(paths.begin(), paths.end())); - std::reverse(sorted.begin(), sorted.end()); +void Store::exportPaths(const Paths& paths, Sink& sink) { + Paths sorted = topoSortPaths(PathSet(paths.begin(), paths.end())); + std::reverse(sorted.begin(), sorted.end()); - std::string doneLabel("paths exported"); - //logger->incExpected(doneLabel, sorted.size()); + std::string doneLabel("paths exported"); + // logger->incExpected(doneLabel, sorted.size()); - for (auto & path : sorted) { - //Activity act(*logger, lvlInfo, format("exporting path '%s'") % path); - sink << 1; - exportPath(path, sink); - //logger->incProgress(doneLabel); - } + for (auto& path : sorted) { + // Activity act(*logger, lvlInfo, format("exporting path '%s'") % path); + sink << 1; + exportPath(path, sink); + // logger->incProgress(doneLabel); + } - sink << 0; + sink << 0; } -void Store::exportPath(const Path & path, Sink & sink) -{ - auto info = queryPathInfo(path); +void Store::exportPath(const Path& path, Sink& sink) { + auto info = queryPathInfo(path); - HashAndWriteSink hashAndWriteSink(sink); + HashAndWriteSink hashAndWriteSink(sink); - narFromPath(path, hashAndWriteSink); + narFromPath(path, hashAndWriteSink); - /* Refuse to export paths that have changed. This prevents - filesystem corruption from spreading to other machines. - Don't complain if the stored hash is zero (unknown). */ - Hash hash = hashAndWriteSink.currentHash(); - if (hash != info->narHash && info->narHash != Hash(info->narHash.type)) - throw Error(format("hash of path '%1%' has changed from '%2%' to '%3%'!") % path - % info->narHash.to_string() % hash.to_string()); + /* Refuse to export paths that have changed. This prevents + filesystem corruption from spreading to other machines. + Don't complain if the stored hash is zero (unknown). */ + Hash hash = hashAndWriteSink.currentHash(); + if (hash != info->narHash && info->narHash != Hash(info->narHash.type)) + throw Error(format("hash of path '%1%' has changed from '%2%' to '%3%'!") % + path % info->narHash.to_string() % hash.to_string()); - hashAndWriteSink << exportMagic << path << info->references << info->deriver << 0; + hashAndWriteSink << exportMagic << path << info->references << info->deriver + << 0; } -Paths Store::importPaths(Source & source, std::shared_ptr accessor, CheckSigsFlag checkSigs) -{ - Paths res; - while (true) { - auto n = readNum(source); - if (n == 0) break; - if (n != 1) throw Error("input doesn't look like something created by 'nix-store --export'"); +Paths Store::importPaths(Source& source, std::shared_ptr accessor, + CheckSigsFlag checkSigs) { + Paths res; + while (true) { + auto n = readNum(source); + if (n == 0) break; + if (n != 1) + throw Error( + "input doesn't look like something created by 'nix-store --export'"); - /* Extract the NAR from the source. */ - TeeSink tee(source); - parseDump(tee, tee.source); + /* Extract the NAR from the source. */ + TeeSink tee(source); + parseDump(tee, tee.source); - uint32_t magic = readInt(source); - if (magic != exportMagic) - throw Error("Nix archive cannot be imported; wrong format"); + uint32_t magic = readInt(source); + if (magic != exportMagic) + throw Error("Nix archive cannot be imported; wrong format"); - ValidPathInfo info; + ValidPathInfo info; - info.path = readStorePath(*this, source); + info.path = readStorePath(*this, source); - //Activity act(*logger, lvlInfo, format("importing path '%s'") % info.path); + // Activity act(*logger, lvlInfo, format("importing path '%s'") % + // info.path); - info.references = readStorePaths(*this, source); + info.references = readStorePaths(*this, source); - info.deriver = readString(source); - if (info.deriver != "") assertStorePath(info.deriver); + info.deriver = readString(source); + if (info.deriver != "") assertStorePath(info.deriver); - info.narHash = hashString(htSHA256, *tee.source.data); - info.narSize = tee.source.data->size(); + info.narHash = hashString(htSHA256, *tee.source.data); + info.narSize = tee.source.data->size(); - // Ignore optional legacy signature. - if (readInt(source) == 1) - readString(source); + // Ignore optional legacy signature. + if (readInt(source) == 1) readString(source); - addToStore(info, tee.source.data, NoRepair, checkSigs, accessor); + addToStore(info, tee.source.data, NoRepair, checkSigs, accessor); - res.push_back(info.path); - } + res.push_back(info.path); + } - return res; + return res; } -} +} // namespace nix -- cgit 1.4.1