diff options
Diffstat (limited to 'src/zenstore/compactcas.cpp')
| -rw-r--r-- | src/zenstore/compactcas.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/zenstore/compactcas.cpp b/src/zenstore/compactcas.cpp index c8fb41ffc..17cf20e35 100644 --- a/src/zenstore/compactcas.cpp +++ b/src/zenstore/compactcas.cpp @@ -910,8 +910,13 @@ CasContainerStrategy::MakeIndexSnapshot() } } - BasicFile ObjectIndexFile; - ObjectIndexFile.Open(IndexPath, BasicFile::Mode::kTruncate); + TemporaryFile ObjectIndexFile; + std::error_code Ec; + ObjectIndexFile.CreateTemporary(IndexPath.parent_path(), Ec); + if (Ec) + { + throw std::system_error(Ec, fmt::format("Failed to create temp file for index snapshot at '{}'", IndexPath)); + } CasDiskIndexHeader Header = {.EntryCount = Entries.size(), .LogPosition = IndexLogPosition, .PayloadAlignment = gsl::narrow<uint32_t>(m_PayloadAlignment)}; @@ -921,7 +926,11 @@ CasContainerStrategy::MakeIndexSnapshot() ObjectIndexFile.Write(&Header, sizeof(CasDiskIndexHeader), 0); ObjectIndexFile.Write(Entries.data(), Entries.size() * sizeof(CasDiskIndexEntry), sizeof(CasDiskIndexHeader)); ObjectIndexFile.Flush(); - ObjectIndexFile.Close(); + ObjectIndexFile.MoveTemporaryIntoPlace(IndexPath, Ec); + if (Ec) + { + throw std::system_error(Ec, fmt::format("Failed to move temp file '{}' to '{}'", ObjectIndexFile.GetPath(), IndexPath)); + } EntryCount = Entries.size(); m_LogFlushPosition = IndexLogPosition; } |