diff options
author | Matúš Kukan <matus.kukan@collabora.com> | 2014-10-21 10:37:02 +0200 |
---|---|---|
committer | Matúš Kukan <matus.kukan@collabora.com> | 2014-11-17 10:49:22 +0100 |
commit | db5552631b13e5a1d330929cd5093bd0f9894ec8 (patch) | |
tree | 869afbb9d5a9f52919058ac2f22b4b1955cb7cfc /package | |
parent | 30f80f12fb1db4c9c6f19fcfda4e796891b6e03c (diff) |
package: Call writeLOC always after putNextEntry explicitly
Preparation step to parallel deflating.
Rename putNextEntry to setEntry and make it a static function.
We need to call setEntry before starting thread but writeLOC after.
Change-Id: I99a9ffa7dc4c18b47c621847b48bf8469bfb789a
Diffstat (limited to 'package')
-rw-r--r-- | package/inc/ZipOutputStream.hxx | 11 | ||||
-rw-r--r-- | package/source/zipapi/ZipOutputStream.cxx | 46 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackage.cxx | 9 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackageFolder.cxx | 3 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackageStream.cxx | 8 |
5 files changed, 39 insertions, 38 deletions
diff --git a/package/inc/ZipOutputStream.hxx b/package/inc/ZipOutputStream.hxx index 2d78eb78c567..f11b8833d146 100644 --- a/package/inc/ZipOutputStream.hxx +++ b/package/inc/ZipOutputStream.hxx @@ -37,33 +37,30 @@ class ZipOutputStream ByteChucker m_aChucker; bool m_bFinished; ZipEntry *m_pCurrentEntry; - bool m_bEncrypt; public: ZipOutputStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > &xOStream ); ~ZipOutputStream(); - // rawWrite to support a direct write to the output stream + void writeLOC( ZipEntry *pEntry, bool bEncrypt = false ) + throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); void rawWrite( ::com::sun::star::uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - void rawCloseEntry() + void rawCloseEntry( bool bEncrypt = false ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - void putNextEntry( ZipEntry& rEntry, bool bEncrypt = false ) - throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); void finish() throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); static sal_uInt32 getCurrentDosTime(); + static void setEntry( ZipEntry *pEntry ); private: void writeEND(sal_uInt32 nOffset, sal_uInt32 nLength) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); void writeCEN( const ZipEntry &rEntry ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - sal_Int32 writeLOC( const ZipEntry &rEntry ) - throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); void writeEXT( const ZipEntry &rEntry ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); }; diff --git a/package/source/zipapi/ZipOutputStream.cxx b/package/source/zipapi/ZipOutputStream.cxx index 25cdb18a6990..c9b6e08cfad7 100644 --- a/package/source/zipapi/ZipOutputStream.cxx +++ b/package/source/zipapi/ZipOutputStream.cxx @@ -50,28 +50,20 @@ ZipOutputStream::~ZipOutputStream( void ) delete m_aZipList[i]; } -void ZipOutputStream::putNextEntry( ZipEntry& rEntry, bool bEncrypt ) - throw(IOException, RuntimeException) +void ZipOutputStream::setEntry( ZipEntry *pEntry ) { - assert(!m_pCurrentEntry && "Forgot to close an entry before putNextEntry()?"); - if (rEntry.nTime == -1) - rEntry.nTime = getCurrentDosTime(); - if (rEntry.nMethod == -1) - rEntry.nMethod = DEFLATED; - rEntry.nVersion = 20; - rEntry.nFlag = 1 << 11; - if (rEntry.nSize == -1 || rEntry.nCompressedSize == -1 || - rEntry.nCrc == -1) + if (pEntry->nTime == -1) + pEntry->nTime = getCurrentDosTime(); + if (pEntry->nMethod == -1) + pEntry->nMethod = DEFLATED; + pEntry->nVersion = 20; + pEntry->nFlag = 1 << 11; + if (pEntry->nSize == -1 || pEntry->nCompressedSize == -1 || + pEntry->nCrc == -1) { - rEntry.nSize = rEntry.nCompressedSize = 0; - rEntry.nFlag |= 8; + pEntry->nSize = pEntry->nCompressedSize = 0; + pEntry->nFlag |= 8; } - m_bEncrypt = bEncrypt; - - sal_Int32 nLOCLength = writeLOC(rEntry); - rEntry.nOffset = m_aChucker.GetPosition() - nLOCLength; - m_aZipList.push_back( &rEntry ); - m_pCurrentEntry = &rEntry; } void ZipOutputStream::rawWrite( Sequence< sal_Int8 >& rBuffer, sal_Int32 /*nNewOffset*/, sal_Int32 nNewLength ) @@ -80,13 +72,14 @@ void ZipOutputStream::rawWrite( Sequence< sal_Int8 >& rBuffer, sal_Int32 /*nNewO m_aChucker.WriteBytes( Sequence< sal_Int8 >(rBuffer.getConstArray(), nNewLength) ); } -void ZipOutputStream::rawCloseEntry() +void ZipOutputStream::rawCloseEntry( bool bEncrypt ) throw(IOException, RuntimeException) { + assert(m_pCurrentEntry && "Forgot to call writeLOC()?"); if ( m_pCurrentEntry->nMethod == DEFLATED && ( m_pCurrentEntry->nFlag & 8 ) ) writeEXT(*m_pCurrentEntry); - if (m_bEncrypt) + if (bEncrypt) m_pCurrentEntry->nMethod = STORED; m_pCurrentEntry = NULL; @@ -192,9 +185,14 @@ void ZipOutputStream::writeEXT( const ZipEntry &rEntry ) } } -sal_Int32 ZipOutputStream::writeLOC( const ZipEntry &rEntry ) +void ZipOutputStream::writeLOC( ZipEntry *pEntry, bool bEncrypt ) throw(IOException, RuntimeException) { + assert(!m_pCurrentEntry && "Forgot to close an entry with rawCloseEntry()?"); + m_pCurrentEntry = pEntry; + m_aZipList.push_back( m_pCurrentEntry ); + const ZipEntry &rEntry = *m_pCurrentEntry; + if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( rEntry.sPath, true ) ) throw IOException("Unexpected character is used in file name." ); @@ -206,7 +204,7 @@ sal_Int32 ZipOutputStream::writeLOC( const ZipEntry &rEntry ) m_aChucker << rEntry.nFlag; // If it's an encrypted entry, we pretend its stored plain text - if (m_bEncrypt) + if (bEncrypt) m_aChucker << static_cast < sal_Int16 > ( STORED ); else m_aChucker << rEntry.nMethod; @@ -240,7 +238,7 @@ sal_Int32 ZipOutputStream::writeLOC( const ZipEntry &rEntry ) Sequence < sal_Int8 > aSequence( (sal_Int8*)sUTF8Name.getStr(), sUTF8Name.getLength() ); m_aChucker.WriteBytes( aSequence ); - return LOCHDR + nNameLength; + m_pCurrentEntry->nOffset = m_aChucker.GetPosition() - (LOCHDR + nNameLength); } sal_uInt32 ZipOutputStream::getCurrentDosTime() diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx index a802fd5e372b..80d4d4fd179e 100644 --- a/package/source/zippackage/ZipPackage.cxx +++ b/package/source/zippackage/ZipPackage.cxx @@ -997,7 +997,8 @@ void ZipPackage::WriteMimetypeMagicFile( ZipOutputStream& aZipOut ) try { - aZipOut.putNextEntry(*pEntry); + ZipOutputStream::setEntry(pEntry); + aZipOut.writeLOC(pEntry); aZipOut.rawWrite(aType, 0, nBufferLength); aZipOut.rawCloseEntry(); } @@ -1039,7 +1040,8 @@ void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< uno::Seq pBuffer->realloc( nBufferLength ); // the manifest.xml is never encrypted - so pass an empty reference - aZipOut.putNextEntry(*pEntry); + ZipOutputStream::setEntry(pEntry); + aZipOut.writeLOC(pEntry); ZipOutputEntry aZipEntry(m_xContext, *pEntry, NULL); aZipEntry.write(pBuffer->getSequence(), 0, nBufferLength); aZipEntry.closeEntry(); @@ -1093,7 +1095,8 @@ void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< uno: pBuffer->realloc( nBufferLength ); // there is no encryption in this format currently - aZipOut.putNextEntry(*pEntry); + ZipOutputStream::setEntry(pEntry); + aZipOut.writeLOC(pEntry); ZipOutputEntry aZipEntry(m_xContext, *pEntry, NULL); aZipEntry.write(pBuffer->getSequence(), 0, nBufferLength); aZipEntry.closeEntry(); diff --git a/package/source/zippackage/ZipPackageFolder.cxx b/package/source/zippackage/ZipPackageFolder.cxx index a6b2e5c139a7..cb72ed180f4a 100644 --- a/package/source/zippackage/ZipPackageFolder.cxx +++ b/package/source/zippackage/ZipPackageFolder.cxx @@ -337,7 +337,8 @@ void ZipPackageFolder::saveContents( try { - rZipOut.putNextEntry( *pTempEntry ); + ZipOutputStream::setEntry(pTempEntry); + rZipOut.writeLOC(pTempEntry); rZipOut.rawCloseEntry(); } catch ( ZipException& ) diff --git a/package/source/zippackage/ZipPackageStream.cxx b/package/source/zippackage/ZipPackageStream.cxx index c5f8a31c4f68..ca2ad01d0bb1 100644 --- a/package/source/zippackage/ZipPackageStream.cxx +++ b/package/source/zippackage/ZipPackageStream.cxx @@ -674,7 +674,8 @@ bool ZipPackageStream::saveChild( if ( bRawStream ) xStream->skipBytes( m_nMagicalHackPos ); - rZipOut.putNextEntry(*pTempEntry); + ZipOutputStream::setEntry(pTempEntry); + rZipOut.writeLOC(pTempEntry); // the entry is provided to the ZipOutputStream that will delete it pAutoTempEntry.release(); @@ -731,7 +732,8 @@ bool ZipPackageStream::saveChild( try { - rZipOut.putNextEntry(*pTempEntry, bToBeEncrypted); + ZipOutputStream::setEntry(pTempEntry); + rZipOut.writeLOC(pTempEntry, bToBeEncrypted); // the entry is provided to the ZipOutputStream that will delete it pAutoTempEntry.release(); sal_Int32 nLength; @@ -759,7 +761,7 @@ bool ZipPackageStream::saveChild( uno::Sequence< sal_Int8 > aCompressedData = aZipEntry.getData(); rZipOut.rawWrite(aCompressedData, 0, aCompressedData.getLength()); } - rZipOut.rawCloseEntry(); + rZipOut.rawCloseEntry(bToBeEncrypted); } catch ( ZipException& ) { |