mirror of
https://github.com/NixOS/nix.git
synced 2025-11-17 07:52:43 +01:00
For example, instead of doing
#include "nix/store-config.hh"
#include "nix/derived-path.hh"
Now do
#include "nix/store/config.hh"
#include "nix/store/derived-path.hh"
This was originally planned in the issue, and also recent requested by
Eelco.
Most of the change is purely mechanical. There is just one small
additional issue. See how, in the example above, we took this
opportunity to also turn `<comp>-config.hh` into `<comp>/config.hh`.
Well, there was already a `nix/util/config.{cc,hh}`. Even though there
is not a public configuration header for libutil (which also would be
called `nix/util/config.{cc,hh}`) that's still confusing, To avoid any
such confusion, we renamed that to `nix/util/configuration.{cc,hh}`.
Finally, note that the libflake headers already did this, so we didn't
need to do anything to them. We wouldn't want to mistakenly get
`nix/flake/flake/flake.hh`!
Progress on #7876
51 lines
1.4 KiB
C++
51 lines
1.4 KiB
C++
#include "nix/store/builtins.hh"
|
|
#include "nix/util/tarfile.hh"
|
|
|
|
namespace nix {
|
|
|
|
namespace fs { using namespace std::filesystem; }
|
|
|
|
void builtinUnpackChannel(
|
|
const BasicDerivation & drv,
|
|
const std::map<std::string, Path> & outputs)
|
|
{
|
|
auto getAttr = [&](const std::string & name) -> const std::string & {
|
|
auto i = drv.env.find(name);
|
|
if (i == drv.env.end()) throw Error("attribute '%s' missing", name);
|
|
return i->second;
|
|
};
|
|
|
|
fs::path out{outputs.at("out")};
|
|
auto & channelName = getAttr("channelName");
|
|
auto & src = getAttr("src");
|
|
|
|
if (fs::path{channelName}.filename().string() != channelName) {
|
|
throw Error("channelName is not allowed to contain filesystem separators, got %1%", channelName);
|
|
}
|
|
|
|
createDirs(out);
|
|
|
|
unpackTarfile(src, out);
|
|
|
|
size_t fileCount;
|
|
std::string fileName;
|
|
try {
|
|
auto entries = fs::directory_iterator{out};
|
|
fileName = entries->path().string();
|
|
fileCount = std::distance(fs::begin(entries), fs::end(entries));
|
|
} catch (fs::filesystem_error &) {
|
|
throw SysError("failed to read directory %1%", out.string());
|
|
}
|
|
|
|
if (fileCount != 1)
|
|
throw Error("channel tarball '%s' contains more than one file", src);
|
|
|
|
auto target = out / channelName;
|
|
try {
|
|
fs::rename(fileName, target);
|
|
} catch (fs::filesystem_error &) {
|
|
throw SysError("failed to rename %1% to %2%", fileName, target.string());
|
|
}
|
|
}
|
|
|
|
}
|