mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 05:56:15 +02:00
Merge pull request #11035 from siddhantk232/refactor
Factor duplicate code into util function `append`
This commit is contained in:
commit
98bef7c38e
1 changed files with 10 additions and 8 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue