aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/builtins/unpack-channel.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-03-27 23:40:35 +0100
committerEelco Dolstra <edolstra@gmail.com>2019-11-26 22:07:28 +0100
commit045708db4343174f30f3647776971c852f72a9e8 (patch)
treec37c82882d48e44338c9bae61eacb3839421f359 /src/libstore/builtins/unpack-channel.cc
parente60f6bd4ce831ced94fafeb527c429b6f88159ac (diff)
Make <nix/unpack-channel.nix> a builtin builder
This was the last function using a shell script, so this allows us to get rid of tar, coreutils, bash etc.
Diffstat (limited to 'src/libstore/builtins/unpack-channel.cc')
-rw-r--r--src/libstore/builtins/unpack-channel.cc39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/libstore/builtins/unpack-channel.cc b/src/libstore/builtins/unpack-channel.cc
new file mode 100644
index 000000000..88202ec6b
--- /dev/null
+++ b/src/libstore/builtins/unpack-channel.cc
@@ -0,0 +1,39 @@
+#include "rust.hh"
+#include "builtins.hh"
+#include "compression.hh"
+
+namespace nix {
+
+void builtinUnpackChannel(const BasicDerivation & drv)
+{
+ auto getAttr = [&](const string & name) {
+ auto i = drv.env.find(name);
+ if (i == drv.env.end()) throw Error("attribute '%s' missing", name);
+ return i->second;
+ };
+
+ Path out = getAttr("out");
+ auto channelName = getAttr("channelName");
+ auto src = getAttr("src");
+
+ createDirs(out);
+
+ auto source = sinkToSource([&](Sink & sink) {
+ auto decompressor =
+ hasSuffix(src, ".bz2") ? makeDecompressionSink("bzip2", sink) :
+ hasSuffix(src, ".xz") ? makeDecompressionSink("xz", sink) :
+ makeDecompressionSink("none", sink);
+ readFile(src, *decompressor);
+ decompressor->finish();
+ });
+
+ unpack_tarfile(*source, out);
+
+ auto entries = readDirectory(out);
+ if (entries.size() != 1)
+ throw Error("channel tarball '%s' contains more than one file", src);
+ if (rename((out + "/" + entries[0].name).c_str(), (out + "/" + channelName).c_str()) == -1)
+ throw SysError("renaming channel directory");
+}
+
+}