diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2022-01-10 19:37:05 +0200 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2022-01-14 12:21:51 +0100 |
commit | afa109d947c811cdce15413fdb536dc4bd90526b (patch) | |
tree | 243f8d577d1d4aab127bf23336cef796d14560a8 | |
parent | 58d4b1aae1a599322b27ec388b62d8a6ed158ef9 (diff) |
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 <noel.grandin@collabora.co.uk>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128274
Tested-by: Jenkins
(cherry picked from commit d1068539a1eb305ebcbb301f2f8f6fda0ab2d6ee)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128342
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
-rw-r--r-- | sfx2/source/doc/doctemplates.cxx | 27 | ||||
-rw-r--r-- | unotools/source/ucbhelper/xtempfile.cxx | 6 |
2 files changed, 16 insertions, 17 deletions
diff --git a/sfx2/source/doc/doctemplates.cxx b/sfx2/source/doc/doctemplates.cxx index 50d11b8b043b..e58a54961e2e 100644 --- a/sfx2/source/doc/doctemplates.cxx +++ b/sfx2/source/doc/doctemplates.cxx @@ -39,6 +39,7 @@ #include <com/sun/star/beans/XPropertySetInfo.hpp> #include <com/sun/star/beans/XPropertyContainer.hpp> #include <com/sun/star/beans/StringPair.hpp> +#include <com/sun/star/ucb/SimpleFileAccess.hpp> #include <com/sun/star/util/theMacroExpander.hpp> #include <com/sun/star/util/theOfficeInstallationDirectories.hpp> #include <com/sun/star/configuration/theDefaultProvider.hpp> @@ -230,7 +231,7 @@ class SfxDocTplService_Impl const OUString& aNewGroupName ); void RemoveUINamesForTemplateDir_Impl( const OUString& aUserPath, std::u16string_view aGroupName ); - bool WriteUINamesForTemplateDir_Impl( const OUString& aUserPath, + bool WriteUINamesForTemplateDir_Impl( std::u16string_view aUserPath, const std::vector< beans::StringPair >& aUINames ); OUString CreateNewGroupFsys( const OUString& rGroupName, Content& aGroup ); @@ -1275,21 +1276,16 @@ 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; try { - uno::Reference< beans::XPropertySet > xTempFile( + uno::Reference< io::XTempFile > xTempFile( io::TempFile::create(mxContext), - uno::UNO_QUERY_THROW ); + uno::UNO_SET_THROW ); - OUString aTempURL; - uno::Any aUrl = xTempFile->getPropertyValue("Uri"); - aUrl >>= aTempURL; - - uno::Reference< io::XStream > xStream( xTempFile, uno::UNO_QUERY_THROW ); - uno::Reference< io::XOutputStream > xOutStream = xStream->getOutputStream(); + uno::Reference< io::XOutputStream > xOutStream = xTempFile->getOutputStream(); if ( !xOutStream.is() ) throw uno::RuntimeException(); @@ -1300,17 +1296,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 4982520abfeb..c97bb424e561 100644 --- a/unotools/source/ucbhelper/xtempfile.cxx +++ b/unotools/source/ucbhelper/xtempfile.cxx @@ -217,6 +217,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->Flush(); + mpStream->Seek(0); + } if ( mbInClosed ) { |