diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-04-18 11:35:04 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-04-18 21:46:33 +0200 |
commit | 8d4fd3418322f3f6852054c44be2cd74b0db76ee (patch) | |
tree | 683729e0d4beabca34ac017c9d291ab2b21e3f7e /comphelper/source/misc/backupfilehelper.cxx | |
parent | ed0097845a07b6129f4e56cd28b90ce9b9368cf5 (diff) |
loplugin:flatten in comphelper
Change-Id: I1a8db4dbd744b87406d1db5609585495f01f4403
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92478
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'comphelper/source/misc/backupfilehelper.cxx')
-rw-r--r-- | comphelper/source/misc/backupfilehelper.cxx | 294 |
1 files changed, 147 insertions, 147 deletions
diff --git a/comphelper/source/misc/backupfilehelper.cxx b/comphelper/source/misc/backupfilehelper.cxx index e58fe768f15b..e443c384d85b 100644 --- a/comphelper/source/misc/backupfilehelper.cxx +++ b/comphelper/source/misc/backupfilehelper.cxx @@ -436,46 +436,46 @@ namespace private: void visitNodesXMLRead(const uno::Reference< xml::dom::XElement >& rElement) { - if (rElement.is()) + if (!rElement.is()) + return; + + const OUString aTagName(rElement->getTagName()); + + if (aTagName == "extension") { - const OUString aTagName(rElement->getTagName()); + OUString aAttrUrl(rElement->getAttribute("url")); + const OUString aAttrRevoked(rElement->getAttribute("revoked")); - if (aTagName == "extension") + if (!aAttrUrl.isEmpty()) { - OUString aAttrUrl(rElement->getAttribute("url")); - const OUString aAttrRevoked(rElement->getAttribute("revoked")); + const sal_Int32 nIndex(aAttrUrl.lastIndexOf('/')); - if (!aAttrUrl.isEmpty()) + if (nIndex > 0 && aAttrUrl.getLength() > nIndex + 1) { - const sal_Int32 nIndex(aAttrUrl.lastIndexOf('/')); - - if (nIndex > 0 && aAttrUrl.getLength() > nIndex + 1) - { - aAttrUrl = aAttrUrl.copy(nIndex + 1); - } - - const bool bEnabled(aAttrRevoked.isEmpty() || !aAttrRevoked.toBoolean()); - maEntries.emplace_back( - OUStringToOString(aAttrUrl, RTL_TEXTENCODING_ASCII_US), - bEnabled); + aAttrUrl = aAttrUrl.copy(nIndex + 1); } + + const bool bEnabled(aAttrRevoked.isEmpty() || !aAttrRevoked.toBoolean()); + maEntries.emplace_back( + OUStringToOString(aAttrUrl, RTL_TEXTENCODING_ASCII_US), + bEnabled); } - else + } + else + { + uno::Reference< xml::dom::XNodeList > aList = rElement->getChildNodes(); + + if (aList.is()) { - uno::Reference< xml::dom::XNodeList > aList = rElement->getChildNodes(); + const sal_Int32 nLength(aList->getLength()); - if (aList.is()) + for (sal_Int32 a(0); a < nLength; a++) { - const sal_Int32 nLength(aList->getLength()); + const uno::Reference< xml::dom::XElement > aChild(aList->item(a), uno::UNO_QUERY); - for (sal_Int32 a(0); a < nLength; a++) + if (aChild.is()) { - const uno::Reference< xml::dom::XElement > aChild(aList->item(a), uno::UNO_QUERY); - - if (aChild.is()) - { - visitNodesXMLRead(aChild); - } + visitNodesXMLRead(aChild); } } } @@ -605,58 +605,58 @@ namespace const ExtensionInfoEntryVector& rToBeEnabled, const ExtensionInfoEntryVector& rToBeDisabled) { - if (DirectoryHelper::fileExists(rUnoPackagReg)) - { - uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext(); - uno::Reference< xml::dom::XDocumentBuilder > xBuilder = xml::dom::DocumentBuilder::create(xContext); - uno::Reference< xml::dom::XDocument > aDocument = xBuilder->parseURI(rUnoPackagReg); + if (!DirectoryHelper::fileExists(rUnoPackagReg)) + return; - if (aDocument.is()) - { - if (visitNodesXMLChange( - rTagToSearch, - aDocument->getDocumentElement(), - rToBeEnabled, - rToBeDisabled)) - { - // did change - write back - uno::Reference< xml::sax::XSAXSerializable > xSerializer(aDocument, uno::UNO_QUERY); + uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext(); + uno::Reference< xml::dom::XDocumentBuilder > xBuilder = xml::dom::DocumentBuilder::create(xContext); + uno::Reference< xml::dom::XDocument > aDocument = xBuilder->parseURI(rUnoPackagReg); - if (xSerializer.is()) - { - // create a SAXWriter - uno::Reference< xml::sax::XWriter > const xSaxWriter = xml::sax::Writer::create(xContext); - uno::Reference< io::XStream > xTempFile = io::TempFile::create(xContext); - uno::Reference< io::XOutputStream > xOutStrm = xTempFile->getOutputStream(); - - // set output stream and do the serialization - xSaxWriter->setOutputStream(xOutStrm); - xSerializer->serialize(xSaxWriter, uno::Sequence< beans::StringPair >()); - - // get URL from temp file - uno::Reference < beans::XPropertySet > xTempFileProps(xTempFile, uno::UNO_QUERY); - uno::Any aUrl = xTempFileProps->getPropertyValue("Uri"); - OUString aTempURL; - aUrl >>= aTempURL; - - // copy back file - if (!aTempURL.isEmpty() && DirectoryHelper::fileExists(aTempURL)) - { - if (DirectoryHelper::fileExists(rUnoPackagReg)) - { - osl::File::remove(rUnoPackagReg); - } + if (!aDocument.is()) + return; + + if (!visitNodesXMLChange( + rTagToSearch, + aDocument->getDocumentElement(), + rToBeEnabled, + rToBeDisabled)) + return; + + // did change - write back + uno::Reference< xml::sax::XSAXSerializable > xSerializer(aDocument, uno::UNO_QUERY); + + if (!xSerializer.is()) + return; + + // create a SAXWriter + uno::Reference< xml::sax::XWriter > const xSaxWriter = xml::sax::Writer::create(xContext); + uno::Reference< io::XStream > xTempFile = io::TempFile::create(xContext); + uno::Reference< io::XOutputStream > xOutStrm = xTempFile->getOutputStream(); + + // set output stream and do the serialization + xSaxWriter->setOutputStream(xOutStrm); + xSerializer->serialize(xSaxWriter, uno::Sequence< beans::StringPair >()); + + // get URL from temp file + uno::Reference < beans::XPropertySet > xTempFileProps(xTempFile, uno::UNO_QUERY); + uno::Any aUrl = xTempFileProps->getPropertyValue("Uri"); + OUString aTempURL; + aUrl >>= aTempURL; + + // copy back file + if (!(!aTempURL.isEmpty() && DirectoryHelper::fileExists(aTempURL))) + return; + + if (DirectoryHelper::fileExists(rUnoPackagReg)) + { + osl::File::remove(rUnoPackagReg); + } #if OSL_DEBUG_LEVEL > 1 - SAL_WARN_IF(osl::FileBase::E_None != osl::File::move(aTempURL, rUnoPackagReg), "comphelper.backupfilehelper", "could not copy back modified Extension configuration file"); + SAL_WARN_IF(osl::FileBase::E_None != osl::File::move(aTempURL, rUnoPackagReg), "comphelper.backupfilehelper", "could not copy back modified Extension configuration file"); #else - osl::File::move(aTempURL, rUnoPackagReg); + osl::File::move(aTempURL, rUnoPackagReg); #endif - } - } - } - } - } } public: @@ -1602,45 +1602,45 @@ namespace comphelper // ensure existence of needed paths getInitialBaseURL(); - if (!maUserConfigBaseURL.isEmpty()) + if (maUserConfigBaseURL.isEmpty()) + return; + + if (bSafeMode) { - if (bSafeMode) + if (!mbSafeModeDirExists) { - if (!mbSafeModeDirExists) - { - std::set< OUString > aExcludeList; + std::set< OUString > aExcludeList; - // do not move SafeMode directory itself - aExcludeList.insert(getSafeModeName()); + // do not move SafeMode directory itself + aExcludeList.insert(getSafeModeName()); - // init SafeMode by creating the 'SafeMode' directory and moving - // all stuff there. All repairs will happen there. Both Dirs have to exist. - // extend maUserConfigWorkURL as needed - maUserConfigWorkURL = maUserConfigBaseURL + "/" + getSafeModeName(); + // init SafeMode by creating the 'SafeMode' directory and moving + // all stuff there. All repairs will happen there. Both Dirs have to exist. + // extend maUserConfigWorkURL as needed + maUserConfigWorkURL = maUserConfigBaseURL + "/" + getSafeModeName(); - osl::Directory::createPath(maUserConfigWorkURL); - DirectoryHelper::moveDirContent(maUserConfigBaseURL, maUserConfigWorkURL, aExcludeList); + osl::Directory::createPath(maUserConfigWorkURL); + DirectoryHelper::moveDirContent(maUserConfigBaseURL, maUserConfigWorkURL, aExcludeList); - // switch local flag, maUserConfigWorkURL is already reset - mbSafeModeDirExists = true; - } + // switch local flag, maUserConfigWorkURL is already reset + mbSafeModeDirExists = true; } - else + } + else + { + if (mbSafeModeDirExists) { - if (mbSafeModeDirExists) - { - // SafeMode has ended, return to normal mode by moving all content - // from 'SafeMode' directory back to UserDirectory and deleting it. - // Both Dirs have to exist - std::set< OUString > aExcludeList; + // SafeMode has ended, return to normal mode by moving all content + // from 'SafeMode' directory back to UserDirectory and deleting it. + // Both Dirs have to exist + std::set< OUString > aExcludeList; - DirectoryHelper::moveDirContent(maUserConfigWorkURL, maUserConfigBaseURL, aExcludeList); - osl::Directory::remove(maUserConfigWorkURL); + DirectoryHelper::moveDirContent(maUserConfigWorkURL, maUserConfigBaseURL, aExcludeList); + osl::Directory::remove(maUserConfigWorkURL); - // switch local flag and reset maUserConfigWorkURL - mbSafeModeDirExists = false; - maUserConfigWorkURL = maUserConfigBaseURL; - } + // switch local flag and reset maUserConfigWorkURL + mbSafeModeDirExists = false; + maUserConfigWorkURL = maUserConfigBaseURL; } } } @@ -1650,22 +1650,22 @@ namespace comphelper // no push when SafeModeDir exists, it may be Office's exit after SafeMode // where SafeMode flag is already deleted, but SafeModeDir cleanup is not // done yet (is done at next startup) - if (mbActive && !mbSafeModeDirExists) - { - const OUString aPackURL(getPackURL()); + if (!(mbActive && !mbSafeModeDirExists)) + return; - // ensure dir and file vectors - fillDirFileInfo(); + const OUString aPackURL(getPackURL()); - // process all files in question recursively - if (!maDirs.empty() || !maFiles.empty()) - { - tryPush_Files( - maDirs, - maFiles, - maUserConfigWorkURL, - aPackURL); - } + // ensure dir and file vectors + fillDirFileInfo(); + + // process all files in question recursively + if (!maDirs.empty() || !maFiles.empty()) + { + tryPush_Files( + maDirs, + maFiles, + maUserConfigWorkURL, + aPackURL); } } @@ -1709,29 +1709,29 @@ namespace comphelper void BackupFileHelper::tryPop() { - if (mbActive) - { - bool bDidPop(false); - const OUString aPackURL(getPackURL()); + if (!mbActive) + return; - // ensure dir and file vectors - fillDirFileInfo(); + bool bDidPop(false); + const OUString aPackURL(getPackURL()); - // process all files in question recursively - if (!maDirs.empty() || !maFiles.empty()) - { - bDidPop = tryPop_files( - maDirs, - maFiles, - maUserConfigWorkURL, - aPackURL); - } + // ensure dir and file vectors + fillDirFileInfo(); - if (bDidPop) - { - // try removal of evtl. empty directory - osl::Directory::remove(aPackURL); - } + // process all files in question recursively + if (!maDirs.empty() || !maFiles.empty()) + { + bDidPop = tryPop_files( + maDirs, + maFiles, + maUserConfigWorkURL, + aPackURL); + } + + if (bDidPop) + { + // try removal of evtl. empty directory + osl::Directory::remove(aPackURL); } } @@ -1751,18 +1751,18 @@ namespace comphelper void BackupFileHelper::tryPopExtensionInfo() { - if (mbActive && mbExtensions) - { - bool bDidPop(false); - const OUString aPackURL(getPackURL()); + if (!(mbActive && mbExtensions)) + return; - bDidPop = tryPop_extensionInfo(aPackURL); + bool bDidPop(false); + const OUString aPackURL(getPackURL()); - if (bDidPop) - { - // try removal of evtl. empty directory - osl::Directory::remove(aPackURL); - } + bDidPop = tryPop_extensionInfo(aPackURL); + + if (bDidPop) + { + // try removal of evtl. empty directory + osl::Directory::remove(aPackURL); } } |