2019-03-28 00:40:35 +02:00
|
|
|
#include "builtins.hh"
|
2019-09-11 14:10:46 +03:00
|
|
|
#include "tarfile.hh"
|
2019-03-28 00:40:35 +02:00
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2024-02-12 17:34:59 +02:00
|
|
|
void builtinUnpackChannel(
|
|
|
|
const BasicDerivation & drv,
|
|
|
|
const std::map<std::string, Path> & outputs)
|
2019-03-28 00:40:35 +02:00
|
|
|
{
|
2022-02-25 17:00:00 +02:00
|
|
|
auto getAttr = [&](const std::string & name) {
|
2019-03-28 00:40:35 +02:00
|
|
|
auto i = drv.env.find(name);
|
|
|
|
if (i == drv.env.end()) throw Error("attribute '%s' missing", name);
|
|
|
|
return i->second;
|
|
|
|
};
|
|
|
|
|
2024-02-12 17:34:59 +02:00
|
|
|
auto out = outputs.at("out");
|
2019-03-28 00:40:35 +02:00
|
|
|
auto channelName = getAttr("channelName");
|
|
|
|
auto src = getAttr("src");
|
|
|
|
|
|
|
|
createDirs(out);
|
|
|
|
|
2019-09-11 16:25:43 +03:00
|
|
|
unpackTarfile(src, out);
|
2019-03-28 00:40:35 +02:00
|
|
|
|
2024-05-12 15:12:18 +03:00
|
|
|
auto entries = std::filesystem::directory_iterator{out};
|
2024-05-13 13:06:00 +03:00
|
|
|
auto fileName = entries->path().string();
|
|
|
|
auto fileCount = std::distance(std::filesystem::begin(entries), std::filesystem::end(entries));
|
2024-05-12 15:12:18 +03:00
|
|
|
|
2024-05-13 13:06:00 +03:00
|
|
|
if (fileCount != 1)
|
2019-03-28 00:40:35 +02:00
|
|
|
throw Error("channel tarball '%s' contains more than one file", src);
|
2024-05-13 16:13:12 +03:00
|
|
|
std::filesystem::rename(fileName, (out + "/" + channelName));
|
2019-03-28 00:40:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|