diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2025-02-14 16:15:05 +0100 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2025-03-24 09:14:22 +0100 |
commit | 6c009825cb320cc00531494985aa5fe7e0989971 (patch) | |
tree | da59ec4ea635e6460945c76c0f161f2f29214d0c /src/utils/cpp/tmp_dir.hpp | |
parent | bf185ababc1b97d2d2ab58de85449ffa7fd0b441 (diff) | |
download | justbuild-6c009825cb320cc00531494985aa5fe7e0989971.tar.gz |
TmpDir: minor refactoring
Diffstat (limited to 'src/utils/cpp/tmp_dir.hpp')
-rw-r--r-- | src/utils/cpp/tmp_dir.hpp | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/src/utils/cpp/tmp_dir.hpp b/src/utils/cpp/tmp_dir.hpp index 92d24f52..e2e1e7a7 100644 --- a/src/utils/cpp/tmp_dir.hpp +++ b/src/utils/cpp/tmp_dir.hpp @@ -17,38 +17,34 @@ #include <filesystem> #include <memory> -#include <string> +#include <utility> -std::string const kDefaultTemplate{"tmp.XXXXXX"}; - -class TmpDir; -using TmpDirPtr = std::shared_ptr<TmpDir const>; - -class TmpDir { +class TmpDir final { public: - // default ctor; not to be used! - TmpDir() = default; - - /// \brief Destroy the TmpDir object. It tries to remove the tmp folder. - ~TmpDir() noexcept; + using Ptr = std::shared_ptr<TmpDir const>; - // no copies, no moves TmpDir(TmpDir const&) = delete; - TmpDir(TmpDir&& other) noexcept = delete; - auto operator=(TmpDir const&) = delete; - auto operator=(TmpDir&& other) noexcept -> TmpDir& = delete; + auto operator=(TmpDir const&) -> TmpDir& = delete; + TmpDir(TmpDir&& other) = delete; + auto operator=(TmpDir&&) -> TmpDir& = delete; + ~TmpDir() noexcept; [[nodiscard]] auto GetPath() const& noexcept - -> std::filesystem::path const&; - [[nodiscard]] auto GetPath() && = delete; + -> std::filesystem::path const& { + return tmp_dir_; + } /// \brief Creates a completely unique directory in a given prefix path. [[nodiscard]] static auto Create( - std::filesystem::path const& prefix, - std::string const& dir_template = kDefaultTemplate) noexcept - -> TmpDirPtr; + std::filesystem::path const& prefix) noexcept -> Ptr; private: + explicit TmpDir(std::filesystem::path path) noexcept + : tmp_dir_{std::move(path)} {} + + [[nodiscard]] static auto CreateImpl( + std::filesystem::path const& path) noexcept -> Ptr; + std::filesystem::path tmp_dir_; }; |