This is an automated email from the ASF dual-hosted git repository.

leginee pushed a commit to branch bz126990-fileCorruptionAtShutdown-trunk
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit 4fb771bc5af3acccf82dd94ca3a25d3a8d92fa6f
Author: Peter Kovacs <[email protected]>
AuthorDate: Tue Jul 28 08:25:54 2026 +0200

    ucb/ucpfile: flush file data to the medium before reporting a write 
successful
    
    Issue 126990; see main/sfx2/source/doc/readme.md for the full analysis.
    
    Co-Authored-By: Claude Opus 5 <[email protected]>
    (cherry picked from commit 0387c05dadfcf647c52ce960f2e148e65ac63c00)
---
 main/ucb/source/ucp/file/shell.cxx | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/main/ucb/source/ucp/file/shell.cxx 
b/main/ucb/source/ucp/file/shell.cxx
index 4f7897936e..63c3c2bb3c 100644
--- a/main/ucb/source/ucp/file/shell.cxx
+++ b/main/ucb/source/ucp/file/shell.cxx
@@ -1911,6 +1911,23 @@ shell::write( sal_Int32 CommandId,
         }
     } while( nReadBytes == nRequestedBytes );
 
+    // Force the data onto the physical medium before success is reported.
+    // Closing alone only flushes osl's own buffer into the OS page cache; the
+    // file system journals the new file size but not the data, so a crash or
+    // power loss between here and the next writeback leaves a file of the
+    // right length containing nothing but zeros (i126990).
+    if( bSuccess )
+    {
+        err = aFile.sync();
+        if( err != osl::FileBase::E_None )
+        {
+            installError( CommandId,
+                          TASKHANDLING_FILEIOERROR_FOR_WRITE,
+                          err );
+            bSuccess = sal_False;
+        }
+    }
+
     err = aFile.close();
     if( err != osl::FileBase::E_None  )
     {

Reply via email to