mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-15 02:36:16 +02:00
c2de0a232c
Directly takes some c++ strings, and gently throws an exception on error (rather than having to inline this logic everywhere)
28 lines
704 B
C++
28 lines
704 B
C++
#include "builtins.hh"
|
|
#include "tarfile.hh"
|
|
|
|
namespace nix {
|
|
|
|
void builtinUnpackChannel(const BasicDerivation & drv)
|
|
{
|
|
auto getAttr = [&](const std::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);
|
|
|
|
unpackTarfile(src, out);
|
|
|
|
auto entries = readDirectory(out);
|
|
if (entries.size() != 1)
|
|
throw Error("channel tarball '%s' contains more than one file", src);
|
|
moveFile((out + "/" + entries[0].name), (out + "/" + channelName));
|
|
}
|
|
|
|
}
|