embeddedobj/source/commonembedding/miscobj.cxx     |    8 ++++----
 embeddedobj/source/commonembedding/persistence.cxx |   11 +++++------
 2 files changed, 9 insertions(+), 10 deletions(-)

New commits:
commit 0498c522724bbfd789261cb1562b3bfe1a81bb3e
Author:     Juergen Funk <juergen.funk...@cib.de>
AuthorDate: Wed Feb 23 05:49:46 2022 +0100
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Mon Mar 21 10:25:03 2022 +0100

    tdf#147589 In document with OLE link, don't show temp-file is in use
    
    Regression from 218f36dd614cf828e949f605faaf6a6fd615da26
    change the handling in OTempFileService::closeOutput
    That was the problem in the OLE-Link handling
    
    Change-Id: I5a7fa74b4a731f758e1c405dfb9cd298b30086a3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130408
    Tested-by: Jenkins
    Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de>

diff --git a/embeddedobj/source/commonembedding/miscobj.cxx 
b/embeddedobj/source/commonembedding/miscobj.cxx
index d65380cdc87e..a5d5573416d1 100644
--- a/embeddedobj/source/commonembedding/miscobj.cxx
+++ b/embeddedobj/source/commonembedding/miscobj.cxx
@@ -231,14 +231,14 @@ void OCommonEmbeddedObject::LinkInit_Impl(
         {
             // create temporary file
             m_aLinkTempFile = io::TempFile::create(m_xContext);
+            uno::Reference< ucb::XSimpleFileAccess > 
xTempOutAccess(ucb::SimpleFileAccess::create(m_xContext));
+            // if the temp stream is used, then the temp file remains locked
+            uno::Reference< io::XOutputStream > 
xOutStream(xTempOutAccess->openFileWrite(m_aLinkTempFile->getUri()));
 
             if(m_aLinkTempFile.is())
             {
                 // completely copy content of original OLE data
-                uno::Reference < io::XOutputStream > xTempOut = 
m_aLinkTempFile->getOutputStream();
-                ::comphelper::OStorageHelper::CopyInputToOutput( xInStream, 
xTempOut );
-                xTempOut->flush();
-                xTempOut->closeOutput();
+                ::comphelper::OStorageHelper::CopyInputToOutput(xInStream, 
xOutStream);
 
                 // reset flag m_bLinkTempFileChanged, so it will also work for 
multiple
                 // save op's of the containing file/document
diff --git a/embeddedobj/source/commonembedding/persistence.cxx 
b/embeddedobj/source/commonembedding/persistence.cxx
index 2aeb60e8eda0..77bc947650af 100644
--- a/embeddedobj/source/commonembedding/persistence.cxx
+++ b/embeddedobj/source/commonembedding/persistence.cxx
@@ -1284,18 +1284,17 @@ void SAL_CALL OCommonEmbeddedObject::storeAsEntry( 
const uno::Reference< embed::
             // tdf#141529 if we have a changed copy of the original OLE data 
we now
             // need to write it back 'over' the original OLE data
             uno::Reference < ucb::XSimpleFileAccess2 > 
xFileAccess(ucb::SimpleFileAccess::create( m_xContext ));
-            uno::Reference < io::XInputStream > xTempIn = 
m_aLinkTempFile->getInputStream();
 
+            uno::Reference< ucb::XSimpleFileAccess > 
xTempAccess(ucb::SimpleFileAccess::create(m_xContext));
+            // if the temp stream is used, then the temp file remains locked
+            uno::Reference< io::XInputStream > 
xInStream(xTempAccess->openFileRead(m_aLinkTempFile->getUri()));
             // This is *needed* since OTempFileService calls 
OTempFileService::readBytes which
             // ensures the SvStream mpStream gets/is opened, *but* also sets 
the mnCachedPos from
             // OTempFileService which still points to the end-of-file (from 
write-cc'ing).
-            uno::Reference < io::XSeekable > xSeek( xTempIn, 
uno::UNO_QUERY_THROW );
+            uno::Reference < io::XSeekable > xSeek( xInStream, 
uno::UNO_QUERY_THROW );
             xSeek->seek(0);
 
-            xFileAccess->writeFile(m_aLinkURL, xTempIn);
-
-            // Do *not* close input, that would remove the temporary file too 
early
-            // xTempIn->closeInput();
+            xFileAccess->writeFile(m_aLinkURL, xInStream);
 
             // reset flag m_bLinkTempFileChanged
             m_bLinkTempFileChanged = false;

Reply via email to