Merge pull request #11035 from siddhantk232/refactor

Factor duplicate code into util function `append`
This commit is contained in:
Eelco Dolstra 2024-07-05 16:34:23 +02:00 committed by GitHub
commit 98bef7c38e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

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);
}