2019-03-27 22:40:35 +00:00
|
|
|
#include "builtins.hh"
|
2019-09-11 11:10:46 +00:00
|
|
|
#include "tarfile.hh"
|
2019-03-27 22:40:35 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2019-09-11 13:25:43 +00:00
|
|
|
unpackTarfile(src, out);
|
2019-03-27 22:40:35 +00:00
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|