1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-09-19 10:50:24 -04:00

factor duplicate code into util function append

This commit is contained in:
siddhantCodes 2024-07-04 11:09:23 +05:30
parent 509be0e77a
commit 976c05879f

View file

@ -82,13 +82,17 @@ struct RestoreRegularFile : CreateRegularFileSink {
void preallocateContents(uint64_t size) override;
};
static std::filesystem::path append(const std::filesystem::path & src, const CanonPath & path)
{
auto dst = src;
if (!path.rel().empty())
dst /= path.rel();
return dst;
}
void RestoreSink::createRegularFile(const CanonPath & path, std::function<void(CreateRegularFileSink &)> func)
{
auto p = dstPath;
if (!path.rel().empty()) {
p = p / path.rel();
}
auto p = append(dstPath, path);
RestoreRegularFile crf;
crf.fd =
@ -140,9 +144,7 @@ void RestoreRegularFile::operator () (std::string_view data)
void RestoreSink::createSymlink(const CanonPath & path, const std::string & target)
{
auto p = dstPath;
if (!path.rel().empty())
p = dstPath / path.rel();
auto p = append(dstPath, path);
nix::createSymlink(target, p);
}