From a6e36dbe301e72a68fbabdb7355575fab0a636dc Mon Sep 17 00:00:00 2001 From: DH Date: Wed, 9 Apr 2025 06:11:03 +0300 Subject: [PATCH] file: add write_pending_file utility --- rpcs3/util/File.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/rpcs3/util/File.h b/rpcs3/util/File.h index 1a63d4eb9..d768a27ee 100644 --- a/rpcs3/util/File.h +++ b/rpcs3/util/File.h @@ -930,6 +930,35 @@ namespace fs return false; } + template + bool write_pending_file(const std::string& path, const Args&... args) + { + // Always use write flag, remove read flag + if (fs::pending_file pending{path}; pending.file) + { + if constexpr (sizeof...(args) == 2u && (std::is_pointer_v || ...)) + { + // Specialization for [const void*, usz] args + pending.file.write(args...); + } + else + { + // Write args sequentially + (pending.file.write(args), ...); + } + + if constexpr (Flush) + { + pending.file.sync(); + } + + pending.commit(); + return true; + } + + return false; + } + file make_gather(std::vector); stx::generator list_dir_recursively(const std::string& path);