[Libreoffice-commits] core.git: 2 commits - package/inc package/source
Kohei Yoshida
kohei.yoshida at collabora.com
Thu Jan 12 02:33:29 UTC 2017
package/inc/ZipFile.hxx | 1 -
package/inc/ZipPackage.hxx | 3 ++-
package/source/zipapi/ZipFile.cxx | 4 +---
package/source/zippackage/ZipPackage.cxx | 12 +++++-------
4 files changed, 8 insertions(+), 12 deletions(-)
New commits:
commit f7c9ecaac9017e94e1dbcd5295b4d6fa3a33948f
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Wed Jan 11 19:39:25 2017 -0500
Use std::unique_ptr for the ZipFile instance.
Change-Id: Ifac7a9e29c8cf0afcf44a82db608ba3c48499ca1
diff --git a/package/inc/ZipPackage.hxx b/package/inc/ZipPackage.hxx
index 2856e42..6a3ac01 100644
--- a/package/inc/ZipPackage.hxx
+++ b/package/inc/ZipPackage.hxx
@@ -36,6 +36,7 @@
#include <osl/file.h>
#include <mutexholder.hxx>
#include <vector>
+#include <memory>
class ZipOutputStream;
class ZipPackageFolder;
@@ -97,7 +98,7 @@ protected:
css::uno::Reference < css::io::XSeekable > m_xContentSeek;
const css::uno::Reference < css::uno::XComponentContext > m_xContext;
- ZipFile *m_pZipFile;
+ std::unique_ptr<ZipFile> m_pZipFile;
bool isLocalFile() const;
diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx
index 026e1ed..cb2e618 100644
--- a/package/source/zippackage/ZipPackage.cxx
+++ b/package/source/zippackage/ZipPackage.cxx
@@ -69,7 +69,6 @@
#include "com/sun/star/io/XAsyncOutputMonitor.hpp"
#include <cstring>
-#include <memory>
#include <vector>
#include <comphelper/processfactory.hxx>
@@ -80,6 +79,7 @@
#include <comphelper/sequenceashashmap.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <comphelper/sequence.hxx>
+#include <o3tl/make_unique.hxx>
using namespace std;
using namespace osl;
@@ -156,14 +156,12 @@ ZipPackage::ZipPackage ( const uno::Reference < XComponentContext > &xContext )
, m_bAllowRemoveOnInsert( true )
, m_eMode ( e_IMode_None )
, m_xContext( xContext )
-, m_pZipFile( nullptr )
{
m_xRootFolder = new ZipPackageFolder( m_xContext, m_nFormat, m_bAllowRemoveOnInsert );
}
ZipPackage::~ZipPackage()
{
- delete m_pZipFile;
}
bool ZipPackage::isLocalFile() const
@@ -734,7 +732,7 @@ void SAL_CALL ZipPackage::initialize( const uno::Sequence< Any >& aArguments )
OUString message;
try
{
- m_pZipFile = new ZipFile ( m_xContentStream, m_xContext, true, m_bForceRecovery );
+ m_pZipFile = o3tl::make_unique<ZipFile>(m_xContentStream, m_xContext, true, m_bForceRecovery);
getZipFileContents();
}
catch ( IOException & e )
@@ -749,14 +747,14 @@ void SAL_CALL ZipPackage::initialize( const uno::Sequence< Any >& aArguments )
}
catch ( Exception & )
{
- if( m_pZipFile ) { delete m_pZipFile; m_pZipFile = nullptr; }
+ m_pZipFile.reset();
throw;
}
if ( bBadZipFile )
{
// clean up the memory, and tell the UCB about the error
- if( m_pZipFile ) { delete m_pZipFile; m_pZipFile = nullptr; }
+ m_pZipFile.reset();
throw css::packages::zip::ZipIOException (
THROW_WHERE "Bad Zip File, " + message,
@@ -1104,7 +1102,7 @@ void ZipPackage::ConnectTo( const uno::Reference< io::XInputStream >& xInStream
if ( m_pZipFile )
m_pZipFile->setInputStream( m_xContentStream );
else
- m_pZipFile = new ZipFile ( m_xContentStream, m_xContext, false );
+ m_pZipFile = o3tl::make_unique<ZipFile>(m_xContentStream, m_xContext, false);
}
namespace
commit e5dc4ab7a023b003d312ea6f12e6473599993335
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Wed Jan 11 17:08:50 2017 -0500
Not worth having this as a separate data member.
It is the same as the input stream instance, and it is only used in
one call site.
Change-Id: If52209420462aec7ec3dbc180e05f09603acaea1
diff --git a/package/inc/ZipFile.hxx b/package/inc/ZipFile.hxx
index bac0168..962733c 100644
--- a/package/inc/ZipFile.hxx
+++ b/package/inc/ZipFile.hxx
@@ -61,7 +61,6 @@ class ZipFile
ByteGrabber aGrabber;
ZipUtils::Inflater aInflater;
css::uno::Reference < css::io::XInputStream > xStream;
- css::uno::Reference < css::io::XSeekable > xSeek;
const css::uno::Reference < css::uno::XComponentContext > m_xContext;
bool bRecoveryMode;
diff --git a/package/source/zipapi/ZipFile.cxx b/package/source/zipapi/ZipFile.cxx
index 49264b0..6b397c6 100644
--- a/package/source/zipapi/ZipFile.cxx
+++ b/package/source/zipapi/ZipFile.cxx
@@ -72,7 +72,6 @@ ZipFile::ZipFile( uno::Reference < XInputStream > &xInput, const uno::Reference
: aGrabber(xInput)
, aInflater( true )
, xStream(xInput)
-, xSeek(xInput, UNO_QUERY)
, m_xContext ( rxContext )
, bRecoveryMode( false )
{
@@ -90,7 +89,6 @@ ZipFile::ZipFile( uno::Reference < XInputStream > &xInput, const uno::Reference
: aGrabber(xInput)
, aInflater( true )
, xStream(xInput)
-, xSeek(xInput, UNO_QUERY)
, m_xContext ( rxContext )
, bRecoveryMode( bForceRecovery )
{
@@ -118,7 +116,6 @@ void ZipFile::setInputStream ( const uno::Reference < XInputStream >& xNewStream
::osl::MutexGuard aGuard( m_aMutex );
xStream = xNewStream;
- xSeek.set( xStream, UNO_QUERY );
aGrabber.setInputStream ( xStream );
}
@@ -489,6 +486,7 @@ bool ZipFile::hasValidPassword ( ZipEntry & rEntry, const ::rtl::Reference< Encr
bool bRet = false;
if ( rData.is() && rData->m_aKey.getLength() )
{
+ css::uno::Reference < css::io::XSeekable > xSeek(xStream, UNO_QUERY_THROW);
xSeek->seek( rEntry.nOffset );
sal_Int64 nSize = rEntry.nMethod == DEFLATED ? rEntry.nCompressedSize : rEntry.nSize;
More information about the Libreoffice-commits
mailing list