summaryrefslogtreecommitdiff
path: root/package
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2019-04-07 11:48:47 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2019-04-07 17:53:04 +0200
commit5a824268dfdd48c00f656b767b48cd12ccbdaabb (patch)
treea25f4afd3ca49cff41fc44559aedea70c82e6c7e /package
parenta6186a678cd9f67359da885606b3c3983f6bdc74 (diff)
Don't use resettable/clearable guard where plain guard is enough
Also use scope where possible. This allows to limit guard scope at language level; visualises the scope clearly; and helps avoiding errors like fixed in commit 61e4437c857854b331fa01da6f39b2b3b58a800b. Change-Id: Ifeca96e2df8e8a0897770d9546b2536806275f41 Reviewed-on: https://gerrit.libreoffice.org/70376 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'package')
-rw-r--r--package/source/xstor/ohierarchyholder.cxx14
-rw-r--r--package/source/xstor/owriteablestream.cxx84
-rw-r--r--package/source/xstor/owriteablestream.hxx2
-rw-r--r--package/source/xstor/xstorage.cxx536
4 files changed, 328 insertions, 308 deletions
diff --git a/package/source/xstor/ohierarchyholder.cxx b/package/source/xstor/ohierarchyholder.cxx
index 26b63f806eae..20c613b8b8d2 100644
--- a/package/source/xstor/ohierarchyholder.cxx
+++ b/package/source/xstor/ohierarchyholder.cxx
@@ -261,15 +261,15 @@ void SAL_CALL OHierarchyElement_Impl::disposing( const lang::EventObject& Source
{
try
{
- ::osl::ClearableMutexGuard aGuard( m_aMutex );
- uno::Reference< embed::XExtendedStorageStream > xStream( Source.Source, uno::UNO_QUERY );
+ {
+ osl::MutexGuard aGuard(m_aMutex);
+ uno::Reference< embed::XExtendedStorageStream > xStream(Source.Source, uno::UNO_QUERY);
- m_aOpenStreams.erase(std::remove_if(m_aOpenStreams.begin(), m_aOpenStreams.end(),
- [&xStream](const OWeakStorRefList_Impl::value_type& rxStorage) {
+ m_aOpenStreams.erase(std::remove_if(m_aOpenStreams.begin(), m_aOpenStreams.end(),
+ [&xStream](const OWeakStorRefList_Impl::value_type& rxStorage) {
return !rxStorage.get().is() || rxStorage.get() == xStream; }),
- m_aOpenStreams.end());
-
- aGuard.clear();
+ m_aOpenStreams.end());
+ }
TestForClosing();
}
diff --git a/package/source/xstor/owriteablestream.cxx b/package/source/xstor/owriteablestream.cxx
index 5f27ba5d7774..67f152075131 100644
--- a/package/source/xstor/owriteablestream.cxx
+++ b/package/source/xstor/owriteablestream.cxx
@@ -1783,7 +1783,7 @@ void OWriteStream::CopyToStreamInternally_Impl( const uno::Reference< io::XStrea
}
}
-void OWriteStream::ModifyParentUnlockMutex_Impl( ::osl::ResettableMutexGuard& aGuard )
+void OWriteStream::ModifyParentUnlockMutex_Impl(osl::ClearableMutexGuard& aGuard)
{
if ( m_pImpl->m_pParent )
{
@@ -2116,7 +2116,7 @@ uno::Reference< io::XOutputStream > SAL_CALL OWriteStream::getOutputStream()
void SAL_CALL OWriteStream::writeBytes( const uno::Sequence< sal_Int8 >& aData )
{
- ::osl::ResettableMutexGuard aGuard( m_pData->m_xSharedMutex->GetMutex() );
+ osl::ClearableMutexGuard aGuard(m_pData->m_xSharedMutex->GetMutex());
// the write method makes initialization itself, since it depends from the aData length
// NO CheckInitOnDemand()!
@@ -2301,7 +2301,7 @@ sal_Int64 SAL_CALL OWriteStream::getLength()
void SAL_CALL OWriteStream::truncate()
{
- ::osl::ResettableMutexGuard aGuard( m_pData->m_xSharedMutex->GetMutex() );
+ osl::ClearableMutexGuard aGuard(m_pData->m_xSharedMutex->GetMutex());
CheckInitOnDemand();
@@ -2414,7 +2414,7 @@ void SAL_CALL OWriteStream::removeEventListener(
void SAL_CALL OWriteStream::setEncryptionPassword( const OUString& aPass )
{
- ::osl::ResettableMutexGuard aGuard( m_pData->m_xSharedMutex->GetMutex() );
+ osl::ClearableMutexGuard aGuard(m_pData->m_xSharedMutex->GetMutex());
CheckInitOnDemand();
@@ -2433,7 +2433,7 @@ void SAL_CALL OWriteStream::setEncryptionPassword( const OUString& aPass )
void SAL_CALL OWriteStream::removeEncryption()
{
- ::osl::ResettableMutexGuard aGuard( m_pData->m_xSharedMutex->GetMutex() );
+ osl::ClearableMutexGuard aGuard(m_pData->m_xSharedMutex->GetMutex());
CheckInitOnDemand();
@@ -2452,7 +2452,7 @@ void SAL_CALL OWriteStream::removeEncryption()
void SAL_CALL OWriteStream::setEncryptionData( const uno::Sequence< beans::NamedValue >& aEncryptionData )
{
- ::osl::ResettableMutexGuard aGuard( m_pData->m_xSharedMutex->GetMutex() );
+ osl::ClearableMutexGuard aGuard(m_pData->m_xSharedMutex->GetMutex());
CheckInitOnDemand();
@@ -2471,7 +2471,7 @@ void SAL_CALL OWriteStream::setEncryptionData( const uno::Sequence< beans::Named
sal_Bool SAL_CALL OWriteStream::hasEncryptionData()
{
- ::osl::ResettableMutexGuard aGuard( m_pData->m_xSharedMutex->GetMutex() );
+ osl::ClearableMutexGuard aGuard(m_pData->m_xSharedMutex->GetMutex());
if (!m_pImpl)
return false;
@@ -2849,7 +2849,7 @@ uno::Reference< beans::XPropertySetInfo > SAL_CALL OWriteStream::getPropertySetI
void SAL_CALL OWriteStream::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
{
- ::osl::ResettableMutexGuard aGuard( m_pData->m_xSharedMutex->GetMutex() );
+ osl::ClearableMutexGuard aGuard(m_pData->m_xSharedMutex->GetMutex());
if ( !m_pImpl )
{
@@ -3142,7 +3142,7 @@ void SAL_CALL OWriteStream::commit()
try {
BroadcastTransaction( STOR_MESS_PRECOMMIT );
- ::osl::ResettableMutexGuard aGuard( m_pData->m_xSharedMutex->GetMutex() );
+ osl::ClearableMutexGuard aGuard(m_pData->m_xSharedMutex->GetMutex());
if ( !m_pImpl )
{
@@ -3199,42 +3199,42 @@ void SAL_CALL OWriteStream::revert()
BroadcastTransaction( STOR_MESS_PREREVERT );
- ::osl::ResettableMutexGuard aGuard( m_pData->m_xSharedMutex->GetMutex() );
-
- if ( !m_pImpl )
{
- SAL_INFO("package.xstor", "Disposed!");
- throw lang::DisposedException();
- }
+ osl::MutexGuard aGuard(m_pData->m_xSharedMutex->GetMutex());
- try {
- m_pImpl->Revert();
- }
- catch( const io::IOException& rIOException )
- {
- SAL_INFO("package.xstor", "Rethrow: " << rIOException);
- throw;
- }
- catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
- {
- SAL_INFO("package.xstor", "Rethrow: " << rStorageWrappedTargetException);
- throw;
- }
- catch( const uno::RuntimeException& rRuntimeException )
- {
- SAL_INFO("package.xstor", "Rethrow: " << rRuntimeException);
- throw;
- }
- catch( const uno::Exception& )
- {
- uno::Any aCaught( ::cppu::getCaughtException() );
- SAL_INFO("package.xstor", "Rethrow: " << exceptionToString(aCaught));
- throw embed::StorageWrappedTargetException( "Problems on revert!",
- static_cast< ::cppu::OWeakObject* >( this ),
- aCaught );
- }
+ if (!m_pImpl)
+ {
+ SAL_INFO("package.xstor", "Disposed!");
+ throw lang::DisposedException();
+ }
- aGuard.clear();
+ try {
+ m_pImpl->Revert();
+ }
+ catch (const io::IOException& rIOException)
+ {
+ SAL_INFO("package.xstor", "Rethrow: " << rIOException);
+ throw;
+ }
+ catch (const embed::StorageWrappedTargetException& rStorageWrappedTargetException)
+ {
+ SAL_INFO("package.xstor", "Rethrow: " << rStorageWrappedTargetException);
+ throw;
+ }
+ catch (const uno::RuntimeException& rRuntimeException)
+ {
+ SAL_INFO("package.xstor", "Rethrow: " << rRuntimeException);
+ throw;
+ }
+ catch (const uno::Exception&)
+ {
+ uno::Any aCaught(::cppu::getCaughtException());
+ SAL_INFO("package.xstor", "Rethrow: " << exceptionToString(aCaught));
+ throw embed::StorageWrappedTargetException("Problems on revert!",
+ static_cast<::cppu::OWeakObject*>(this),
+ aCaught);
+ }
+ }
BroadcastTransaction( STOR_MESS_REVERTED );
}
diff --git a/package/source/xstor/owriteablestream.hxx b/package/source/xstor/owriteablestream.hxx
index 7d7abf6647c3..629d679fdccf 100644
--- a/package/source/xstor/owriteablestream.hxx
+++ b/package/source/xstor/owriteablestream.hxx
@@ -257,7 +257,7 @@ protected:
void CopyToStreamInternally_Impl( const css::uno::Reference< css::io::XStream >& xStream );
- void ModifyParentUnlockMutex_Impl( ::osl::ResettableMutexGuard& aGuard );
+ void ModifyParentUnlockMutex_Impl(osl::ClearableMutexGuard& aGuard);
void BroadcastTransaction( sal_Int8 nMessage );
diff --git a/package/source/xstor/xstorage.cxx b/package/source/xstor/xstorage.cxx
index 1130c344ce51..20dff2794b63 100644
--- a/package/source/xstor/xstorage.cxx
+++ b/package/source/xstor/xstorage.cxx
@@ -2231,7 +2231,7 @@ void SAL_CALL OStorage::copyToStorage( const uno::Reference< embed::XStorage >&
uno::Reference< io::XStream > SAL_CALL OStorage::openStreamElement(
const OUString& aStreamName, sal_Int32 nOpenMode )
{
- ::osl::ResettableMutexGuard aGuard( m_pData->m_xSharedMutex->GetMutex() );
+ osl::ClearableMutexGuard aGuard(m_pData->m_xSharedMutex->GetMutex());
if ( !m_pImpl )
{
@@ -2770,161 +2770,167 @@ sal_Bool SAL_CALL OStorage::isStorageElement( const OUString& aElementName )
void SAL_CALL OStorage::removeElement( const OUString& aElementName )
{
- ::osl::ResettableMutexGuard aGuard( m_pData->m_xSharedMutex->GetMutex() );
-
- if ( !m_pImpl )
{
- SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
- throw lang::DisposedException( THROW_WHERE );
- }
+ osl::MutexGuard aGuard(m_pData->m_xSharedMutex->GetMutex());
- if ( aElementName.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, false ) )
- throw lang::IllegalArgumentException( THROW_WHERE "Unexpected entry name syntax.", uno::Reference< uno::XInterface >(), 1 );
+ if (!m_pImpl)
+ {
+ SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
+ throw lang::DisposedException(THROW_WHERE);
+ }
- if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && aElementName == "_rels" )
- throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 1 ); // TODO: unacceptable name
+ if (aElementName.isEmpty()
+ || !::comphelper::OStorageHelper::IsValidZipEntryFileName(aElementName, false))
+ throw lang::IllegalArgumentException(THROW_WHERE "Unexpected entry name syntax.",
+ uno::Reference<uno::XInterface>(), 1);
- if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) )
- throw io::IOException( THROW_WHERE ); // TODO: access denied
+ if (m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && aElementName == "_rels")
+ throw lang::IllegalArgumentException(THROW_WHERE, uno::Reference<uno::XInterface>(),
+ 1); // TODO: unacceptable name
- try
- {
- SotElement_Impl* pElement = m_pImpl->FindElement( aElementName );
+ if (!(m_pImpl->m_nStorageMode & embed::ElementModes::WRITE))
+ throw io::IOException(THROW_WHERE); // TODO: access denied
- if ( !pElement )
- throw container::NoSuchElementException( THROW_WHERE ); //???
+ try
+ {
+ SotElement_Impl* pElement = m_pImpl->FindElement(aElementName);
- m_pImpl->RemoveElement( pElement );
+ if (!pElement)
+ throw container::NoSuchElementException(THROW_WHERE); //???
- m_pImpl->m_bIsModified = true;
- m_pImpl->m_bBroadcastModified = true;
- }
- catch( const embed::InvalidStorageException& rInvalidStorageException )
- {
- SAL_INFO("package.xstor", "Rethrow: " << rInvalidStorageException);
- throw;
- }
- catch( const lang::IllegalArgumentException& rIllegalArgumentException )
- {
- SAL_INFO("package.xstor", "Rethrow: " << rIllegalArgumentException);
- throw;
- }
- catch( const container::NoSuchElementException& rNoSuchElementException )
- {
- SAL_INFO("package.xstor", "Rethrow: " << rNoSuchElementException);
- throw;
- }
- catch( const io::IOException& rIOException )
- {
- SAL_INFO("package.xstor", "Rethrow: " << rIOException);
- throw;
- }
- catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
- {
- SAL_INFO("package.xstor", "Rethrow: " << rStorageWrappedTargetException);
- throw;
- }
- catch( const uno::RuntimeException& rRuntimeException )
- {
- SAL_INFO("package.xstor", "Rethrow: " << rRuntimeException);
- throw;
- }
- catch( const uno::Exception& )
- {
- uno::Any aCaught( ::cppu::getCaughtException() );
- SAL_INFO("package.xstor", "Rethrow: " << exceptionToString(aCaught));
+ m_pImpl->RemoveElement(pElement);
- throw embed::StorageWrappedTargetException( THROW_WHERE "Can't remove element!",
- uno::Reference< io::XInputStream >(),
- aCaught );
- }
+ m_pImpl->m_bIsModified = true;
+ m_pImpl->m_bBroadcastModified = true;
+ }
+ catch (const embed::InvalidStorageException& rInvalidStorageException)
+ {
+ SAL_INFO("package.xstor", "Rethrow: " << rInvalidStorageException);
+ throw;
+ }
+ catch (const lang::IllegalArgumentException& rIllegalArgumentException)
+ {
+ SAL_INFO("package.xstor", "Rethrow: " << rIllegalArgumentException);
+ throw;
+ }
+ catch (const container::NoSuchElementException& rNoSuchElementException)
+ {
+ SAL_INFO("package.xstor", "Rethrow: " << rNoSuchElementException);
+ throw;
+ }
+ catch (const io::IOException& rIOException)
+ {
+ SAL_INFO("package.xstor", "Rethrow: " << rIOException);
+ throw;
+ }
+ catch (const embed::StorageWrappedTargetException& rStorageWrappedTargetException)
+ {
+ SAL_INFO("package.xstor", "Rethrow: " << rStorageWrappedTargetException);
+ throw;
+ }
+ catch (const uno::RuntimeException& rRuntimeException)
+ {
+ SAL_INFO("package.xstor", "Rethrow: " << rRuntimeException);
+ throw;
+ }
+ catch (const uno::Exception&)
+ {
+ uno::Any aCaught(::cppu::getCaughtException());
+ SAL_INFO("package.xstor", "Rethrow: " << exceptionToString(aCaught));
- aGuard.clear();
+ throw embed::StorageWrappedTargetException(THROW_WHERE "Can't remove element!",
+ uno::Reference<io::XInputStream>(), aCaught);
+ }
+ }
BroadcastModifiedIfNecessary();
}
void SAL_CALL OStorage::renameElement( const OUString& aElementName, const OUString& aNewName )
{
- ::osl::ResettableMutexGuard aGuard( m_pData->m_xSharedMutex->GetMutex() );
-
- if ( !m_pImpl )
{
- SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
- throw lang::DisposedException( THROW_WHERE );
- }
+ osl::MutexGuard aGuard(m_pData->m_xSharedMutex->GetMutex());
- if ( aElementName.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, false )
- || aNewName.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aNewName, false ) )
- throw lang::IllegalArgumentException( THROW_WHERE "Unexpected entry name syntax.", uno::Reference< uno::XInterface >(), 1 );
+ if (!m_pImpl)
+ {
+ SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
+ throw lang::DisposedException(THROW_WHERE);
+ }
- if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && ( aElementName == "_rels" || aNewName == "_rels" ) )
- throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 0 ); // TODO: unacceptable element name
+ if (aElementName.isEmpty()
+ || !::comphelper::OStorageHelper::IsValidZipEntryFileName(aElementName, false)
+ || aNewName.isEmpty()
+ || !::comphelper::OStorageHelper::IsValidZipEntryFileName(aNewName, false))
+ throw lang::IllegalArgumentException(THROW_WHERE "Unexpected entry name syntax.",
+ uno::Reference<uno::XInterface>(), 1);
- if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) )
- throw io::IOException( THROW_WHERE ); // TODO: access denied
+ if (m_pData->m_nStorageType == embed::StorageFormats::OFOPXML
+ && (aElementName == "_rels" || aNewName == "_rels"))
+ throw lang::IllegalArgumentException(THROW_WHERE, uno::Reference<uno::XInterface>(),
+ 0); // TODO: unacceptable element name
- try
- {
- SotElement_Impl* pRefElement = m_pImpl->FindElement( aNewName );
- if ( pRefElement )
- throw container::ElementExistException( THROW_WHERE ); //???
+ if (!(m_pImpl->m_nStorageMode & embed::ElementModes::WRITE))
+ throw io::IOException(THROW_WHERE); // TODO: access denied
- SotElement_Impl* pElement = m_pImpl->FindElement( aElementName );
- if ( !pElement )
- throw container::NoSuchElementException( THROW_WHERE ); //???
+ try
+ {
+ SotElement_Impl* pRefElement = m_pImpl->FindElement(aNewName);
+ if (pRefElement)
+ throw container::ElementExistException(THROW_WHERE); //???
- pElement->m_aName = aNewName;
+ SotElement_Impl* pElement = m_pImpl->FindElement(aElementName);
+ if (!pElement)
+ throw container::NoSuchElementException(THROW_WHERE); //???
- m_pImpl->m_bIsModified = true;
- m_pImpl->m_bBroadcastModified = true;
- }
- catch( const embed::InvalidStorageException& rInvalidStorageException )
- {
- SAL_INFO("package.xstor", "Rethrow: " << rInvalidStorageException);
- throw;
- }
- catch( const lang::IllegalArgumentException& rIllegalArgumentException )
- {
- SAL_INFO("package.xstor", "Rethrow: " << rIllegalArgumentException);
- throw;
- }
- catch( const container::NoSuchElementException& rNoSuchElementException )
- {
- SAL_INFO("package.xstor", "Rethrow: " << rNoSuchElementException);
- throw;
- }
- catch( const container::ElementExistException& rElementExistException )
- {
- SAL_INFO("package.xstor", "Rethrow: " << rElementExistException);
- throw;
- }
- catch( const io::IOException& rIOException )
- {
- SAL_INFO("package.xstor", "Rethrow: " << rIOException);
- throw;
- }
- catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
- {
- SAL_INFO("package.xstor", "Rethrow: " << rStorageWrappedTargetException);
- throw;
- }
- catch( const uno::RuntimeException& rRuntimeException )
- {
- SAL_INFO("package.xstor", "Rethrow: " << rRuntimeException);
- throw;
- }
- catch( const uno::Exception& )
- {
- uno::Any aCaught( ::cppu::getCaughtException() );
- SAL_INFO("package.xstor", "Rethrow: " << exceptionToString(aCaught));
+ pElement->m_aName = aNewName;
- throw embed::StorageWrappedTargetException( THROW_WHERE "Can't rename element!",
- uno::Reference< io::XInputStream >(),
- aCaught );
- }
+ m_pImpl->m_bIsModified = true;
+ m_pImpl->m_bBroadcastModified = true;
+ }
+ catch (const embed::InvalidStorageException& rInvalidStorageException)
+ {
+ SAL_INFO("package.xstor", "Rethrow: " << rInvalidStorageException);
+ throw;
+ }
+ catch (const lang::IllegalArgumentException& rIllegalArgumentException)
+ {
+ SAL_INFO("package.xstor", "Rethrow: " << rIllegalArgumentException);
+ throw;
+ }
+ catch (const container::NoSuchElementException& rNoSuchElementException)
+ {
+ SAL_INFO("package.xstor", "Rethrow: " << rNoSuchElementException);
+ throw;
+ }
+ catch (const container::ElementExistException& rElementExistException)
+ {
+ SAL_INFO("package.xstor", "Rethrow: " << rElementExistException);
+ throw;
+ }
+ catch (const io::IOException& rIOException)
+ {
+ SAL_INFO("package.xstor", "Rethrow: " << rIOException);
+ throw;
+ }
+ catch (const embed::StorageWrappedTargetException& rStorageWrappedTargetException)
+ {
+ SAL_INFO("package.xstor", "Rethrow: " << rStorageWrappedTargetException);
+ throw;
+ }
+ catch (const uno::RuntimeException& rRuntimeException)
+ {
+ SAL_INFO("package.xstor", "Rethrow: " << rRuntimeException);
+ throw;
+ }
+ catch (const uno::Exception&)
+ {
+ uno::Any aCaught(::cppu::getCaughtException());
+ SAL_INFO("package.xstor", "Rethrow: " << exceptionToString(aCaught));
- aGuard.clear();
+ throw embed::StorageWrappedTargetException(THROW_WHERE "Can't rename element!",
+ uno::Reference<io::XInputStream>(), aCaught);
+ }
+ }
BroadcastModifiedIfNecessary();
}
@@ -3014,90 +3020,97 @@ void SAL_CALL OStorage::moveElementTo( const OUString& aElementName,
const uno::Reference< embed::XStorage >& xDest,
const OUString& aNewName )
{
- ::osl::ResettableMutexGuard aGuard( m_pData->m_xSharedMutex->GetMutex() );
-
- if ( !m_pImpl )
{
- SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
- throw lang::DisposedException( THROW_WHERE );
- }
+ osl::MutexGuard aGuard(m_pData->m_xSharedMutex->GetMutex());
- if ( aElementName.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, false )
- || aNewName.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aNewName, false ) )
- throw lang::IllegalArgumentException( THROW_WHERE "Unexpected entry name syntax.", uno::Reference< uno::XInterface >(), 1 );
+ if (!m_pImpl)
+ {
+ SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
+ throw lang::DisposedException(THROW_WHERE);
+ }
- if ( !xDest.is() || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ) )
- throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 2 );
+ if (aElementName.isEmpty()
+ || !::comphelper::OStorageHelper::IsValidZipEntryFileName(aElementName, false)
+ || aNewName.isEmpty()
+ || !::comphelper::OStorageHelper::IsValidZipEntryFileName(aNewName, false))
+ throw lang::IllegalArgumentException(THROW_WHERE "Unexpected entry name syntax.",
+ uno::Reference<uno::XInterface>(), 1);
- if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && ( aElementName == "_rels" || aNewName == "_rels" ) )
- throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 0 ); // unacceptable element name
+ if (!xDest.is()
+ || xDest
+ == uno::Reference<uno::XInterface>(static_cast<OWeakObject*>(this),
+ uno::UNO_QUERY))
+ throw lang::IllegalArgumentException(THROW_WHERE, uno::Reference<uno::XInterface>(), 2);
- if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) )
- throw io::IOException( THROW_WHERE ); // TODO: access denied
+ if (m_pData->m_nStorageType == embed::StorageFormats::OFOPXML
+ && (aElementName == "_rels" || aNewName == "_rels"))
+ throw lang::IllegalArgumentException(THROW_WHERE, uno::Reference<uno::XInterface>(),
+ 0); // unacceptable element name
- try
- {
- SotElement_Impl* pElement = m_pImpl->FindElement( aElementName );
- if ( !pElement )
- throw container::NoSuchElementException( THROW_WHERE ); //???
+ if (!(m_pImpl->m_nStorageMode & embed::ElementModes::WRITE))
+ throw io::IOException(THROW_WHERE); // TODO: access denied
- uno::Reference< XNameAccess > xNameAccess( xDest, uno::UNO_QUERY_THROW );
- if ( xNameAccess->hasByName( aNewName ) )
- throw container::ElementExistException( THROW_WHERE );
+ try
+ {
+ SotElement_Impl* pElement = m_pImpl->FindElement(aElementName);
+ if (!pElement)
+ throw container::NoSuchElementException(THROW_WHERE); //???
- m_pImpl->CopyStorageElement( pElement, xDest, aNewName, false );
+ uno::Reference<XNameAccess> xNameAccess(xDest, uno::UNO_QUERY_THROW);
+ if (xNameAccess->hasByName(aNewName))
+ throw container::ElementExistException(THROW_WHERE);
- m_pImpl->RemoveElement( pElement );
+ m_pImpl->CopyStorageElement(pElement, xDest, aNewName, false);
- m_pImpl->m_bIsModified = true;
- m_pImpl->m_bBroadcastModified = true;
- }
- catch( const embed::InvalidStorageException& rInvalidStorageException )
- {
- SAL_INFO("package.xstor", "Rethrow: " << rInvalidStorageException);
- throw;
- }
- catch( const lang::IllegalArgumentException& rIllegalArgumentException )
- {
- SAL_INFO("package.xstor", "Rethrow: " << rIllegalArgumentException);
- throw;
- }
- catch( const container::NoSuchElementException& rNoSuchElementException )
- {
- SAL_INFO("package.xstor", "Rethrow: " << rNoSuchElementException);
- throw;
- }
- catch( const container::ElementExistException& rElementExistException )
- {
- SAL_INFO("package.xstor", "Rethrow: " << rElementExistException);
- throw;
- }
- catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
- {
- SAL_INFO("package.xstor", "Rethrow: " << rStorageWrappedTargetException);
- throw;
- }
- catch( const io::IOException& rIOException )
- {
- SAL_INFO("package.xstor", "Rethrow: " << rIOException);
- throw;
- }
- catch( const uno::RuntimeException& rRuntimeException )
- {
- SAL_INFO("package.xstor", "Rethrow: " << rRuntimeException);
- throw;
- }
- catch( const uno::Exception& )
- {
- uno::Any aCaught( ::cppu::getCaughtException() );
- SAL_INFO("package.xstor", "Rethrow: " << exceptionToString(aCaught));
+ m_pImpl->RemoveElement(pElement);
- throw embed::StorageWrappedTargetException( THROW_WHERE "Can't move element!",
- uno::Reference< io::XInputStream >(),
- aCaught );
- }
+ m_pImpl->m_bIsModified = true;
+ m_pImpl->m_bBroadcastModified = true;
+ }
+ catch (const embed::InvalidStorageException& rInvalidStorageException)
+ {
+ SAL_INFO("package.xstor", "Rethrow: " << rInvalidStorageException);
+ throw;
+ }
+ catch (const lang::IllegalArgumentException& rIllegalArgumentException)
+ {
+ SAL_INFO("package.xstor", "Rethrow: " << rIllegalArgumentException);
+ throw;
+ }
+ catch (const container::NoSuchElementException& rNoSuchElementException)
+ {
+ SAL_INFO("package.xstor", "Rethrow: " << rNoSuchElementException);
+ throw;
+ }
+ catch (const container::ElementExistException& rElementExistException)
+ {
+ SAL_INFO("package.xstor", "Rethrow: " << rElementExistException);
+ throw;
+ }
+ catch (const embed::StorageWrappedTargetException& rStorageWrappedTargetException)
+ {
+ SAL_INFO("package.xstor", "Rethrow: " << rStorageWrappedTargetException);
+ throw;
+ }
+ catch (const io::IOException& rIOException)
+ {
+ SAL_INFO("package.xstor", "Rethrow: " << rIOException);
+ throw;
+ }
+ catch (const uno::RuntimeException& rRuntimeException)
+ {
+ SAL_INFO("package.xstor", "Rethrow: " << rRuntimeException);
+ throw;
+ }
+ catch (const uno::Exception&)
+ {
+ uno::Any aCaught(::cppu::getCaughtException());
+ SAL_INFO("package.xstor", "Rethrow: " << exceptionToString(aCaught));
- aGuard.clear();
+ throw embed::StorageWrappedTargetException(THROW_WHERE "Can't move element!",
+ uno::Reference<io::XInputStream>(), aCaught);
+ }
+ }
BroadcastModifiedIfNecessary();
}
@@ -3106,7 +3119,7 @@ void SAL_CALL OStorage::moveElementTo( const OUString& aElementName,
uno::Reference< io::XStream > SAL_CALL OStorage::openEncryptedStream(
const OUString& aStreamName, sal_Int32 nOpenMode, const uno::Sequence< beans::NamedValue >& aEncryptionData )
{
- ::osl::ResettableMutexGuard aGuard( m_pData->m_xSharedMutex->GetMutex() );
+ osl::ClearableMutexGuard aGuard( m_pData->m_xSharedMutex->GetMutex() );
if ( !m_pImpl )
{
@@ -3589,57 +3602,63 @@ void SAL_CALL OStorage::revert()
BroadcastTransaction( STOR_MESS_PREREVERT );
- ::osl::ResettableMutexGuard aGuard( m_pData->m_xSharedMutex->GetMutex() );
-
- if ( !m_pImpl )
{
- SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
- throw lang::DisposedException( THROW_WHERE );
- }
+ osl::MutexGuard aGuard(m_pData->m_xSharedMutex->GetMutex());
- bool bThrow = std::any_of(m_pImpl->m_aChildrenVector.begin(), m_pImpl->m_aChildrenVector.end(), [](const SotElement_Impl* pElement) {
- return (pElement->m_xStorage
- && (pElement->m_xStorage->m_pAntiImpl || !pElement->m_xStorage->m_aReadOnlyWrapVector.empty()))
- || (pElement->m_xStream
- && (pElement->m_xStream->m_pAntiImpl || !pElement->m_xStream->m_aInputStreamsVector.empty())); });
- if (bThrow)
- throw io::IOException( THROW_WHERE ); // TODO: access denied
+ if (!m_pImpl)
+ {
+ SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
+ throw lang::DisposedException(THROW_WHERE);
+ }
- if ( m_pData->m_bReadOnlyWrap || !m_pImpl->m_bListCreated )
- return; // nothing to do
+ bool bThrow = std::any_of(
+ m_pImpl->m_aChildrenVector.begin(), m_pImpl->m_aChildrenVector.end(),
+ [](const SotElement_Impl* pElement) {
+ return (pElement->m_xStorage
+ && (pElement->m_xStorage->m_pAntiImpl
+ || !pElement->m_xStorage->m_aReadOnlyWrapVector.empty()))
+ || (pElement->m_xStream
+ && (pElement->m_xStream->m_pAntiImpl
+ || !pElement->m_xStream->m_aInputStreamsVector.empty()));
+ });
+ if (bThrow)
+ throw io::IOException(THROW_WHERE); // TODO: access denied
+
+ if (m_pData->m_bReadOnlyWrap || !m_pImpl->m_bListCreated)
+ return; // nothing to do
- try {
- m_pImpl->Revert();
- m_pImpl->m_bIsModified = false;
- m_pImpl->m_bBroadcastModified = true;
- }
- catch( const io::IOException& rIOException )
- {
- SAL_INFO("package.xstor", "Rethrow: " << rIOException);
- throw;
- }
- catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
- {
- SAL_INFO("package.xstor", "Rethrow: " << rStorageWrappedTargetException);
- throw;
- }
- catch( const uno::RuntimeException& rRuntimeException )
- {
- SAL_INFO("package.xstor", "Rethrow: " << rRuntimeException);
- throw;
- }
- catch( const uno::Exception& )
- {
- uno::Any aCaught( ::cppu::getCaughtException() );
- SAL_INFO("package.xstor", "Rethrow: " << exceptionToString(aCaught));
+ try
+ {
+ m_pImpl->Revert();
+ m_pImpl->m_bIsModified = false;
+ m_pImpl->m_bBroadcastModified = true;
+ }
+ catch (const io::IOException& rIOException)
+ {
+ SAL_INFO("package.xstor", "Rethrow: " << rIOException);
+ throw;
+ }
+ catch (const embed::StorageWrappedTargetException& rStorageWrappedTargetException)
+ {
+ SAL_INFO("package.xstor", "Rethrow: " << rStorageWrappedTargetException);
+ throw;
+ }
+ catch (const uno::RuntimeException& rRuntimeException)
+ {
+ SAL_INFO("package.xstor", "Rethrow: " << rRuntimeException);
+ throw;
+ }
+ catch (const uno::Exception&)
+ {
+ uno::Any aCaught(::cppu::getCaughtException());
+ SAL_INFO("package.xstor", "Rethrow: " << exceptionToString(aCaught));
- throw embed::StorageWrappedTargetException( THROW_WHERE "Problems on revert!",
- static_cast< ::cppu::OWeakObject* >( this ),
- aCaught );
+ throw embed::StorageWrappedTargetException(THROW_WHERE "Problems on revert!",
+ static_cast<::cppu::OWeakObject*>(this),
+ aCaught);
+ }
}
- aGuard.clear();
-
setModified( false );
BroadcastTransaction( STOR_MESS_REVERTED );
}
@@ -3693,21 +3712,22 @@ sal_Bool SAL_CALL OStorage::isModified()
void SAL_CALL OStorage::setModified( sal_Bool bModified )
{
- ::osl::ResettableMutexGuard aGuard( m_pData->m_xSharedMutex->GetMutex() );
-
- if ( !m_pImpl )
{
- SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
- throw lang::DisposedException( THROW_WHERE );
- }
+ osl::MutexGuard aGuard(m_pData->m_xSharedMutex->GetMutex());
- if ( m_pData->m_bReadOnlyWrap )
- throw beans::PropertyVetoException( THROW_WHERE ); // TODO: access denied
+ if (!m_pImpl)
+ {
+ SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
+ throw lang::DisposedException(THROW_WHERE);
+ }
- if ( m_pImpl->m_bIsModified != bool(bModified) )
- m_pImpl->m_bIsModified = bModified;
+ if (m_pData->m_bReadOnlyWrap)
+ throw beans::PropertyVetoException(THROW_WHERE); // TODO: access denied
+
+ if (m_pImpl->m_bIsModified != bool(bModified))
+ m_pImpl->m_bIsModified = bModified;
+ }
- aGuard.clear();
if ( bModified )
{
m_pImpl->m_bBroadcastModified = true;