diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2025-03-10 10:57:45 +0100 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2025-03-11 10:53:58 +0100 |
commit | 5e24dd0fc5e255d094a3d78e8e1b64a202c1e7a4 (patch) | |
tree | 88d6c6edd39ee3a1efdb6377a31b13f139ebdcad /src/buildtool/execution_api/execution_service/server_implementation.cpp | |
parent | 1efdbe20d506990028caccbfbc7fd241b5a01a99 (diff) | |
download | justbuild-5e24dd0fc5e255d094a3d78e8e1b64a202c1e7a4.tar.gz |
just execute: write pid and info files atomically
Diffstat (limited to 'src/buildtool/execution_api/execution_service/server_implementation.cpp')
-rw-r--r-- | src/buildtool/execution_api/execution_service/server_implementation.cpp | 22 |
1 files changed, 4 insertions, 18 deletions
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 <fstream> #include <memory> #include <utility> #include <variant> @@ -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 <typename T> -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<std::string> interface, std::optional<int> port, std::optional<std::string> info_file, @@ -144,7 +129,8 @@ auto ServerImpl::Run(gsl::not_null<LocalContext const*> 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<LocalContext const*> 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; } |