diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2025-04-17 16:56:57 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2025-04-22 13:50:57 +0200 |
commit | 8b57548de9836fce3663b99d0140146f12668e8c (patch) | |
tree | 59c1f554ac15bb64fa7be2789bd810f42e616c61 /src/buildtool/file_system/file_system_manager.hpp | |
parent | d65d711f844224dcf9215c52be8f69fd2885adfc (diff) | |
download | justbuild-8b57548de9836fce3663b99d0140146f12668e8c.tar.gz |
FileSystemManager: Always remove directories recursively
Diffstat (limited to 'src/buildtool/file_system/file_system_manager.hpp')
-rw-r--r-- | src/buildtool/file_system/file_system_manager.hpp | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/buildtool/file_system/file_system_manager.hpp b/src/buildtool/file_system/file_system_manager.hpp index fe316451..a6d15c84 100644 --- a/src/buildtool/file_system/file_system_manager.hpp +++ b/src/buildtool/file_system/file_system_manager.hpp @@ -44,6 +44,7 @@ #include <string> #include <string_view> #include <system_error> +#include <tuple> #include <unordered_set> #include <utility> #include <variant> @@ -510,9 +511,9 @@ class FileSystemManager { } } - [[nodiscard]] static auto RemoveDirectory(std::filesystem::path const& dir, - bool recursively = false) noexcept - -> bool { + /// \brief Remove directory recursively. + [[nodiscard]] static auto RemoveDirectory( + std::filesystem::path const& dir) noexcept -> bool { try { auto status = std::filesystem::symlink_status(dir); if (not std::filesystem::exists(status)) { @@ -521,11 +522,9 @@ class FileSystemManager { if (not std::filesystem::is_directory(status)) { return false; } - if (recursively) { - return (std::filesystem::remove_all(dir) != - static_cast<uintmax_t>(-1)); - } - return std::filesystem::remove(dir); + // If it doesn't throw, it succeeds: + std::ignore = std::filesystem::remove_all(dir); + return true; } catch (std::exception const& e) { Logger::Log(LogLevel::Error, "removing directory {}:\n{}", |