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; 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) void RestoreSink::createRegularFile(const CanonPath & path, std::function<void(CreateRegularFileSink &)> func)
{ {
auto p = dstPath; auto p = append(dstPath, path);
if (!path.rel().empty()) {
p = p / path.rel();
}
RestoreRegularFile crf; RestoreRegularFile crf;
crf.fd = crf.fd =
@ -140,9 +144,7 @@ void RestoreRegularFile::operator () (std::string_view data)
void RestoreSink::createSymlink(const CanonPath & path, const std::string & target) void RestoreSink::createSymlink(const CanonPath & path, const std::string & target)
{ {
auto p = dstPath; auto p = append(dstPath, path);
if (!path.rel().empty())
p = dstPath / path.rel();
nix::createSymlink(target, p); nix::createSymlink(target, p);
} }