diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2018-11-03 22:50:52 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2018-11-03 23:00:09 +0100 |
commit | e3720db59b23486cab773e6fadf6bf95b089b5d1 (patch) | |
tree | 3ac9f344cfb334564f0e389b8fc558d17fa64905 /svl | |
parent | b50d16a88727047c2cdf9eeb4b8b2f5916cab859 (diff) |
tdf#120703 PVS: V547 Expression is always false
Let FSStorage::GetContent() return reference.
Change-Id: I6595f48d56f7eb9256600eb6ee1a569077fef92f
Reviewed-on: https://gerrit.libreoffice.org/62823
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'svl')
-rw-r--r-- | svl/source/fsstor/fsstorage.cxx | 92 | ||||
-rw-r--r-- | svl/source/fsstor/fsstorage.hxx | 6 |
2 files changed, 19 insertions, 79 deletions
diff --git a/svl/source/fsstor/fsstorage.cxx b/svl/source/fsstor/fsstorage.cxx index 360083cf386a..32f88f6c8596 100644 --- a/svl/source/fsstor/fsstorage.cxx +++ b/svl/source/fsstor/fsstorage.cxx @@ -132,10 +132,10 @@ bool FSStorage::MakeFolderNoUI( const OUString& rFolder ) return false; } -::ucbhelper::Content* FSStorage::GetContent() +ucbhelper::Content& FSStorage::GetContent() { ::osl::MutexGuard aGuard( m_aMutex ); - return &m_pImpl->m_aContent; + return m_pImpl->m_aContent; } void FSStorage::CopyStreamToSubStream( const OUString& aSourceURL, @@ -166,11 +166,9 @@ void FSStorage::CopyStreamToSubStream( const OUString& aSourceURL, xDestOutput->closeOutput(); } -void FSStorage::CopyContentToStorage_Impl( ::ucbhelper::Content* pContent, const uno::Reference< embed::XStorage >& xDest ) +void FSStorage::CopyContentToStorage_Impl(ucbhelper::Content& rContent, + const uno::Reference<embed::XStorage>& xDest) { - if ( !pContent ) - throw uno::RuntimeException(); - // get list of contents of the Content // create cursor for access to children uno::Sequence< OUString > aProps( 2 ); @@ -180,7 +178,8 @@ void FSStorage::CopyContentToStorage_Impl( ::ucbhelper::Content* pContent, const try { - uno::Reference< sdbc::XResultSet > xResultSet = pContent->createCursor( aProps, ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS ); + uno::Reference<sdbc::XResultSet> xResultSet + = rContent.createCursor(aProps, ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS); uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY ); if ( xResultSet.is() ) { @@ -203,7 +202,7 @@ void FSStorage::CopyContentToStorage_Impl( ::ucbhelper::Content* pContent, const uno::Reference< ucb::XCommandEnvironment > xDummyEnv; ::ucbhelper::Content aSourceContent( aSourceURL, xDummyEnv, comphelper::getProcessComponentContext() ); - CopyContentToStorage_Impl( &aSourceContent, xSubStorage ); + CopyContentToStorage_Impl( aSourceContent, xSubStorage ); } else { @@ -294,9 +293,6 @@ void SAL_CALL FSStorage::copyToStorage( const uno::Reference< embed::XStorage >& if ( !xDest.is() || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject*> ( this ), uno::UNO_QUERY ) ) throw lang::IllegalArgumentException(); // TODO: - if ( !GetContent() ) - throw io::IOException(); // TODO: error handling - try { CopyContentToStorage_Impl( GetContent(), xDest ); @@ -338,9 +334,6 @@ uno::Reference< io::XStream > SAL_CALL FSStorage::openStreamElement( if ( !m_pImpl ) throw lang::DisposedException(); - if ( !GetContent() ) - throw io::IOException(); // TODO: error handling - // TODO/LATER: may need possibility to create folder if it was removed, since the folder can not be locked INetURLObject aFileURL( m_pImpl->m_aURL ); aFileURL.Append( aStreamName ); @@ -445,9 +438,6 @@ uno::Reference< embed::XStorage > SAL_CALL FSStorage::openStorageElement( if ( !m_pImpl ) throw lang::DisposedException(); - if ( !GetContent() ) - throw io::IOException(); // TODO: error handling - if ( ( nStorageMode & embed::ElementModes::WRITE ) && !( m_pImpl->m_nMode & embed::ElementModes::WRITE ) ) throw io::IOException(); // TODO: error handling @@ -531,9 +521,6 @@ uno::Reference< io::XStream > SAL_CALL FSStorage::cloneStreamElement( const OUSt if ( !m_pImpl ) throw lang::DisposedException(); - if ( !GetContent() ) - throw io::IOException(); // TODO: error handling - // TODO/LATER: may need possibility to create folder if it was removed, since the folder can not be locked INetURLObject aFileURL( m_pImpl->m_aURL ); aFileURL.Append( aStreamName ); @@ -624,9 +611,6 @@ sal_Bool SAL_CALL FSStorage::isStreamElement( const OUString& aElementName ) if ( !m_pImpl ) throw lang::DisposedException(); - if ( !GetContent() ) - throw embed::InvalidStorageException(); // TODO: error handling - INetURLObject aURL( m_pImpl->m_aURL ); aURL.Append( aElementName ); @@ -640,9 +624,6 @@ sal_Bool SAL_CALL FSStorage::isStorageElement( const OUString& aElementName ) if ( !m_pImpl ) throw lang::DisposedException(); - if ( !GetContent() ) - throw embed::InvalidStorageException(); // TODO: error handling - INetURLObject aURL( m_pImpl->m_aURL ); aURL.Append( aElementName ); @@ -656,9 +637,6 @@ void SAL_CALL FSStorage::removeElement( const OUString& aElementName ) if ( !m_pImpl ) throw lang::DisposedException(); - if ( !GetContent() ) - throw io::IOException(); // TODO: error handling - INetURLObject aURL( m_pImpl->m_aURL ); aURL.Append( aElementName ); @@ -676,9 +654,6 @@ void SAL_CALL FSStorage::renameElement( const OUString& aElementName, const OUSt if ( !m_pImpl ) throw lang::DisposedException(); - if ( !GetContent() ) - throw io::IOException(); // TODO: error handling - INetURLObject aOldURL( m_pImpl->m_aURL ); aOldURL.Append( aElementName ); @@ -698,10 +673,8 @@ void SAL_CALL FSStorage::renameElement( const OUString& aElementName, const OUSt uno::Reference< ucb::XCommandEnvironment > xDummyEnv; ::ucbhelper::Content aSourceContent( aOldURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), xDummyEnv, comphelper::getProcessComponentContext() ); - GetContent()->transferContent( aSourceContent, - ::ucbhelper::InsertOperation::Move, - aNewName, - ucb::NameClash::ERROR ); + GetContent().transferContent(aSourceContent, ::ucbhelper::InsertOperation::Move, aNewName, + ucb::NameClash::ERROR); } catch( embed::InvalidStorageException& ) { @@ -752,9 +725,6 @@ void SAL_CALL FSStorage::copyElementTo( const OUString& aElementName, if ( !xDest.is() ) throw uno::RuntimeException(); - if ( !GetContent() ) - throw io::IOException(); // TODO: error handling - INetURLObject aOwnURL( m_pImpl->m_aURL ); aOwnURL.Append( aElementName ); @@ -771,7 +741,7 @@ void SAL_CALL FSStorage::copyElementTo( const OUString& aElementName, xDest->openStorageElement( aNewName, embed::ElementModes::READWRITE ), uno::UNO_QUERY_THROW ); - CopyContentToStorage_Impl( &aSourceContent, xDestSubStor ); + CopyContentToStorage_Impl( aSourceContent, xDestSubStor ); } else if ( ::utl::UCBContentHelper::IsDocument( aOwnURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ) ) ) { @@ -845,9 +815,6 @@ uno::Any SAL_CALL FSStorage::getByName( const OUString& aName ) uno::Any aResult; try { - if ( !GetContent() ) - throw io::IOException(); // TODO: error handling - INetURLObject aURL( m_pImpl->m_aURL ); aURL.Append( aName ); @@ -898,13 +865,11 @@ uno::Sequence< OUString > SAL_CALL FSStorage::getElementNames() try { - if ( !GetContent() ) - throw io::IOException(); // TODO: error handling - uno::Sequence<OUString> aProps { "Title" }; sal_Int32 nSize = 0; - uno::Reference< sdbc::XResultSet > xResultSet = GetContent()->createCursor( aProps, ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS ); + uno::Reference<sdbc::XResultSet> xResultSet + = GetContent().createCursor(aProps, ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS); uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY ); if ( xResultSet.is() ) { @@ -951,25 +916,8 @@ sal_Bool SAL_CALL FSStorage::hasByName( const OUString& aName ) if ( !m_pImpl ) throw lang::DisposedException(); - try - { - if ( !GetContent() ) - throw io::IOException(); // TODO: error handling - - if ( aName.isEmpty() ) - throw lang::IllegalArgumentException(); - } - catch( uno::RuntimeException& ) - { - throw; - } - catch ( uno::Exception& ) - { - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetRuntimeException( "Can not open storage!", - static_cast< OWeakObject* >( this ), - aCaught ); - } + if ( aName.isEmpty() ) + throw lang::IllegalArgumentException(); INetURLObject aURL( m_pImpl->m_aURL ); aURL.Append( aName ); @@ -998,12 +946,10 @@ sal_Bool SAL_CALL FSStorage::hasElements() try { - if ( !GetContent() ) - throw io::IOException(); // TODO: error handling - uno::Sequence<OUString> aProps { "TargetURL" }; - uno::Reference< sdbc::XResultSet > xResultSet = GetContent()->createCursor( aProps, ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS ); + uno::Reference<sdbc::XResultSet> xResultSet + = GetContent().createCursor(aProps, ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS); return ( xResultSet.is() && xResultSet->next() ); } catch (const uno::RuntimeException&) @@ -1167,9 +1113,6 @@ uno::Reference< embed::XExtendedStorageStream > SAL_CALL FSStorage::openStreamEl if ( sStreamPath.toChar() == '/' ) throw lang::IllegalArgumentException(); - if ( !GetContent() ) - throw io::IOException(); // TODO: error handling - INetURLObject aBaseURL( m_pImpl->m_aURL ); if ( !aBaseURL.setFinalSlash() ) throw uno::RuntimeException(); @@ -1283,9 +1226,6 @@ void SAL_CALL FSStorage::removeStreamElementByHierarchicalName( const OUString& if ( !m_pImpl ) throw lang::DisposedException(); - if ( !GetContent() ) - throw io::IOException(); // TODO: error handling - // TODO/LATER: may need possibility to create folder if it was removed, since the folder can not be locked INetURLObject aBaseURL( m_pImpl->m_aURL ); if ( !aBaseURL.setFinalSlash() ) diff --git a/svl/source/fsstor/fsstorage.hxx b/svl/source/fsstor/fsstorage.hxx index 18574f2b7205..4db99c0bda48 100644 --- a/svl/source/fsstor/fsstorage.hxx +++ b/svl/source/fsstor/fsstorage.hxx @@ -55,14 +55,14 @@ public: virtual ~FSStorage() override; - ::ucbhelper::Content* GetContent(); + ucbhelper::Content& GetContent(); static void CopyStreamToSubStream( const OUString& aSourceURL, const css::uno::Reference< css::embed::XStorage >& xDest, const OUString& aNewEntryName ); - void CopyContentToStorage_Impl( ::ucbhelper::Content* pContent, - const css::uno::Reference< css::embed::XStorage >& xDest ); + void CopyContentToStorage_Impl(ucbhelper::Content& rContent, + const css::uno::Reference<css::embed::XStorage>& xDest); static bool MakeFolderNoUI( const OUString& rFolder ); |