diff options
Diffstat (limited to 'package')
-rw-r--r-- | package/source/xstor/makefile.mk | 1 | ||||
-rw-r--r-- | package/source/xstor/owriteablestream.cxx | 33 | ||||
-rw-r--r-- | package/source/xstor/selfterminatefilestream.cxx | 156 | ||||
-rw-r--r-- | package/source/xstor/selfterminatefilestream.hxx | 79 | ||||
-rw-r--r-- | package/source/zipapi/ZipFile.cxx | 4 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackage.cxx | 35 |
6 files changed, 266 insertions, 42 deletions
diff --git a/package/source/xstor/makefile.mk b/package/source/xstor/makefile.mk index a0e49f2096e0..703873f9ca71 100644 --- a/package/source/xstor/makefile.mk +++ b/package/source/xstor/makefile.mk @@ -52,6 +52,7 @@ SLOFILES = \ $(SLO)$/xstorage.obj\ $(SLO)$/xfactory.obj\ $(SLO)$/disposelistener.obj\ + $(SLO)$/selfterminatefilestream.obj\ $(SLO)$/switchpersistencestream.obj\ $(SLO)$/register.obj diff --git a/package/source/xstor/owriteablestream.cxx b/package/source/xstor/owriteablestream.cxx index 67e71baf8533..4f3a912b8c0b 100644 --- a/package/source/xstor/owriteablestream.cxx +++ b/package/source/xstor/owriteablestream.cxx @@ -48,6 +48,7 @@ #include <comphelper/storagehelper.hxx> #include <comphelper/ofopxmlhelper.hxx> +#include "selfterminatefilestream.hxx" #include "owriteablestream.hxx" #include "oseekinstream.hxx" #include "mutexholder.hxx" @@ -592,18 +593,21 @@ uno::Reference< lang::XMultiServiceFactory > OWriteStream_Impl::GetServiceFactor if ( aData.getLength() > nRead ) aData.realloc( nRead ); - if ( nRead && nRead <= MAX_STORCACHE_SIZE ) + if ( nRead <= MAX_STORCACHE_SIZE ) { uno::Reference< io::XStream > xCacheStream = CreateMemoryStream( GetServiceFactory() ); OSL_ENSURE( xCacheStream.is(), "If the stream can not be created an exception must be thrown!\n" ); - uno::Reference< io::XOutputStream > xOutStream( xCacheStream->getOutputStream(), uno::UNO_SET_THROW ); - xOutStream->writeBytes( aData ); + if ( nRead ) + { + uno::Reference< io::XOutputStream > xOutStream( xCacheStream->getOutputStream(), uno::UNO_SET_THROW ); + xOutStream->writeBytes( aData ); + } m_xCacheSeek.set( xCacheStream, uno::UNO_QUERY_THROW ); m_xCacheStream = xCacheStream; m_xCacheSeek->seek( 0 ); } - else if ( nRead && !m_aTempURL.getLength() ) + else if ( !m_aTempURL.getLength() ) { m_aTempURL = GetNewTempFileURL( GetServiceFactory() ); @@ -847,6 +851,9 @@ void OWriteStream_Impl::Commit() if ( m_xCacheStream.is() ) { + if ( m_pAntiImpl ) + m_pAntiImpl->DeInit(); + uno::Reference< io::XInputStream > xInStream( m_xCacheStream->getInputStream(), uno::UNO_SET_THROW ); xNewPackageStream = uno::Reference< packages::XDataSinkEncrSupport >( @@ -858,23 +865,16 @@ void OWriteStream_Impl::Commit() m_xCacheStream = uno::Reference< io::XStream >(); m_xCacheSeek = uno::Reference< io::XSeekable >(); - if ( m_pAntiImpl ) - m_pAntiImpl->DeInit(); } else if ( m_aTempURL.getLength() ) { - uno::Reference < ucb::XSimpleFileAccess > xTempAccess( - GetServiceFactory()->createInstance ( - ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ), - uno::UNO_QUERY ); - - if ( !xTempAccess.is() ) - throw uno::RuntimeException(); // TODO: + if ( m_pAntiImpl ) + m_pAntiImpl->DeInit(); uno::Reference< io::XInputStream > xInStream; try { - xInStream = xTempAccess->openFileRead( m_aTempURL ); + xInStream.set( static_cast< io::XInputStream* >( new OSelfTerminateFileStream( GetServiceFactory(), m_aTempURL ) ), uno::UNO_QUERY ); } catch( uno::Exception& ) { @@ -890,9 +890,6 @@ void OWriteStream_Impl::Commit() // TODO/NEW: Let the temporary file be removed after commit xNewPackageStream->setDataStream( xInStream ); m_aTempURL = ::rtl::OUString(); - - if ( m_pAntiImpl ) - m_pAntiImpl->DeInit(); } else // if ( m_bHasInsertedStreamOptimization ) { @@ -2624,6 +2621,8 @@ void SAL_CALL OWriteStream::dispose() m_xInStream = uno::Reference< io::XInputStream >(); } + m_xSeekable = uno::Reference< io::XSeekable >(); + m_pImpl->m_pAntiImpl = NULL; if ( !m_bInitOnDemand ) diff --git a/package/source/xstor/selfterminatefilestream.cxx b/package/source/xstor/selfterminatefilestream.cxx new file mode 100644 index 000000000000..ebb707e59de6 --- /dev/null +++ b/package/source/xstor/selfterminatefilestream.cxx @@ -0,0 +1,156 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: ocompinstream.cxx,v $ + * $Revision: 1.12 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_package.hxx" + +#include <com/sun/star/ucb/XSimpleFileAccess.hpp> + +#include "selfterminatefilestream.hxx" +#include <comphelper/processfactory.hxx> + +using namespace ::com::sun::star; + +//----------------------------------------------- +OSelfTerminateFileStream::OSelfTerminateFileStream( const uno::Reference< lang::XMultiServiceFactory > xFactory, const ::rtl::OUString& aURL ) +: m_aURL( aURL ) +{ + uno::Reference< lang::XMultiServiceFactory > xOwnFactory = xFactory; + if ( !xOwnFactory.is() ) + xOwnFactory.set( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW ); + + // IMPORTANT: The implementation is based on idea that m_xFileAccess, m_xInputStream and m_xSeekable are always set + // otherwise an exception is thrown in constructor + + m_xFileAccess.set( xOwnFactory->createInstance ( + ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ), + uno::UNO_QUERY_THROW ); + + m_xInputStream.set( m_xFileAccess->openFileRead( aURL ), uno::UNO_SET_THROW ); + m_xSeekable.set( m_xInputStream, uno::UNO_QUERY_THROW ); +} + +//----------------------------------------------- +OSelfTerminateFileStream::~OSelfTerminateFileStream() +{ + CloseStreamDeleteFile(); +} + +//----------------------------------------------- +void OSelfTerminateFileStream::CloseStreamDeleteFile() +{ + try + { + m_xInputStream->closeInput(); + } + catch( uno::Exception& ) + {} + + try + { + m_xFileAccess->kill( m_aURL ); + } + catch( uno::Exception& ) + {} +} + +//----------------------------------------------- +sal_Int32 SAL_CALL OSelfTerminateFileStream::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) + throw ( io::NotConnectedException, + io::BufferSizeExceededException, + io::IOException, + uno::RuntimeException ) +{ + return m_xInputStream->readBytes( aData, nBytesToRead ); +} + +//----------------------------------------------- +sal_Int32 SAL_CALL OSelfTerminateFileStream::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) + throw ( io::NotConnectedException, + io::BufferSizeExceededException, + io::IOException, + uno::RuntimeException ) +{ + return m_xInputStream->readSomeBytes( aData, nMaxBytesToRead ); +} + +//----------------------------------------------- +void SAL_CALL OSelfTerminateFileStream::skipBytes( sal_Int32 nBytesToSkip ) + throw ( io::NotConnectedException, + io::BufferSizeExceededException, + io::IOException, + uno::RuntimeException ) +{ + return m_xInputStream->skipBytes( nBytesToSkip ); +} + +//----------------------------------------------- +sal_Int32 SAL_CALL OSelfTerminateFileStream::available( ) + throw ( io::NotConnectedException, + io::IOException, + uno::RuntimeException ) +{ + return m_xInputStream->available(); +} + +//----------------------------------------------- +void SAL_CALL OSelfTerminateFileStream::closeInput( ) + throw ( io::NotConnectedException, + io::IOException, + uno::RuntimeException ) +{ + CloseStreamDeleteFile(); +} + +//----------------------------------------------- +void SAL_CALL OSelfTerminateFileStream::seek( sal_Int64 location ) + throw ( lang::IllegalArgumentException, + io::IOException, + uno::RuntimeException ) +{ + m_xSeekable->seek( location ); +} + +//----------------------------------------------- +sal_Int64 SAL_CALL OSelfTerminateFileStream::getPosition() + throw ( io::IOException, + uno::RuntimeException) +{ + return m_xSeekable->getPosition(); +} + +//----------------------------------------------- +sal_Int64 SAL_CALL OSelfTerminateFileStream::getLength() + throw ( io::IOException, + uno::RuntimeException ) +{ + return m_xSeekable->getLength(); +} + diff --git a/package/source/xstor/selfterminatefilestream.hxx b/package/source/xstor/selfterminatefilestream.hxx new file mode 100644 index 000000000000..6f95ba17ec42 --- /dev/null +++ b/package/source/xstor/selfterminatefilestream.hxx @@ -0,0 +1,79 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: ocompinstream.hxx,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _SELFTERMINATEFILESTREAM_HXX_ +#define _SELFTERMINATEFILESTREAM_HXX_ + +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XSeekable.hpp> +#include <com/sun/star/ucb/XSimpleFileAccess.hpp> +#include <cppuhelper/implbase2.hxx> + +struct OWriteStream_Impl; + +class OSelfTerminateFileStream : public cppu::WeakImplHelper2< ::com::sun::star::io::XInputStream, + ::com::sun::star::io::XSeekable > +{ +protected: + ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > m_xFileAccess; + + ::rtl::OUString m_aURL; + + ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > m_xInputStream; + ::com::sun::star::uno::Reference< ::com::sun::star::io::XSeekable > m_xSeekable; + +public: + OSelfTerminateFileStream( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory, const ::rtl::OUString& aURL ); + + virtual ~OSelfTerminateFileStream(); + + void CloseStreamDeleteFile(); + + // XInputStream + virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) + throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) + throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) + throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual sal_Int32 SAL_CALL available() + throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL closeInput() + throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + + //XSeekable + virtual void SAL_CALL seek( sal_Int64 location ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual sal_Int64 SAL_CALL getPosition() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual sal_Int64 SAL_CALL getLength() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + +}; + +#endif + diff --git a/package/source/zipapi/ZipFile.cxx b/package/source/zipapi/ZipFile.cxx index f6dafac4cb6a..9934caa0c066 100644 --- a/package/source/zipapi/ZipFile.cxx +++ b/package/source/zipapi/ZipFile.cxx @@ -880,8 +880,8 @@ sal_Int32 ZipFile::recover() if ( aEntry.nExtraLen < 0 ) aEntry.nExtraLen = 0x7FFF; // End of quick fix - - sal_Int32 nBlockLength = aEntry.nSize + aEntry.nPathLen + aEntry.nExtraLen + 30 + nDescrLength; + sal_Int32 nDataSize = ( aEntry.nMethod == DEFLATED ) ? aEntry.nCompressedSize : aEntry.nSize; + sal_Int32 nBlockLength = nDataSize + aEntry.nPathLen + aEntry.nExtraLen + 30 + nDescrLength; if ( aEntry.nPathLen <= ZIP_MAXNAMELEN && aEntry.nExtraLen < ZIP_MAXEXTRA && ( nGenPos + nPos + nBlockLength ) <= nLength ) { diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx index 6ca9981d2291..a692586681b5 100644 --- a/package/source/zippackage/ZipPackage.cxx +++ b/package/source/zippackage/ZipPackage.cxx @@ -135,25 +135,6 @@ sal_Bool isLocalFile_Impl( ::rtl::OUString aURL ) return ( aSystemPath.getLength() != 0 ); } -class PostinitializationGuard -{ - uno::Reference< io::XInputStream > m_xTempStream; - - ZipPackage& m_rZipPackage; - -public: - PostinitializationGuard( const uno::Reference< io::XInputStream >& xTempStream, - ZipPackage& rZipPackage ) - : m_xTempStream( xTempStream ) - , m_rZipPackage( rZipPackage ) - {} - - virtual ~PostinitializationGuard() - { - m_rZipPackage.ConnectTo( m_xTempStream ); - } -}; - } //=========================================================================== @@ -1370,8 +1351,18 @@ void SAL_CALL ZipPackage::commitChanges() { uno::Reference< io::XSeekable > xTempSeek( xTempInStream, uno::UNO_QUERY_THROW ); - // switch to the new temporary stream only after the transfer - PostinitializationGuard aPostInitGuard( xTempInStream, *this ); + try + { + xTempSeek->seek( 0 ); + } + catch( uno::Exception& r ) + { + throw WrappedTargetException( OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "Temporary file should be seekable!" ) ), + static_cast < OWeakObject * > ( this ), makeAny ( r ) ); + } + + // connect to the temporary stream + ConnectTo( xTempInStream ); if ( m_eMode == e_IMode_XStream ) { @@ -1381,8 +1372,6 @@ void SAL_CALL ZipPackage::commitChanges() // preparation for copy step try { - xTempSeek->seek( 0 ); - xOutputStream = m_xStream->getOutputStream(); uno::Reference < XTruncate > xTruncate ( xOutputStream, UNO_QUERY ); if ( !xTruncate.is() ) |