about summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2018-03-21T21·56+0100
committerEelco Dolstra <edolstra@gmail.com>2018-03-21T22·10+0100
commit47f7e5585bbb9a6acfaddda7327ba4eeb5b662c2 (patch)
tree9ef9057da8d91c8178f54161841bcc76d52ab7c1 /src/libstore
parent92dfc223272083061d0c02d35efcad0a8bb9ba4d (diff)
Make 'nix copy --from ssh://...' run in constant memory
For instance, this reduced the memory consumption of

  $ nix copy --from ssh://localhost --to ~/my-nix /nix/store/1n7x0yv8vq6zi90hfmian84vdhd04bgp-blender-2.79a

from 632 MiB to 16 MiB.
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/legacy-ssh-store.cc7
-rw-r--r--src/libstore/ssh-store.cc19
2 files changed, 2 insertions, 24 deletions
diff --git a/src/libstore/legacy-ssh-store.cc b/src/libstore/legacy-ssh-store.cc
index 2a2e3d914815..b52de5434155 100644
--- a/src/libstore/legacy-ssh-store.cc
+++ b/src/libstore/legacy-ssh-store.cc
@@ -151,12 +151,7 @@ struct LegacySSHStore : public Store
 
         conn->to << cmdDumpStorePath << path;
         conn->to.flush();
-
-        /* FIXME: inefficient. */
-        ParseSink parseSink; /* null sink; just parse the NAR */
-        TeeSource savedNAR(conn->from);
-        parseDump(parseSink, savedNAR);
-        sink(*savedNAR.data);
+        copyNAR(conn->from, sink);
     }
 
     PathSet queryAllValidPaths() override { unsupported(); }
diff --git a/src/libstore/ssh-store.cc b/src/libstore/ssh-store.cc
index 398408ea8d78..39205ae2ce12 100644
--- a/src/libstore/ssh-store.cc
+++ b/src/libstore/ssh-store.cc
@@ -63,29 +63,12 @@ private:
     };
 };
 
-
-class ForwardSource : public Source
-{
-    Source & readSource;
-    Sink & writeSink;
-public:
-    ForwardSource(Source & readSource, Sink & writeSink) : readSource(readSource), writeSink(writeSink) {}
-    size_t read(unsigned char * data, size_t len) override
-    {
-        auto n = readSource.read(data, len);
-        writeSink(data, n);
-        return n;
-    }
-};
-
 void SSHStore::narFromPath(const Path & path, Sink & sink)
 {
     auto conn(connections->get());
     conn->to << wopNarFromPath << path;
     conn->processStderr();
-    ParseSink ps;
-    auto fwd = ForwardSource(conn->from, sink);
-    parseDump(ps, fwd);
+    copyNAR(conn->from, sink);
 }
 
 ref<FSAccessor> SSHStore::getFSAccessor()