From 375fa71cb816acb25bd2eaf24ef5cc292a1f2c36 Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Thu, 2 May 2024 17:01:09 +0200 Subject: use write and move in place for safer writing of files (#70) * use write and move in place for safer writing of files --- src/zenstore/cas.cpp | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) (limited to 'src/zenstore/cas.cpp') diff --git a/src/zenstore/cas.cpp b/src/zenstore/cas.cpp index 67790e2c6..f300c08e3 100644 --- a/src/zenstore/cas.cpp +++ b/src/zenstore/cas.cpp @@ -220,19 +220,7 @@ CasImpl::UpdateManifest() ZEN_TRACE("Writing new manifest to '{}'", ManifestPath); - TemporaryFile Marker; - std::error_code Ec; - Marker.CreateTemporary(ManifestPath.parent_path(), Ec); - if (Ec) - { - throw std::system_error(Ec, fmt::format("Failed to create temp file for cas manifest at '{}'", ManifestPath)); - } - Marker.Write(m_ManifestObject.GetBuffer(), 0); - Marker.MoveTemporaryIntoPlace(ManifestPath, Ec); - if (Ec) - { - throw std::system_error(Ec, fmt::format("Failed to move temp file '{}' to '{}'", Marker.GetPath(), ManifestPath)); - } + TemporaryFile::SafeWriteFile(ManifestPath, m_ManifestObject.GetBuffer().GetView()); } CasStore::InsertResult -- cgit v1.2.3