From 5e24dd0fc5e255d094a3d78e8e1b64a202c1e7a4 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Mon, 10 Mar 2025 10:57:45 +0100 Subject: just execute: write pid and info files atomically --- .../execution_service/server_implementation.cpp | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) (limited to 'src/buildtool/execution_api/execution_service/server_implementation.cpp') diff --git a/src/buildtool/execution_api/execution_service/server_implementation.cpp b/src/buildtool/execution_api/execution_service/server_implementation.cpp index d88c12a4..fddc36b6 100644 --- a/src/buildtool/execution_api/execution_service/server_implementation.cpp +++ b/src/buildtool/execution_api/execution_service/server_implementation.cpp @@ -20,7 +20,6 @@ #error "Non-unix is not supported yet" #endif -#include #include #include #include @@ -40,26 +39,12 @@ #include "src/buildtool/execution_api/execution_service/cas_server.hpp" #include "src/buildtool/execution_api/execution_service/execution_server.hpp" #include "src/buildtool/execution_api/execution_service/operations_server.hpp" +#include "src/buildtool/file_system/atomic.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/logging/logger.hpp" #include "src/buildtool/storage/config.hpp" #include "src/utils/cpp/type_safe_arithmetic.hpp" -namespace { -template -auto TryWrite(std::string const& file, T const& content) noexcept -> bool { - std::ofstream of{file}; - if (not of.good()) { - Logger::Log(LogLevel::Error, - "Could not open {}. Make sure to have write permissions", - file); - return false; - } - of << content; - return true; -} -} // namespace - auto ServerImpl::Create(std::optional interface, std::optional port, std::optional info_file, @@ -144,7 +129,8 @@ auto ServerImpl::Run(gsl::not_null const& local_context, {"interface", interface_}, {"port", port_}, {"pid", pid}}; if (not pid_file_.empty()) { - if (not TryWrite(pid_file_, pid)) { + if (not FileSystemAtomic::WriteFile(pid_file_, + fmt::format("{}", pid))) { server->Shutdown(); return false; } @@ -157,7 +143,7 @@ auto ServerImpl::Run(gsl::not_null const& local_context, info_str); if (not info_file_.empty()) { - if (not TryWrite(info_file_, info_str)) { + if (not FileSystemAtomic::WriteFile(info_file_, info_str)) { server->Shutdown(); return false; } -- cgit v1.2.3