From 8b57548de9836fce3663b99d0140146f12668e8c Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Thu, 17 Apr 2025 16:56:57 +0200 Subject: FileSystemManager: Always remove directories recursively --- src/buildtool/file_system/file_system_manager.hpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/buildtool/file_system/file_system_manager.hpp') 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 #include #include +#include #include #include #include @@ -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(-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{}", -- cgit v1.2.3