aboutsummaryrefslogtreecommitdiff
path: root/src/zencore
diff options
context:
space:
mode:
Diffstat (limited to 'src/zencore')
-rw-r--r--src/zencore/basicfile.cpp24
-rw-r--r--src/zencore/include/zencore/basicfile.h2
2 files changed, 26 insertions, 0 deletions
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()
diff --git a/src/zencore/include/zencore/basicfile.h b/src/zencore/include/zencore/basicfile.h
index 465499d2b..f5c82b8fe 100644
--- a/src/zencore/include/zencore/basicfile.h
+++ b/src/zencore/include/zencore/basicfile.h
@@ -107,6 +107,8 @@ public:
static void SafeWriteFile(const std::filesystem::path& Path, MemoryView Data);
static void SafeWriteFile(const std::filesystem::path& Path, MemoryView Data, std::error_code& OutEc);
+ static void SafeWriteFile(const std::filesystem::path& Path, const CompositeBuffer& Data);
+ static void SafeWriteFile(const std::filesystem::path& Path, const CompositeBuffer& Data, std::error_code& OutEc);
private:
void Close();