diff options
Diffstat (limited to 'src/zenstore/filecas.cpp')
| -rw-r--r-- | src/zenstore/filecas.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/zenstore/filecas.cpp b/src/zenstore/filecas.cpp index af0a3a176..428183827 100644 --- a/src/zenstore/filecas.cpp +++ b/src/zenstore/filecas.cpp @@ -1179,8 +1179,13 @@ FileCasStrategy::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)); + } filecas::impl::FileCasIndexHeader Header = {.EntryCount = Entries.size(), .LogPosition = IndexLogPosition}; Header.Checksum = filecas::impl::FileCasIndexHeader::ComputeChecksum(Header); @@ -1188,7 +1193,11 @@ FileCasStrategy::MakeIndexSnapshot() ObjectIndexFile.Write(&Header, sizeof(filecas::impl::FileCasIndexHeader), 0); ObjectIndexFile.Write(Entries.data(), Entries.size() * sizeof(FileCasIndexEntry), sizeof(filecas::impl::FileCasIndexHeader)); 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; } |