mirror of
https://github.com/NixOS/nix
synced 2025-07-01 12:37:59 +02:00
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.
This commit is contained in:
parent
e60f6bd4ce
commit
045708db43
9 changed files with 55 additions and 84 deletions
39
src/libstore/builtins/unpack-channel.cc
Normal file
39
src/libstore/builtins/unpack-channel.cc
Normal file
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue