diff --git a/cpp/src/Private/sweepstore/header.cpp b/cpp/src/Private/sweepstore/header.cpp index bdde5f6..3867644 100644 --- a/cpp/src/Private/sweepstore/header.cpp +++ b/cpp/src/Private/sweepstore/header.cpp @@ -88,7 +88,7 @@ void SweepstoreHeader::initialise() { writeAddressTablePointer(SweepstorePointer::NULL_PTR); writeFreeListCount(0); writeIsFreeListLifted(false); - file->flush(); + file.flush(); } uint64_t SweepstoreConcurrencyHeader::readMasterIdentifier() { @@ -158,7 +158,7 @@ void SweepstoreConcurrencyHeader::initialise(int concurrentWorkers) { SweepstoreWorkerTicket ticketWriter = SweepstoreWorkerTicket(i, file); ticketWriter.write(ticket); } - file->flush(); + file.flush(); } void SweepstoreWorkerTicket::write(SweepstoreWorkerTicketSnapshot &snapshot) { @@ -189,7 +189,7 @@ void SweepstoreWorkerTicket::write(SweepstoreWorkerTicketSnapshot &snapshot) { // Write to file file.writeSeek(getOffset()); file.writeBytes(dataPtr, data.size()); - file->flush(); + file.flush(); } bool SweepstoreWorkerTicket::writable() { diff --git a/cpp/src/Private/sweepstore/utils/file_handle.cpp b/cpp/src/Private/sweepstore/utils/file_handle.cpp index 06f4e1c..ce85a7f 100644 --- a/cpp/src/Private/sweepstore/utils/file_handle.cpp +++ b/cpp/src/Private/sweepstore/utils/file_handle.cpp @@ -55,6 +55,23 @@ void SweepstoreFileHandle::close() { #endif } +// flush +void SweepstoreFileHandle::flush() { +#ifdef WITH_UNREAL + if (unrealHandle) { + unrealHandle->Flush(); + } +#else + if (stream) { + stream->flush(); +#ifdef _WIN32 + // On Windows, also sync to ensure data hits disk + stream->sync(); +#endif + } +#endif +} + #if defined(_WIN32) || defined(WITH_UNREAL) // readSeek void SweepstoreFileHandle::readSeek(std::streampos pos, std::ios::seekdir dir) { diff --git a/cpp/src/Public/sweepstore/utils/file_handle.h b/cpp/src/Public/sweepstore/utils/file_handle.h index efcf87c..334919a 100644 --- a/cpp/src/Public/sweepstore/utils/file_handle.h +++ b/cpp/src/Public/sweepstore/utils/file_handle.h @@ -37,6 +37,7 @@ public: bool isOpen() const; void close(); + void flush(); // Windows-compatible I/O wrappers #if defined(_WIN32) || defined(WITH_UNREAL)