include/sfx2/docfile.hxx    |    5 +++++
 sfx2/source/doc/docfile.cxx |    4 ++++
 sfx2/source/doc/objstor.cxx |   10 +++++++++-
 3 files changed, 18 insertions(+), 1 deletion(-)

New commits:
commit 5a814b69e5ce691994d518db64bed72974e7f0e9
Author:     Caolán McNamara <[email protected]>
AuthorDate: Thu Nov 6 09:10:18 2025 +0000
Commit:     Caolán McNamara <[email protected]>
CommitDate: Thu Nov 6 16:03:54 2025 +0100

    SfxObjectShell::SaveTo_Impl may overwrite its original output file
    
    at which point the cached value of the 'Modified' timestamp is that
    of the pre-overwrite time. Drop the cached value and fetch it again
    on next demand.
    
    Otherwise another overwrite#2 attempt will compare against the
    timestamp of the pre-overwrite-#1 and not of the post-overwrite#1
    and a 2nd overwrite behaves differently that a 1st overwrite.
    
    It assumes that the timestamp mismatch means the file has been modified
    by an external event and requests an XInteractionHandler intervention to
    approve the 2nd overwrite (but not the 1st overwrite).
    
    This is indistinguisable from the 1st overwrite if there is no 
XInteractionHandler
    during the 2nd overwrite, but not if there is an XInteractionHandler
    set.
    
    The QuietInteractionHandler, used for headless and silent mode, defaults to
    aborting the save for queries it doesn't recognize, so will throws an 
exception in
    this case.
    
    The result is that CppunitTest_sfx2_misc 'testOverwrite' fails if the
    same interaction handler present during the 1st overwrite is still
    present during the 2nd overwrite. Which the next commit will introduce.
    
    Change-Id: I80b997ce6adba38049c0e92bd8b18d160a0a2292
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193522
    Reviewed-by: Caolán McNamara <[email protected]>
    Tested-by: Jenkins

diff --git a/include/sfx2/docfile.hxx b/include/sfx2/docfile.hxx
index a1b27e34057a..0e1c70a66364 100644
--- a/include/sfx2/docfile.hxx
+++ b/include/sfx2/docfile.hxx
@@ -143,7 +143,12 @@ public:
 
     void                CheckFileDate( const css::util::DateTime& aInitDate );
     [[nodiscard]] bool  DocNeedsFileDateCheck() const;
+    // Returns the 'DateModified' of the URLObject. With bIgnoreOldValue of
+    // false returns previously cached value. If true, or no cached value
+    // available, fetches it anew.
     css::util::DateTime const & GetInitFileDate( bool bIgnoreOldValue );
+    // Clear a previously cached 'DateModified' cache.
+    void ClearInitFileDateCache();
 
     css::uno::Reference< css::ucb::XContent > GetContent() const;
     const OUString& GetPhysicalName() const;
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index 012d0a418cb1..a64a4239f03a 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -637,6 +637,10 @@ util::DateTime const & SfxMedium::GetInitFileDate( bool 
bIgnoreOldValue )
     return pImpl->m_aDateTime;
 }
 
+void SfxMedium::ClearInitFileDateCache()
+{
+    pImpl->m_bGotDateTime = false;
+}
 
 Reference < XContent > SfxMedium::GetContent() const
 {
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index 9c33b88ec1f1..51e6cb8a605f 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -1581,7 +1581,8 @@ bool SfxObjectShell::SaveTo_Impl
         pMedium->DisableUnlockWebDAV();
         bStoreToSameLocation = true;
 
-        if ( pMedium->DocNeedsFileDateCheck() )
+        const bool bDocNeedsFileDateCheck = pMedium->DocNeedsFileDateCheck();
+        if (bDocNeedsFileDateCheck)
         {
             rMedium.CheckFileDate( pMedium->GetInitFileDate( false ) );
             if (rMedium.GetErrorCode() == ERRCODE_ABORT)
@@ -1700,6 +1701,13 @@ bool SfxObjectShell::SaveTo_Impl
             }
         }
         pMedium->DisableUnlockWebDAV(false);
+        if (bDocNeedsFileDateCheck)
+        {
+            // If we have already fetched 'DateModified' (via GetInitFileDate) 
then in
+            // this overwrite scenario that cached date is no longer 
necessarily true.
+            // Fetch it again on next demand.
+            pMedium->ClearInitFileDateCache();
+        }
     }
     else
     {

Reply via email to