[Libreoffice-commits] core.git: sfx2/source unotools/source

2022-02-25 Thread Noel Grandin (via logerrit)
 sfx2/source/doc/doctemplates.cxx   |   11 ---
 unotools/source/ucbhelper/tempfile.cxx |7 +++
 2 files changed, 15 insertions(+), 3 deletions(-)

New commits:
commit 02caa6e40cfa55d96befc82515b343045b5cfd7b
Author: Noel Grandin 
AuthorDate: Thu Feb 24 16:17:46 2022 +0200
Commit: Noel Grandin 
CommitDate: Fri Feb 25 12:13:00 2022 +0100

renames in template manager creates xml file in wrong location

revert part of
commit dd42f133f604ee2f7e0ffbca6a8d94fb8f95dfe5
Author: Noel Grandin 
Date:   Mon Jan 10 19:37:05 2022 +0200
tdf#146375 Cannot rename user-defined categories in template manager

specifically, revert the

>Simplify the UCB usage to just write the contents of the tempfile

and also call SvStream::Flush() in utl::TempFile::GetURL(), so that
the data actually hits the disk, so that when UCB attempts to read
the data using a separate file handle, it sees the data.

(Otherwise the temporary file data only exists in the operating system
buffers, and can only be read by the same file handle that created it)

Change-Id: I17798c53e49d65484605f2dcd96b45babd70054d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130499
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/sfx2/source/doc/doctemplates.cxx b/sfx2/source/doc/doctemplates.cxx
index cbdbe676f6f1..70250cf51270 100644
--- a/sfx2/source/doc/doctemplates.cxx
+++ b/sfx2/source/doc/doctemplates.cxx
@@ -1281,12 +1281,17 @@ bool 
SfxDocTplService_Impl::WriteUINamesForTemplateDir_Impl( std::u16string_view
 DocTemplLocaleHelper::WriteGroupLocalizationSequence( xOutStream, 
aUINames, mxContext);
 try {
 // the SAX writer might close the stream
-xOutStream->closeOutput();
+//xOutStream->closeOutput();
 } catch( uno::Exception& )
 {}
 
-uno::Reference < ucb::XSimpleFileAccess3 > 
xAccess(ucb::SimpleFileAccess::create(mxContext));
-xAccess->writeFile(OUString::Concat(aUserPath) + "groupuinames.xml", 
xTempFile->getInputStream());
+Content aTargetContent( OUString(aUserPath), maCmdEnv, 
comphelper::getProcessComponentContext() );
+Content aSourceContent( xTempFile->getUri(), maCmdEnv, 
comphelper::getProcessComponentContext() );
+aTargetContent.transferContent( aSourceContent,
+InsertOperation::Copy,
+"groupuinames.xml",
+ucb::NameClash::OVERWRITE,
+"text/xml" );
 
 bResult = true;
 }
diff --git a/unotools/source/ucbhelper/tempfile.cxx 
b/unotools/source/ucbhelper/tempfile.cxx
index 07889ffdab83..cccad1c367f0 100644
--- a/unotools/source/ucbhelper/tempfile.cxx
+++ b/unotools/source/ucbhelper/tempfile.cxx
@@ -413,6 +413,13 @@ OUString TempFile::GetFileName() const
 
 OUString const & TempFile::GetURL() const
 {
+// if you request the URL, then you presumably want to access this via UCB,
+// and UCB will want to open the file via a separate file handle, which 
means
+// we have to make this file data actually hit disk. We do this here (and 
not
+// elsewhere) to make the other (normal) paths fast. Flushing to disk
+// really slows temp files down.
+if (pStream)
+pStream->Flush();
 return aName;
 }
 


[Libreoffice-commits] core.git: sfx2/source unotools/source

2022-01-10 Thread Noel Grandin (via logerrit)
 sfx2/source/doc/doctemplates.cxx|   21 -
 unotools/source/ucbhelper/xtempfile.cxx |6 ++
 2 files changed, 14 insertions(+), 13 deletions(-)

New commits:
commit dd42f133f604ee2f7e0ffbca6a8d94fb8f95dfe5
Author: Noel Grandin 
AuthorDate: Mon Jan 10 19:37:05 2022 +0200
Commit: Noel Grandin 
CommitDate: Tue Jan 11 07:19:02 2022 +0100

tdf#146375 Cannot rename user-defined categories in template manager

