diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2025-02-17 14:18:38 +0100 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2025-03-24 09:25:05 +0100 |
commit | 91f648dbcf9e6e5638a16dc8aee85e8236ad53d4 (patch) | |
tree | f444cd247186832d4cfcf1f662096422d5e52254 /src/utils/cpp/tmp_dir.hpp | |
parent | 3cd82862c1b44409dddcbe65a14bd483574e7460 (diff) | |
download | justbuild-91f648dbcf9e6e5638a16dc8aee85e8236ad53d4.tar.gz |
TmpDir: Create nested directories
... and keep parent directories alive while nested directories exist.
Diffstat (limited to 'src/utils/cpp/tmp_dir.hpp')
-rw-r--r-- | src/utils/cpp/tmp_dir.hpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/utils/cpp/tmp_dir.hpp b/src/utils/cpp/tmp_dir.hpp index e2e1e7a7..28805e3d 100644 --- a/src/utils/cpp/tmp_dir.hpp +++ b/src/utils/cpp/tmp_dir.hpp @@ -38,13 +38,20 @@ class TmpDir final { [[nodiscard]] static auto Create( std::filesystem::path const& prefix) noexcept -> Ptr; + /// \brief Create a new nested temporary directory. This nested directory + /// remains valid even if the parent directory goes out of scope. + [[nodiscard]] static auto CreateNestedDirectory( + TmpDir::Ptr const& parent) noexcept -> Ptr; + private: - explicit TmpDir(std::filesystem::path path) noexcept - : tmp_dir_{std::move(path)} {} + explicit TmpDir(TmpDir::Ptr parent, std::filesystem::path path) noexcept + : parent_{std::move(parent)}, tmp_dir_{std::move(path)} {} [[nodiscard]] static auto CreateImpl( + TmpDir::Ptr parent, std::filesystem::path const& path) noexcept -> Ptr; + TmpDir::Ptr parent_; std::filesystem::path tmp_dir_; }; |