summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Voitenko <mav@openoffice.org>2009-12-12 00:46:25 +0000
committerMikhail Voitenko <mav@openoffice.org>2009-12-12 00:46:25 +0000
commite80a941120b6eee8035271fc8249141cc6c76303 (patch)
tree11a9a931ff77d9a055d24a28519c9a36eee1c198
parent12c7dc97e4470d70a9df30429c3dc51343682c07 (diff)
#i104974# workaround impossibility to copy opened file
-rw-r--r--sfx2/source/doc/docfile.cxx23
-rw-r--r--sfx2/source/doc/objstor.cxx14
2 files changed, 28 insertions, 9 deletions
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index 445508e2e1..5157692bc1 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -3433,13 +3433,14 @@ void SfxMedium::CreateTempFile( sal_Bool bReplace )
if ( !( nStorOpenMode & STREAM_TRUNC ) )
{
+ sal_Bool bTransferSuccess = sal_False;
+
if ( GetContent().is()
&& ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) )
&& ::utl::UCBContentHelper::IsDocument( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) )
{
// if there is already such a document, we should copy it
// if it is a file system use OS copy process
- sal_Bool bTransferSuccess = sal_False;
try
{
uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > xComEnv;
@@ -3460,16 +3461,14 @@ void SfxMedium::CreateTempFile( sal_Bool bReplace )
catch( uno::Exception& )
{}
- if ( !bTransferSuccess )
+ if ( bTransferSuccess )
{
- SetError( ERRCODE_IO_CANTWRITE, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
- return;
+ CloseOutStream();
+ CloseInStream();
}
-
- CloseOutStream();
- CloseInStream();
}
- else if ( pInStream )
+
+ if ( !bTransferSuccess && pInStream )
{
// the case when there is no URL-access available or this is a remote protocoll
// but there is an input stream
@@ -3489,6 +3488,7 @@ void SfxMedium::CreateTempFile( sal_Bool bReplace )
pOutStream->Write( pBuf, nRead );
}
+ bTransferSuccess = sal_True;
delete[] pBuf;
CloseInStream();
}
@@ -3496,6 +3496,13 @@ void SfxMedium::CreateTempFile( sal_Bool bReplace )
}
else
CloseInStream();
+
+
+ if ( !bTransferSuccess )
+ {
+ SetError( ERRCODE_IO_CANTWRITE, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ return;
+ }
}
CloseStorage();
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index e1a8c626b2..972ac57ce6 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -1872,7 +1872,19 @@ sal_Bool SfxObjectShell::DisconnectStorage_Impl( SfxMedium& rSrcMedium, SfxMediu
{
uno::Reference< embed::XOptimizedStorage > xOptStorage( xStorage, uno::UNO_QUERY_THROW );
::rtl::OUString aBackupURL = rTargetMedium.GetBackup_Impl();
- if ( aBackupURL.getLength() )
+ if ( !aBackupURL.getLength() )
+ {
+ // the backup could not be created, try to disconnect the storage and close the source SfxMedium
+ // in this case the optimization is not possible, connect storage to a temporary file
+ rTargetMedium.ResetError();
+ xOptStorage->writeAndAttachToStream( uno::Reference< io::XStream >() );
+ rSrcMedium.CanDisposeStorage_Impl( sal_False );
+ rSrcMedium.Close();
+
+ // now try to create the backup
+ rTargetMedium.GetBackup_Impl();
+ }
+ else
{
// the following call will only compare stream sizes
// TODO/LATER: this is a very risky part, since if the URL contents are different from the storage