nix-super/src/libstore/unix/builtins/unpack-channel.cc

31 lines
760 B
C++
Raw Normal View History

#include "builtins.hh"
2019-09-11 14:10:46 +03:00
#include "tarfile.hh"
namespace nix {
void builtinUnpackChannel(
const BasicDerivation & drv,
const std::map<std::string, Path> & outputs)
{
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;
};
auto out = outputs.at("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);
renameFile(entries[0].path().string(), (out + "/" + channelName));
}
}