From 976c05879f48e73eabe6818231da4bc7886c6c8c Mon Sep 17 00:00:00 2001 From: siddhantCodes Date: Thu, 4 Jul 2024 11:09:23 +0530 Subject: [PATCH] factor duplicate code into util function `append` --- src/libutil/fs-sink.cc | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/libutil/fs-sink.cc b/src/libutil/fs-sink.cc index 597272ec9..194e86fdd 100644 --- a/src/libutil/fs-sink.cc +++ b/src/libutil/fs-sink.cc @@ -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 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); }