about summary refs log tree commit diff
path: root/third_party/nix/src/libstore/export-import.cc
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-05-17T15·31+0100
committerVincent Ambo <tazjin@google.com>2020-05-17T15·31+0100
commit0f2cf531f705d370321843e5ba9135b2ebdb5d19 (patch)
tree256feb13963a849ed96e89228fa05454c2a22363 /third_party/nix/src/libstore/export-import.cc
parent65a1aae98ce5a237c9643e639e550c8b0c0be7f1 (diff)
style(3p/nix): Reformat project in Google C++ style r/740
Reformatted with:

    fd . -e hh -e cc | xargs clang-format -i
Diffstat (limited to 'third_party/nix/src/libstore/export-import.cc')
-rw-r--r--third_party/nix/src/libstore/export-import.cc142
1 files changed, 68 insertions, 74 deletions
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 <algorithm>
 #include "archive.hh"
+#include "store-api.hh"
 #include "worker-protocol.hh"
 
-#include <algorithm>
-
 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<FSAccessor> accessor, CheckSigsFlag checkSigs)
-{
-    Paths res;
-    while (true) {
-        auto n = readNum<uint64_t>(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<FSAccessor> accessor,
+                         CheckSigsFlag checkSigs) {
+  Paths res;
+  while (true) {
+    auto n = readNum<uint64_t>(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<PathSet>(*this, source);
+    info.references = readStorePaths<PathSet>(*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