diff options
author | Caolán McNamara <caolanm@redhat.com> | 2013-06-21 16:05:04 +0100 |
---|---|---|
committer | Fridrich Strba <fridrich@documentfoundation.org> | 2013-06-23 04:09:37 +0000 |
commit | e54b0c7c36e7368d7b4fffd0ddd3f3c57349a938 (patch) | |
tree | 64365642d5be2f5fbb77327167d1f4a2e826f470 | |
parent | 5b3867f801dadc5c2c6346561e7d71990cd7eb33 (diff) |
Resolves: fdo#65501 ensure configured backup dir exists before using it
the ucb stuff is the most god awful painful api ever
Change-Id: I491d2cb9b7d5d37723b32f0a26a22a09c16bc02e
(cherry picked from commit ecdd9d1a47587aa7557c1b151010c78efa90fef2)
Reviewed-on: https://gerrit.libreoffice.org/4434
Reviewed-by: Fridrich Strba <fridrich@documentfoundation.org>
Tested-by: Fridrich Strba <fridrich@documentfoundation.org>
-rw-r--r-- | sfx2/source/doc/docfile.cxx | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx index d08f3fcdb514..70cee7593d13 100644 --- a/sfx2/source/doc/docfile.cxx +++ b/sfx2/source/doc/docfile.cxx @@ -2113,6 +2113,25 @@ void SfxMedium::DoInternalBackup_Impl( const ::ucbhelper::Content& aOriginalCont aTransactTemp.EnableKillingFile( true ); } +bool ensureFolder( + uno::Reference< uno::XComponentContext > xCtx, + uno::Reference< ucb::XCommandEnvironment > xEnv, + const OUString& rFolder, ucbhelper::Content & result) +{ + INetURLObject aURL( rFolder ); + OUString aTitle = aURL.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ); + aURL.removeSegment(); + ::ucbhelper::Content aParent; + + if ( ::ucbhelper::Content::create( aURL.GetMainURL( INetURLObject::NO_DECODE ), + xEnv, xCtx, aParent ) ) + { + return ::utl::UCBContentHelper::MakeFolder(aParent, aTitle, result); + } + + return false; +} + //------------------------------------------------------------------ void SfxMedium::DoInternalBackup_Impl( const ::ucbhelper::Content& aOriginalContent ) { @@ -2126,9 +2145,13 @@ void SfxMedium::DoInternalBackup_Impl( const ::ucbhelper::Content& aOriginalCont sal_Int32 nPrefixLen = aFileName.lastIndexOf( '.' ); String aPrefix = ( nPrefixLen == -1 ) ? aFileName : aFileName.copy( 0, nPrefixLen ); String aExtension = ( nPrefixLen == -1 ) ? String() : String(aFileName.copy( nPrefixLen )); - String aBakDir = SvtPathOptions().GetBackupPath(); + String aBakDir = SvtPathOptions().GetBackupPath(); - DoInternalBackup_Impl( aOriginalContent, aPrefix, aExtension, aBakDir ); + // create content for the parent folder ( = backup folder ) + ::ucbhelper::Content aContent; + Reference < ::com::sun::star::ucb::XCommandEnvironment > xEnv; + if( ensureFolder(comphelper::getProcessComponentContext(), xEnv, aBakDir, aContent) ) + DoInternalBackup_Impl( aOriginalContent, aPrefix, aExtension, aBakDir ); if ( pImp->m_aBackupURL.isEmpty() ) { @@ -2167,7 +2190,7 @@ void SfxMedium::DoBackup_Impl() // create content for the parent folder ( = backup folder ) ::ucbhelper::Content aContent; Reference < ::com::sun::star::ucb::XCommandEnvironment > xEnv; - if( ::ucbhelper::Content::create( aBakDir, xEnv, comphelper::getProcessComponentContext(), aContent ) ) + if( ensureFolder(comphelper::getProcessComponentContext(), xEnv, aBakDir, aContent) ) { // save as ".bak" file INetURLObject aDest( aBakDir ); |