aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/builtins/fetchurl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore/builtins/fetchurl.cc')
-rw-r--r--src/libstore/builtins/fetchurl.cc22
1 files changed, 9 insertions, 13 deletions
diff --git a/src/libstore/builtins/fetchurl.cc b/src/libstore/builtins/fetchurl.cc
index 1f4abd374..92aec63a0 100644
--- a/src/libstore/builtins/fetchurl.cc
+++ b/src/libstore/builtins/fetchurl.cc
@@ -24,6 +24,7 @@ void builtinFetchurl(const BasicDerivation & drv, const std::string & netrcData)
Path storePath = getAttr("out");
auto mainUrl = getAttr("url");
+ bool unpack = get(drv.env, "unpack", "") == "1";
/* Note: have to use a fresh downloader here because we're in
a forked process. */
@@ -39,21 +40,16 @@ void builtinFetchurl(const BasicDerivation & drv, const std::string & netrcData)
request.verifyTLS = false;
request.decompress = false;
- downloader->download(std::move(request), sink);
+ auto decompressor = makeDecompressionSink(
+ unpack && hasSuffix(mainUrl, ".xz") ? "xz" : "none", sink);
+ downloader->download(std::move(request), *decompressor);
+ decompressor->finish();
});
- if (get(drv.env, "unpack", "") == "1") {
-
- if (hasSuffix(mainUrl, ".xz")) {
- auto source2 = sinkToSource([&](Sink & sink) {
- decompress("xz", *source, sink);
- });
- restorePath(storePath, *source2);
- } else
- restorePath(storePath, *source);
-
- } else
- writeFile(storePath, *source);
+ if (unpack)
+ restorePath(storePath, *source);
+ else
+ writeFile(storePath, *source);
auto executable = drv.env.find("executable");
if (executable != drv.env.end() && executable->second == "1") {