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 700ea1d3f3ecb58f33821f9eeb7c9fc02e0a91c0
Author:     Caolán McNamara <[email protected]>
AuthorDate: Thu Nov 6 09:10:18 2025 +0000
Commit:     Andras Timar <[email protected]>
CommitDate: Mon Nov 10 11:14:27 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/+/193520
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193729
    Tested-by: Andras Timar <[email protected]>
    Reviewed-by: Andras Timar <[email protected]>

diff --git a/include/sfx2/docfile.hxx b/include/sfx2/docfile.hxx
index ec95a16bacf9..dc339bc9154f 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 a5ec8ab17e0f..9e4691805323 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -636,6 +636,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 43a7a9e140c2..c1449a020343 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