aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/download.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-09-11 15:25:43 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-11-26 22:07:28 +0100
commit8918bae09828133259acb36d6aef60ffbfad252c (patch)
tree67cb5628c4fc537a4c42ba38a79dbf342215e36c /src/libstore/download.cc
parentf2bd8470926686361602e545d63a69d4bfc22f90 (diff)
Drop remaining uses of external "tar"
Also, fetchGit now runs in O(1) memory since we pipe the output of 'git archive' directly into unpackTarball() (rather than first reading it all into memory).
Diffstat (limited to 'src/libstore/download.cc')
-rw-r--r--src/libstore/download.cc12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/libstore/download.cc b/src/libstore/download.cc
index e80663dff..61e88c5c1 100644
--- a/src/libstore/download.cc
+++ b/src/libstore/download.cc
@@ -8,6 +8,7 @@
#include "compression.hh"
#include "pathlocks.hh"
#include "finally.hh"
+#include "tarfile.hh"
#ifdef ENABLE_S3
#include <aws/core/client/ClientConfiguration.h>
@@ -903,12 +904,15 @@ CachedDownloadResult Downloader::downloadCached(
unpackedStorePath = "";
}
if (unpackedStorePath.empty()) {
- printInfo(format("unpacking '%1%'...") % url);
+ printInfo("unpacking '%s'...", url);
Path tmpDir = createTempDir();
AutoDelete autoDelete(tmpDir, true);
- // FIXME: this requires GNU tar for decompression.
- runProgram("tar", true, {"xf", store->toRealPath(storePath), "-C", tmpDir, "--strip-components", "1"});
- unpackedStorePath = store->addToStore(name, tmpDir, true, htSHA256, defaultPathFilter, NoRepair);
+ unpackTarfile(store->toRealPath(storePath), tmpDir, baseNameOf(url));
+ auto members = readDirectory(tmpDir);
+ if (members.size() != 1)
+ throw nix::Error("tarball '%s' contains an unexpected number of top-level files", url);
+ auto topDir = tmpDir + "/" + members.begin()->name;
+ unpackedStorePath = store->addToStore(name, topDir, true, htSHA256, defaultPathFilter, NoRepair);
}
replaceSymlink(unpackedStorePath, unpackedLink);
storePath = unpackedStorePath;