Regression from
  commit 3624a703361b108d22448bd60a97733f05e37820
  tdf#135316 remove OTempFileService pessimisation

So fix two things here

(1) make it so the tempfile service flushes the SvStream buffer
and resets the file position, so we can read the data
after writing it.
(2) Simplify the UCB usage to just write the contents of the tempfile
via the tempfile InputStream, which is simpler and safer

Change-Id: I15ed3b02c2d6415d10a9579f66374e6268188d5c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128195
Tested-by: Noel Grandin 
Reviewed-by: Noel Grandin 

diff --git a/sfx2/source/doc/doctemplates.cxx b/sfx2/source/doc/doctemplates.cxx
index 9ac236b3b4f4..cbdbe676f6f1 100644
--- a/sfx2/source/doc/doctemplates.cxx
+++ b/sfx2/source/doc/doctemplates.cxx
@@ -40,6 +40,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -231,7 +232,7 @@ class SfxDocTplService_Impl
   const 
OUString& aNewGroupName );
 voidRemoveUINamesForTemplateDir_Impl( const OUString& 
aUserPath,
   
std::u16string_view aGroupName );
-boolWriteUINamesForTemplateDir_Impl( const OUString& 
aUserPath,
+boolWriteUINamesForTemplateDir_Impl( 
std::u16string_view aUserPath,
 const 
std::vector< beans::StringPair >& aUINames );
 
 OUStringCreateNewGroupFsys( const OUString& rGroupName, 
Content& aGroup );
@@ -1264,7 +1265,7 @@ void 
SfxDocTplService_Impl::RemoveUINamesForTemplateDir_Impl( const OUString& aU
 }
 
 
-bool SfxDocTplService_Impl::WriteUINamesForTemplateDir_Impl( const OUString& 
aUserPath,
+bool SfxDocTplService_Impl::WriteUINamesForTemplateDir_Impl( 
std::u16string_view aUserPath,
  const 
std::vector< beans::StringPair >& aUINames )
 {
 bool bResult = false;
@@ -1273,10 +1274,7 @@ bool 
SfxDocTplService_Impl::WriteUINamesForTemplateDir_Impl( const OUString& aUs
 io::TempFile::create(mxContext),
 uno::UNO_SET_THROW );
 
-OUString aTempURL = xTempFile->getUri();
-
-uno::Reference< io::XStream > xStream( xTempFile );
-uno::Reference< io::XOutputStream > xOutStream = 
xStream->getOutputStream();
+uno::Reference< io::XOutputStream > xOutStream = 
xTempFile->getOutputStream();
 if ( !xOutStream.is() )
 throw uno::RuntimeException();
 
@@ -1287,17 +1285,14 @@ bool 
SfxDocTplService_Impl::WriteUINamesForTemplateDir_Impl( const OUString& aUs
 } catch( uno::Exception& )
 {}
 
-Content aTargetContent( aUserPath, maCmdEnv, 
comphelper::getProcessComponentContext() );
-Content aSourceContent( aTempURL, maCmdEnv, 
comphelper::getProcessComponentContext() );
-aTargetContent.transferContent( aSourceContent,
-InsertOperation::Copy,
-"groupuinames.xml",
-ucb::NameClash::OVERWRITE,
-"text/xml" );
+uno::Reference < ucb::XSimpleFileAccess3 > 
xAccess(ucb::SimpleFileAccess::create(mxContext));
+xAccess->writeFile(OUString::Concat(aUserPath) + "groupuinames.xml", 
xTempFile->getInputStream());
+
 bResult = true;
 }
 catch ( uno::Exception& )
 {
+TOOLS_WARN_EXCEPTION("sfx.doc", "");
 }
 
 return bResult;
diff --git a/unotools/source/ucbhelper/xtempfile.cxx 
b/unotools/source/ucbhelper/xtempfile.cxx
index a8ace5da6725..a5772d8ba0c7 100644
--- a/unotools/source/ucbhelper/xtempfile.cxx
+++ b/unotools/source/ucbhelper/xtempfile.cxx
@@ -218,6 +218,12 @@ void SAL_CALL OTempFileService::closeOutput(  )
 throw css::io::NotConnectedException ( OUString(), static_cast < 
css::uno::XWeak * > (this ) );
 
 mbOutClosed = true;
+if (mpStream)
+{
+// so that if you then open the InputStream, you can read the content
+mpStream->FlushBuffer();
+mpStream->Seek(0);
+}
 
 if ( mbInClosed )
 {