From 72b1797e2b65ad47f4dc8e9fab73b9aa170889b4 Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Fri, 7 Nov 2025 12:27:44 +0100 Subject: get oplog attachments (#622) * add support for downloading individual attachments from an oplog --- src/zencore/basicfile.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/zencore/basicfile.cpp') diff --git a/src/zencore/basicfile.cpp b/src/zencore/basicfile.cpp index 6989da67e..2fa02937d 100644 --- a/src/zencore/basicfile.cpp +++ b/src/zencore/basicfile.cpp @@ -513,6 +513,30 @@ TemporaryFile::SafeWriteFile(const std::filesystem::path& Path, MemoryView Data, } } +void +TemporaryFile::SafeWriteFile(const std::filesystem::path& Path, const CompositeBuffer& Data) +{ + std::error_code Ec; + SafeWriteFile(Path, Data, Ec); + if (Ec) + { + throw std::system_error(Ec, fmt::format("Failed to safely write file '{}'", Path)); + } +} + +void +TemporaryFile::SafeWriteFile(const std::filesystem::path& Path, const CompositeBuffer& Data, std::error_code& OutEc) +{ + TemporaryFile TempFile; + if (TempFile.CreateTemporary(Path.parent_path(), OutEc); !OutEc) + { + if (TempFile.Write(Data, 0, OutEc); !OutEc) + { + TempFile.MoveTemporaryIntoPlace(Path, OutEc); + } + } +} + ////////////////////////////////////////////////////////////////////////// LockFile::LockFile() -- cgit v1.2.3