[Libreoffice-commits] core.git: Branch 'feature/cib_contract138c' - 7 commits - comphelper/Library_comphelper.mk comphelper/source configmgr/README.vars configmgr/source configure.ac desktop/source extensions/source include/comphelper unotools/source

Samuel Mehrbrodt (via logerrit) logerrit at kemper.freedesktop.org
Thu Jan 23 13:06:30 UTC 2020


 comphelper/Library_comphelper.mk                 |    1 
 comphelper/source/misc/DirectoryHelper.cxx       |  206 ++++++++++++++++++
 comphelper/source/misc/backupfilehelper.cxx      |  255 ++---------------------
 configmgr/README.vars                            |    3 
 configmgr/source/writemodfile.cxx                |    4 
 configure.ac                                     |    2 
 desktop/source/deployment/manager/dp_manager.cxx |    3 
 desktop/source/pkgchk/unopkg/unopkg_app.cxx      |   31 +-
 desktop/source/pkgchk/unopkg/unopkg_misc.cxx     |    8 
 desktop/source/pkgchk/unopkg/unopkg_shared.h     |    2 
 extensions/source/logging/consolehandler.cxx     |   39 +++
 include/comphelper/DirectoryHelper.hxx           |   34 +++
 unotools/source/ucbhelper/tempfile.cxx           |    4 
 13 files changed, 343 insertions(+), 249 deletions(-)

New commits:
commit 9929b07ac151f8564d2e6c6c270d3ae9d95b53b3
Author:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
AuthorDate: Thu Jan 23 14:05:33 2020 +0100
Commit:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
CommitDate: Thu Jan 23 14:05:33 2020 +0100

    Release 6.2.9.2
    
    Change-Id: I881936cd6d8192e392420f58070def4834d60ec3

diff --git a/configure.ac b/configure.ac
index a6c7f84e13e9..6d962c3acddf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -9,7 +9,7 @@ dnl in order to create a configure script.
 # several non-alphanumeric characters, those are split off and used only for the
 # ABOUTBOXPRODUCTVERSIONSUFFIX in openoffice.lst. Why that is necessary, no idea.
 
-AC_INIT([LibreOffice],[6.2.9.1],[],[],[http://documentfoundation.org/])
+AC_INIT([LibreOffice],[6.2.9.2],[],[],[http://documentfoundation.org/])
 
 AC_PREREQ([2.59])
 
commit 173b74d3421ffb55127aee9ab77f83ce41727307
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Thu Jan 23 12:56:00 2020 +0300
Commit:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
CommitDate: Thu Jan 23 13:05:19 2020 +0100

    Logger should be initialized with local context
    
    ... otherwise its output will go to connected soffice, and will not
    reach the unopkg console, e.g. trying to execute
    
        unopkg add wrong_extension_name
    
    while an instance of soffice is running.
    
    Change-Id: Ic0b0c48f9b3e8be084e0fdd1838cb0614da6817e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87248
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
    Tested-by: Mike Kaganski <mike.kaganski at collabora.com>
    (cherry picked from commit 5fe5c3a3f485f925a327cdc7b95c8691f6078608)

diff --git a/desktop/source/pkgchk/unopkg/unopkg_app.cxx b/desktop/source/pkgchk/unopkg/unopkg_app.cxx
index e7f7c0c26938..72c5ff315b4b 100644
--- a/desktop/source/pkgchk/unopkg/unopkg_app.cxx
+++ b/desktop/source/pkgchk/unopkg/unopkg_app.cxx
@@ -313,13 +313,13 @@ extern "C" int unopkg_main()
 
         // Initialize logging. This will log errors to the console and
         // also to file if the --log-file parameter was provided.
-        logger.reset(new comphelper::EventLogger(xComponentContext, "unopkg"));
+        logger.reset(new comphelper::EventLogger(xLocalComponentContext, "unopkg"));
         const Reference<XLogger> xLogger(logger->getLogger());
         xLogger->setLevel(LogLevel::WARNING);
-        Reference<XLogFormatter> xLogFormatter(SimpleTextFormatter::create(xComponentContext));
+        Reference<XLogFormatter> xLogFormatter(SimpleTextFormatter::create(xLocalComponentContext));
         Sequence < beans::NamedValue > aSeq { { "Formatter", Any(xLogFormatter) } };
 
-        xConsoleHandler.set(ConsoleHandler::createWithSettings(xComponentContext, aSeq));
+        xConsoleHandler.set(ConsoleHandler::createWithSettings(xLocalComponentContext, aSeq));
         xLogger->addLogHandler(xConsoleHandler);
         xConsoleHandler->setLevel(LogLevel::WARNING);
         xLogger->setLevel(LogLevel::WARNING);
@@ -328,7 +328,7 @@ extern "C" int unopkg_main()
         if (!logFile.isEmpty())
         {
             Sequence < beans::NamedValue > aSeq2 { { "Formatter", Any(xLogFormatter) }, {"FileURL", Any(logFile)} };
-            xFileHandler.set(css::logging::FileHandler::createWithSettings(xComponentContext, aSeq2));
+            xFileHandler.set(css::logging::FileHandler::createWithSettings(xLocalComponentContext, aSeq2));
             xFileHandler->setLevel(LogLevel::WARNING);
             xLogger->addLogHandler(xFileHandler);
         }
commit 91eb178d23eabdd239fa30676a6753248f01cb91
Author:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
AuthorDate: Mon Jan 20 11:12:12 2020 +0100
Commit:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
CommitDate: Thu Jan 23 13:03:32 2020 +0100

    tdf#129917 Use temp user profile when installing shared extensions
    
    Change-Id: I62dd163758e6348a62fc8a0b25150a62f282de90

diff --git a/configmgr/README.vars b/configmgr/README.vars
new file mode 100644
index 000000000000..d4ebae297e1b
--- /dev/null
+++ b/configmgr/README.vars
@@ -0,0 +1,3 @@
+Environment variables in configmgr:
+
+LO_NO_REGISTRYMODIFICATIONS - Don't write registrymodifications.xcu
diff --git a/configmgr/source/writemodfile.cxx b/configmgr/source/writemodfile.cxx
index b3592bb1a8af..e6f76b582985 100644
--- a/configmgr/source/writemodfile.cxx
+++ b/configmgr/source/writemodfile.cxx
@@ -31,6 +31,7 @@
 #include <o3tl/string_view.hxx>
 #include <osl/file.h>
 #include <osl/file.hxx>
+#include <rtl/bootstrap.hxx>
 #include <rtl/string.h>
 #include <rtl/string.hxx>
 #include <rtl/textcvt.h>
@@ -563,6 +564,9 @@ void writeValueContent(TempFile &handle, o3tl::u16string_view value) {
 void writeModFile(
     Components & components, OUString const & url, Data const & data)
 {
+    OUString sTokenOut;
+    if (rtl::Bootstrap::get("LO_NO_REGISTRYMODIFICATIONS", sTokenOut))
+        return;
     sal_Int32 i = url.lastIndexOf('/');
     assert(i != -1);
     OUString dir(url.copy(0, i));
diff --git a/desktop/source/pkgchk/unopkg/unopkg_app.cxx b/desktop/source/pkgchk/unopkg/unopkg_app.cxx
index 045ee94ec7ef..e7f7c0c26938 100644
--- a/desktop/source/pkgchk/unopkg/unopkg_app.cxx
+++ b/desktop/source/pkgchk/unopkg/unopkg_app.cxx
@@ -31,6 +31,7 @@
 #include <osl/process.h>
 #include <osl/conditn.hxx>
 #include <osl/file.hxx>
+#include <unotools/tempfile.hxx>
 #include <cppuhelper/implbase.hxx>
 #include <cppuhelper/exc_hlp.hxx>
 #include <comphelper/anytostring.hxx>
@@ -204,6 +205,7 @@ extern "C" int unopkg_main()
     Reference<XLogHandler> xFileHandler;
     Reference<XLogHandler> xConsoleHandler;
     std::unique_ptr<comphelper::EventLogger> logger;
+    std::unique_ptr<utl::TempFile> pUserProfileTempDir;
 
     OptionInfo const * info_shared = getOptionInfo(
         s_option_infos, "shared" );
@@ -298,8 +300,16 @@ extern "C" int unopkg_main()
             }
         }
 
-        xComponentContext = getUNO(
-        option_verbose, option_shared, subcmd_gui, xLocalComponentContext );
+        // tdf#129917 Use temp user profile when installing shared extensions
+        if (option_shared)
+        {
+            pUserProfileTempDir.reset(new utl::TempFile(nullptr, true));
+            pUserProfileTempDir->EnableKillingFile();
+        }
+
+        xComponentContext = getUNO(option_verbose, subcmd_gui,
+                                   pUserProfileTempDir ? pUserProfileTempDir->GetURL() : "",
+                                   xLocalComponentContext);
 
         // Initialize logging. This will log errors to the console and
         // also to file if the --log-file parameter was provided.
@@ -359,7 +369,6 @@ extern "C" int unopkg_main()
                            APP_NAME, toString(info_shared), toString(info_bundled));
                 return 1;
             }
-
         }
 #endif
 
diff --git a/desktop/source/pkgchk/unopkg/unopkg_misc.cxx b/desktop/source/pkgchk/unopkg/unopkg_misc.cxx
index 7f1cbffb3488..d9cfdd91e9c3 100644
--- a/desktop/source/pkgchk/unopkg/unopkg_misc.cxx
+++ b/desktop/source/pkgchk/unopkg/unopkg_misc.cxx
@@ -416,12 +416,14 @@ static OUString getLockFilePath()
 }
 
 Reference<XComponentContext> getUNO(
-    bool verbose, bool shared, bool bGui,
+    bool verbose, bool bGui, const OUString& sTempDir,
     Reference<XComponentContext> & out_localContext)
 {
     // do not create any user data (for the root user) in --shared mode:
-    if (shared) {
-        rtl::Bootstrap::set("CFG_CacheUrl", OUString());
+    if (!sTempDir.isEmpty()) {
+        rtl::Bootstrap::set("UserInstallation", sTempDir);
+        // Prevent writing registrymodifications.xcu - it can't be cleaned in the temp directory
+        rtl::Bootstrap::set("LO_NO_REGISTRYMODIFICATIONS", "1");
     }
 
     // hold lock during process runtime:
diff --git a/desktop/source/pkgchk/unopkg/unopkg_shared.h b/desktop/source/pkgchk/unopkg/unopkg_shared.h
index 6d23b4c8f39e..68a46227314e 100644
--- a/desktop/source/pkgchk/unopkg/unopkg_shared.h
+++ b/desktop/source/pkgchk/unopkg/unopkg_shared.h
@@ -109,7 +109,7 @@ void printf_packages(
 
 
 css::uno::Reference<css::uno::XComponentContext> getUNO(
-    bool verbose, bool shared, bool bGui,
+    bool verbose, bool bGui, const OUString& sTempDir,
     css::uno::Reference<css::uno::XComponentContext> & out_LocalComponentContext);
 
 }
commit 066d5797255b027da205adfe0decca235f8c2433
Author:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
AuthorDate: Fri Jan 10 07:12:28 2020 +0100
Commit:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
CommitDate: Thu Jan 23 13:02:54 2020 +0100

    unopkg: Correctly display log messages on Windows
    
    Change-Id: I5ec8c55f9afac8d6f7f697c0e5e387e88db4fde7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86517
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
    Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
    (cherry picked from commit 015e9f780bc133788f79868bb7fb0b1d4e81f5f3)

diff --git a/extensions/source/logging/consolehandler.cxx b/extensions/source/logging/consolehandler.cxx
index cf74e46e1332..816e4f8807bc 100644
--- a/extensions/source/logging/consolehandler.cxx
+++ b/extensions/source/logging/consolehandler.cxx
@@ -31,9 +31,15 @@
 #include <cppuhelper/compbase.hxx>
 #include <cppuhelper/basemutex.hxx>
 #include <cppuhelper/supportsservice.hxx>
+#include <osl/thread.hxx>
 
 #include <stdio.h>
 
+#ifdef _WIN32
+#include <prewin.h>
+#include <postwin.h>
+#endif
+
 namespace logging
 {
     using ::com::sun::star::logging::XConsoleHandler;
@@ -211,10 +217,38 @@ namespace logging
     void SAL_CALL ConsoleHandler::flush(  )
     {
         MethodGuard aGuard( *this );
+#ifndef _WIN32
         fflush( stdout );
         fflush( stderr );
+#endif
+    }
+
+    namespace
+    {
+    void lcl_printConsole(const OString& sText)
+    {
+#ifdef _WIN32
+        DWORD nWrittenChars = 0;
+        OUString s = OStringToOUString(sText, RTL_TEXTENCODING_ASCII_US);
+        WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), s.getStr(), s.getLength() * 2,
+                  &nWrittenChars, nullptr);
+#else
+        fprintf(stdout, "%s\n", sText.getStr());
+#endif
     }
 
+    void lcl_printConsoleError(const OString& sText)
+    {
+#ifdef _WIN32
+        DWORD nWrittenChars = 0;
+        OUString s = OStringToOUString(sText, RTL_TEXTENCODING_ASCII_US);
+        WriteFile(GetStdHandle(STD_ERROR_HANDLE), s.getStr(), s.getLength() * 2,
+                  &nWrittenChars, nullptr);
+#else
+        fprintf(stderr, "%s\n", sText.getStr());
+#endif
+    }
+    } // namespace
 
     sal_Bool SAL_CALL ConsoleHandler::publish( const LogRecord& _rRecord )
     {
@@ -225,10 +259,9 @@ namespace logging
             return false;
 
         if ( _rRecord.Level >= m_nThreshold )
-            fprintf( stderr, "%s\n", sEntry.getStr() );
+            lcl_printConsoleError(sEntry);
         else
-            fprintf( stdout, "%s\n", sEntry.getStr() );
-
+            lcl_printConsole(sEntry);
         return true;
     }
 
commit b978abd566ea6f5b06f4d7dcb53de8d510713fcd
Author:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
AuthorDate: Mon Jan 20 15:23:06 2020 +0100
Commit:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
CommitDate: Thu Jan 23 13:01:07 2020 +0100

    Make TempFile destructor remove temp directory recursively
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87080
    Tested-by: Jenkins
    Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
    (cherry picked from commit 4a25fb867f7cc0a0fc21c4079c84fadec6647ad1)
    
    Change-Id: Idcfa93ffe86112477ad81bcbf74b8e5b858423f2

diff --git a/comphelper/Library_comphelper.mk b/comphelper/Library_comphelper.mk
index a5275f971be4..12c06baebc91 100644
--- a/comphelper/Library_comphelper.mk
+++ b/comphelper/Library_comphelper.mk
@@ -101,6 +101,7 @@ $(eval $(call gb_Library_add_exception_objects,comphelper,\
     comphelper/source/misc/componentmodule \
     comphelper/source/misc/configuration \
     comphelper/source/misc/configurationhelper \
+    comphelper/source/misc/DirectoryHelper \
     comphelper/source/misc/dispatchcommand \
     comphelper/source/misc/docpasswordhelper \
     comphelper/source/misc/docpasswordrequest \
diff --git a/comphelper/source/misc/DirectoryHelper.cxx b/comphelper/source/misc/DirectoryHelper.cxx
new file mode 100644
index 000000000000..a659421654b3
--- /dev/null
+++ b/comphelper/source/misc/DirectoryHelper.cxx
@@ -0,0 +1,206 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <comphelper/DirectoryHelper.hxx>
+
+#include <sal/config.h>
+#include <osl/file.hxx>
+
+#include <memory>
+
+namespace comphelper
+{
+typedef std::shared_ptr<osl::File> FileSharedPtr;
+
+OUString DirectoryHelper::splitAtLastToken(const OUString& rSrc, sal_Unicode aToken,
+                                           OUString& rRight)
+{
+    const sal_Int32 nIndex(rSrc.lastIndexOf(aToken));
+    OUString aRetval;
+
+    if (-1 == nIndex)
+    {
+        aRetval = rSrc;
+        rRight.clear();
+    }
+    else if (nIndex > 0)
+    {
+        aRetval = rSrc.copy(0, nIndex);
+
+        if (rSrc.getLength() > nIndex + 1)
+        {
+            rRight = rSrc.copy(nIndex + 1);
+        }
+    }
+
+    return aRetval;
+}
+
+bool DirectoryHelper::fileExists(const OUString& rBaseURL)
+{
+    if (!rBaseURL.isEmpty())
+    {
+        FileSharedPtr aBaseFile(new osl::File(rBaseURL));
+
+        return (osl::File::E_None == aBaseFile->open(osl_File_OpenFlag_Read));
+    }
+
+    return false;
+}
+
+bool DirectoryHelper::dirExists(const OUString& rDirURL)
+{
+    if (!rDirURL.isEmpty())
+    {
+        osl::Directory aDirectory(rDirURL);
+
+        return (osl::FileBase::E_None == aDirectory.open());
+    }
+
+    return false;
+}
+
+void DirectoryHelper::scanDirsAndFiles(const OUString& rDirURL, std::set<OUString>& rDirs,
+                                       std::set<std::pair<OUString, OUString>>& rFiles)
+{
+    if (!rDirURL.isEmpty())
+    {
+        osl::Directory aDirectory(rDirURL);
+
+        if (osl::FileBase::E_None == aDirectory.open())
+        {
+            osl::DirectoryItem aDirectoryItem;
+
+            while (osl::FileBase::E_None == aDirectory.getNextItem(aDirectoryItem))
+            {
+                osl::FileStatus aFileStatus(osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileURL
+                                            | osl_FileStatus_Mask_FileName);
+
+                if (osl::FileBase::E_None == aDirectoryItem.getFileStatus(aFileStatus))
+                {
+                    if (aFileStatus.isDirectory())
+                    {
+                        const OUString aFileName(aFileStatus.getFileName());
+
+                        if (!aFileName.isEmpty())
+                        {
+                            rDirs.insert(aFileName);
+                        }
+                    }
+                    else if (aFileStatus.isRegular())
+                    {
+                        OUString aFileName(aFileStatus.getFileName());
+                        OUString aExtension;
+                        aFileName = splitAtLastToken(aFileName, '.', aExtension);
+
+                        if (!aFileName.isEmpty())
+                        {
+                            rFiles.insert(std::pair<OUString, OUString>(aFileName, aExtension));
+                        }
+                    }
+                }
+            }
+        }
+    }
+}
+
+bool DirectoryHelper::deleteDirRecursively(const OUString& rDirURL)
+{
+    std::set<OUString> aDirs;
+    std::set<std::pair<OUString, OUString>> aFiles;
+    bool bError(false);
+
+    scanDirsAndFiles(rDirURL, aDirs, aFiles);
+
+    for (const auto& dir : aDirs)
+    {
+        const OUString aNewDirURL(rDirURL + "/" + dir);
+
+        bError |= deleteDirRecursively(aNewDirURL);
+    }
+
+    for (const auto& file : aFiles)
+    {
+        OUString aNewFileURL(rDirURL + "/" + file.first);
+
+        if (!file.second.isEmpty())
+        {
+            aNewFileURL += "." + file.second;
+        }
+        bError |= (osl::FileBase::E_None != osl::File::remove(aNewFileURL));
+    }
+
+    bError |= (osl::FileBase::E_None != osl::Directory::remove(rDirURL));
+
+    return bError;
+}
+
+// both exist, move content
+bool DirectoryHelper::moveDirContent(const OUString& rSourceDirURL, const OUString& rTargetDirURL,
+                                     const std::set<OUString>& rExcludeList)
+{
+    std::set<OUString> aDirs;
+    std::set<std::pair<OUString, OUString>> aFiles;
+    bool bError(false);
+
+    scanDirsAndFiles(rSourceDirURL, aDirs, aFiles);
+
+    for (const auto& dir : aDirs)
+    {
+        const bool bExcluded(!rExcludeList.empty() && rExcludeList.find(dir) != rExcludeList.end());
+
+        if (!bExcluded)
+        {
+            const OUString aNewSourceDirURL(rSourceDirURL + "/" + dir);
+
+            if (dirExists(aNewSourceDirURL))
+            {
+                const OUString aNewTargetDirURL(rTargetDirURL + "/" + dir);
+
+                if (dirExists(aNewTargetDirURL))
+                {
+                    deleteDirRecursively(aNewTargetDirURL);
+                }
+
+                bError |= (osl::FileBase::E_None
+                           != osl::File::move(aNewSourceDirURL, aNewTargetDirURL));
+            }
+        }
+    }
+
+    for (const auto& file : aFiles)
+    {
+        OUString aSourceFileURL(rSourceDirURL + "/" + file.first);
+
+        if (!file.second.isEmpty())
+        {
+            aSourceFileURL += "." + file.second;
+        }
+
+        if (fileExists(aSourceFileURL))
+        {
+            OUString aTargetFileURL(rTargetDirURL + "/" + file.first);
+
+            if (!file.second.isEmpty())
+            {
+                aTargetFileURL += "." + file.second;
+            }
+
+            if (fileExists(aTargetFileURL))
+            {
+                osl::File::remove(aTargetFileURL);
+            }
+
+            bError |= (osl::FileBase::E_None != osl::File::move(aSourceFileURL, aTargetFileURL));
+        }
+    }
+
+    return bError;
+}
+}
\ No newline at end of file
diff --git a/comphelper/source/misc/backupfilehelper.cxx b/comphelper/source/misc/backupfilehelper.cxx
index 315fccb1c501..fc88cedc3623 100644
--- a/comphelper/source/misc/backupfilehelper.cxx
+++ b/comphelper/source/misc/backupfilehelper.cxx
@@ -13,6 +13,7 @@
 #include <sal/log.hxx>
 #include <osl/file.hxx>
 #include <comphelper/backupfilehelper.hxx>
+#include <comphelper/DirectoryHelper.hxx>
 #include <rtl/crc.h>
 #include <algorithm>
 #include <deque>
@@ -43,6 +44,7 @@
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <cppuhelper/exc_hlp.hxx>
 
+using namespace comphelper;
 using namespace css;
 using namespace css::xml::dom;
 
@@ -52,29 +54,6 @@ namespace
 {
     typedef std::shared_ptr< osl::File > FileSharedPtr;
 
-    OUString splitAtLastToken(const OUString& rSrc, sal_Unicode aToken, OUString& rRight)
-    {
-        const sal_Int32 nIndex(rSrc.lastIndexOf(aToken));
-        OUString aRetval;
-
-        if (-1 == nIndex)
-        {
-            aRetval = rSrc;
-            rRight.clear();
-        }
-        else if (nIndex > 0)
-        {
-            aRetval = rSrc.copy(0, nIndex);
-
-            if (rSrc.getLength() > nIndex + 1)
-            {
-                rRight = rSrc.copy(nIndex + 1);
-            }
-        }
-
-        return aRetval;
-    }
-
     sal_uInt32 createCrc32(FileSharedPtr const & rCandidate, sal_uInt32 nOffset)
     {
         sal_uInt32 nCrc32(0);
@@ -215,184 +194,6 @@ namespace
 
         return aRetval;
     }
-
-    bool fileExists(const OUString& rBaseURL)
-    {
-        if (!rBaseURL.isEmpty())
-        {
-            FileSharedPtr aBaseFile(new osl::File(rBaseURL));
-
-            return (osl::File::E_None == aBaseFile->open(osl_File_OpenFlag_Read));
-        }
-
-        return false;
-    }
-
-    bool dirExists(const OUString& rDirURL)
-    {
-        if (!rDirURL.isEmpty())
-        {
-            osl::Directory aDirectory(rDirURL);
-
-            return (osl::FileBase::E_None == aDirectory.open());
-        }
-
-        return false;
-    }
-
-    void scanDirsAndFiles(
-        const OUString& rDirURL,
-        std::set< OUString >& rDirs,
-        std::set< std::pair< OUString, OUString > >& rFiles)
-    {
-        if (!rDirURL.isEmpty())
-        {
-            osl::Directory aDirectory(rDirURL);
-
-            if (osl::FileBase::E_None == aDirectory.open())
-            {
-                osl::DirectoryItem aDirectoryItem;
-
-                while (osl::FileBase::E_None == aDirectory.getNextItem(aDirectoryItem))
-                {
-                    osl::FileStatus aFileStatus(osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileURL | osl_FileStatus_Mask_FileName);
-
-                    if (osl::FileBase::E_None == aDirectoryItem.getFileStatus(aFileStatus))
-                    {
-                        if (aFileStatus.isDirectory())
-                        {
-                            const OUString aFileName(aFileStatus.getFileName());
-
-                            if (!aFileName.isEmpty())
-                            {
-                                rDirs.insert(aFileName);
-                            }
-                        }
-                        else if (aFileStatus.isRegular())
-                        {
-                            OUString aFileName(aFileStatus.getFileName());
-                            OUString aExtension;
-                            aFileName = splitAtLastToken(aFileName, '.', aExtension);
-
-                            if (!aFileName.isEmpty())
-                            {
-                                rFiles.insert(std::pair< OUString, OUString >(aFileName, aExtension));
-                            }
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-    bool deleteDirRecursively(const OUString& rDirURL)
-    {
-        std::set< OUString > aDirs;
-        std::set< std::pair< OUString, OUString > > aFiles;
-        bool bError(false);
-
-        scanDirsAndFiles(
-            rDirURL,
-            aDirs,
-            aFiles);
-
-        for (const auto& dir : aDirs)
-        {
-            const OUString aNewDirURL(rDirURL + "/" + dir);
-
-            bError |= deleteDirRecursively(aNewDirURL);
-        }
-
-        for (const auto& file : aFiles)
-        {
-            OUString aNewFileURL(rDirURL + "/" + file.first);
-
-            if (!file.second.isEmpty())
-            {
-                aNewFileURL += ".";
-                aNewFileURL += file.second;
-            }
-
-            bError |= (osl::FileBase::E_None != osl::File::remove(aNewFileURL));
-        }
-
-        bError |= (osl::FileBase::E_None != osl::Directory::remove(rDirURL));
-
-        return bError;
-    }
-
-    // both exist, move content
-    bool moveDirContent(
-        const OUString& rSourceDirURL,
-        const OUString& rTargetDirURL,
-        const std::set< OUString >& rExcludeList)
-    {
-        std::set< OUString > aDirs;
-        std::set< std::pair< OUString, OUString > > aFiles;
-        bool bError(false);
-
-        scanDirsAndFiles(
-            rSourceDirURL,
-            aDirs,
-            aFiles);
-
-        for (const auto& dir : aDirs)
-        {
-            const bool bExcluded(
-                !rExcludeList.empty() &&
-                rExcludeList.find(dir) != rExcludeList.end());
-
-            if (!bExcluded)
-            {
-                const OUString aNewSourceDirURL(rSourceDirURL + "/" + dir);
-
-                if (dirExists(aNewSourceDirURL))
-                {
-                    const OUString aNewTargetDirURL(rTargetDirURL + "/" + dir);
-
-                    if (dirExists(aNewTargetDirURL))
-                    {
-                        deleteDirRecursively(aNewTargetDirURL);
-                    }
-
-                    bError |= (osl::FileBase::E_None != osl::File::move(
-                        aNewSourceDirURL,
-                        aNewTargetDirURL));
-                }
-            }
-        }
-
-        for (const auto& file : aFiles)
-        {
-            OUString aSourceFileURL(rSourceDirURL + "/" + file.first);
-
-            if (!file.second.isEmpty())
-            {
-                aSourceFileURL += ".";
-                aSourceFileURL += file.second;
-            }
-
-            if (fileExists(aSourceFileURL))
-            {
-                OUString aTargetFileURL(rTargetDirURL + "/" + file.first);
-
-                if (!file.second.isEmpty())
-                {
-                    aTargetFileURL += ".";
-                    aTargetFileURL += file.second;
-                }
-
-                if (fileExists(aTargetFileURL))
-                {
-                    osl::File::remove(aTargetFileURL);
-                }
-
-                bError |= (osl::FileBase::E_None != osl::File::move(aSourceFileURL, aTargetFileURL));
-            }
-        }
-
-        return bError;
-    }
 }
 
 namespace
@@ -697,7 +498,7 @@ namespace
 
         void createExtensionRegistryEntriesFromXML(const OUString& aPath)
         {
-            if (fileExists(aPath))
+            if (DirectoryHelper::fileExists(aPath))
             {
                 uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
                 uno::Reference< xml::dom::XDocumentBuilder > xBuilder(xml::dom::DocumentBuilder::create(xContext));
@@ -798,7 +599,7 @@ namespace
             const ExtensionInfoEntryVector& rToBeEnabled,
             const ExtensionInfoEntryVector& rToBeDisabled)
         {
-            if (fileExists(rUnoPackagReg))
+            if (DirectoryHelper::fileExists(rUnoPackagReg))
             {
                 uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
                 uno::Reference< xml::dom::XDocumentBuilder > xBuilder = xml::dom::DocumentBuilder::create(xContext);
@@ -833,9 +634,9 @@ namespace
                             aUrl >>= aTempURL;
 
                             // copy back file
-                            if (!aTempURL.isEmpty() && fileExists(aTempURL))
+                            if (!aTempURL.isEmpty() && DirectoryHelper::fileExists(aTempURL))
                             {
-                                if (fileExists(rUnoPackagReg))
+                                if (DirectoryHelper::fileExists(rUnoPackagReg))
                                 {
                                     osl::File::remove(rUnoPackagReg);
                                 }
@@ -1697,13 +1498,15 @@ namespace comphelper
             if (!maInitialBaseURL.isEmpty())
             {
                 // split URL at extension and at last path separator
-                maUserConfigBaseURL = splitAtLastToken(splitAtLastToken(maInitialBaseURL, '.', maExt), '/', maRegModName);
+                maUserConfigBaseURL = DirectoryHelper::splitAtLastToken(
+                    DirectoryHelper::splitAtLastToken(maInitialBaseURL, '.', maExt), '/',
+                    maRegModName);
             }
 
             if (!maUserConfigBaseURL.isEmpty())
             {
                 // check if SafeModeDir exists
-                mbSafeModeDirExists = dirExists(maUserConfigBaseURL + "/" + getSafeModeName());
+                mbSafeModeDirExists = DirectoryHelper::dirExists(maUserConfigBaseURL + "/" + getSafeModeName());
             }
 
             maUserConfigWorkURL = maUserConfigBaseURL;
@@ -1811,7 +1614,7 @@ namespace comphelper
                     maUserConfigWorkURL = maUserConfigBaseURL + "/" + getSafeModeName();
 
                     osl::Directory::createPath(maUserConfigWorkURL);
-                    moveDirContent(maUserConfigBaseURL, maUserConfigWorkURL, aExcludeList);
+                    DirectoryHelper::moveDirContent(maUserConfigBaseURL, maUserConfigWorkURL, aExcludeList);
 
                     // switch local flag, maUserConfigWorkURL is already reset
                     mbSafeModeDirExists = true;
@@ -1826,7 +1629,7 @@ namespace comphelper
                     // Both Dirs have to exist
                     std::set< OUString > aExcludeList;
 
-                    moveDirContent(maUserConfigWorkURL, maUserConfigBaseURL, aExcludeList);
+                    DirectoryHelper::moveDirContent(maUserConfigWorkURL, maUserConfigBaseURL, aExcludeList);
                     osl::Directory::remove(maUserConfigWorkURL);
 
                     // switch local flag and reset maUserConfigWorkURL
@@ -2007,7 +1810,7 @@ namespace comphelper
     void BackupFileHelper::tryDeinstallUserExtensions()
     {
         // delete User Extension installs
-        deleteDirRecursively(maUserConfigWorkURL + "/uno_packages");
+        DirectoryHelper::deleteDirRecursively(maUserConfigWorkURL + "/uno_packages");
     }
 
     bool BackupFileHelper::isTryResetSharedExtensionsPossible()
@@ -2023,7 +1826,7 @@ namespace comphelper
     void BackupFileHelper::tryResetSharedExtensions()
     {
         // reset shared extension info
-        deleteDirRecursively(maUserConfigWorkURL + "/extensions/shared");
+        DirectoryHelper::deleteDirRecursively(maUserConfigWorkURL + "/extensions/shared");
     }
 
     bool BackupFileHelper::isTryResetBundledExtensionsPossible()
@@ -2039,7 +1842,7 @@ namespace comphelper
     void BackupFileHelper::tryResetBundledExtensions()
     {
         // reset shared extension info
-        deleteDirRecursively(maUserConfigWorkURL + "/extensions/bundled");
+        DirectoryHelper::deleteDirRecursively(maUserConfigWorkURL + "/extensions/bundled");
     }
 
     const std::vector< OUString >& BackupFileHelper::getCustomizationDirNames()
@@ -2096,7 +1899,7 @@ namespace comphelper
     void BackupFileHelper::tryDisableHWAcceleration()
     {
         const OUString aRegistryModifications(maUserConfigWorkURL + "/registrymodifications.xcu");
-        if (!fileExists(aRegistryModifications))
+        if (!DirectoryHelper::fileExists(aRegistryModifications))
             return;
 
         uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
@@ -2133,10 +1936,10 @@ namespace comphelper
         aUrl >>= aTempURL;
 
         // copy back file
-        if (aTempURL.isEmpty() || !fileExists(aTempURL))
+        if (aTempURL.isEmpty() || !DirectoryHelper::fileExists(aTempURL))
             return;
 
-        if (fileExists(aRegistryModifications))
+        if (DirectoryHelper::fileExists(aRegistryModifications))
         {
             osl::File::remove(aRegistryModifications);
         }
@@ -2152,7 +1955,7 @@ namespace comphelper
 
         for (const auto& a : rDirs)
         {
-            if (dirExists(maUserConfigWorkURL + "/" + a))
+            if (DirectoryHelper::dirExists(maUserConfigWorkURL + "/" + a))
             {
                 return true;
             }
@@ -2162,7 +1965,7 @@ namespace comphelper
 
         for (const auto& b : rFiles)
         {
-            if (fileExists(maUserConfigWorkURL + "/" + b))
+            if (DirectoryHelper::fileExists(maUserConfigWorkURL + "/" + b))
             {
                 return true;
             }
@@ -2178,7 +1981,7 @@ namespace comphelper
 
         for (const auto& a : rDirs)
         {
-            deleteDirRecursively(maUserConfigWorkURL + "/" + a);
+            DirectoryHelper::deleteDirRecursively(maUserConfigWorkURL + "/" + a);
         }
 
         const std::vector< OUString >& rFiles = getCustomizationFileNames();
@@ -2192,7 +1995,7 @@ namespace comphelper
     void BackupFileHelper::tryResetUserProfile()
     {
         // completely delete the current UserProfile
-        deleteDirRecursively(maUserConfigWorkURL);
+        DirectoryHelper::deleteDirRecursively(maUserConfigWorkURL);
     }
 
     const OUString& BackupFileHelper::getUserProfileURL()
@@ -2242,7 +2045,7 @@ namespace comphelper
             std::set< OUString > aNewDirs;
             std::set< std::pair< OUString, OUString > > aNewFiles;
 
-            scanDirsAndFiles(
+            DirectoryHelper::scanDirsAndFiles(
                 aNewSourceURL,
                 aNewDirs,
                 aNewFiles);
@@ -2275,7 +2078,7 @@ namespace comphelper
     {
         const OUString aFileURL(createFileURL(rSourceURL, rName, rExt));
 
-        if (fileExists(aFileURL))
+        if (DirectoryHelper::fileExists(aFileURL))
         {
             const OUString aPackURL(createPackURL(rTargetURL, rName));
             PackedFile aPackedFile(aPackURL);
@@ -2323,7 +2126,7 @@ namespace comphelper
             std::set< OUString > aNewDirs;
             std::set< std::pair< OUString, OUString > > aNewFiles;
 
-            scanDirsAndFiles(
+            DirectoryHelper::scanDirsAndFiles(
                 aNewSourceURL,
                 aNewDirs,
                 aNewFiles);
@@ -2350,7 +2153,7 @@ namespace comphelper
     {
         const OUString aFileURL(createFileURL(rSourceURL, rName, rExt));
 
-        if (fileExists(aFileURL))
+        if (DirectoryHelper::fileExists(aFileURL))
         {
             const OUString aPackURL(createPackURL(rTargetURL, rName));
             PackedFile aPackedFile(aPackURL);
@@ -2390,7 +2193,7 @@ namespace comphelper
             std::set< OUString > aNewDirs;
             std::set< std::pair< OUString, OUString > > aNewFiles;
 
-            scanDirsAndFiles(
+            DirectoryHelper::scanDirsAndFiles(
                 aNewSourceURL,
                 aNewDirs,
                 aNewFiles);
@@ -2423,7 +2226,7 @@ namespace comphelper
     {
         const OUString aFileURL(createFileURL(rSourceURL, rName, rExt));
 
-        if (fileExists(aFileURL))
+        if (DirectoryHelper::fileExists(aFileURL))
         {
             // try Pop for base file
             const OUString aPackURL(createPackURL(rTargetURL, rName));
@@ -2687,7 +2490,7 @@ namespace comphelper
             // whole directory. To do so, scan directory and exclude some dirs
             // from which we know they do not need to be secured explicitly. This
             // should already include registrymodifications, too.
-            scanDirsAndFiles(
+            DirectoryHelper::scanDirsAndFiles(
                 maUserConfigWorkURL,
                 maDirs,
                 maFiles);
diff --git a/include/comphelper/DirectoryHelper.hxx b/include/comphelper/DirectoryHelper.hxx
new file mode 100644
index 000000000000..61b0287e9f77
--- /dev/null
+++ b/include/comphelper/DirectoryHelper.hxx
@@ -0,0 +1,34 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include <sal/config.h>
+
+#include <comphelper/comphelperdllapi.h>
+#include <rtl/ustring.hxx>
+#include <set>
+
+namespace comphelper
+{
+class COMPHELPER_DLLPUBLIC DirectoryHelper
+{
+public:
+    static OUString splitAtLastToken(const OUString& rSrc, sal_Unicode aToken, OUString& rRight);
+    static bool fileExists(const OUString& rBaseURL);
+    static bool dirExists(const OUString& rDirURL);
+    static void scanDirsAndFiles(const OUString& rDirURL, std::set<OUString>& rDirs,
+                                 std::set<std::pair<OUString, OUString>>& rFiles);
+    static bool deleteDirRecursively(const OUString& rDirURL);
+    static bool moveDirContent(const OUString& rSourceDirURL, const OUString& rTargetDirURL,
+                               const std::set<OUString>& rExcludeList);
+};
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/unotools/source/ucbhelper/tempfile.cxx b/unotools/source/ucbhelper/tempfile.cxx
index a659428f8623..ff1f8bd8eabe 100644
--- a/unotools/source/ucbhelper/tempfile.cxx
+++ b/unotools/source/ucbhelper/tempfile.cxx
@@ -32,6 +32,7 @@
 #include <tools/time.hxx>
 #include <tools/debug.hxx>
 #include <stdio.h>
+#include <comphelper/DirectoryHelper.hxx>
 
 #ifdef UNX
 #include <sys/stat.h>
@@ -389,8 +390,7 @@ TempFile::~TempFile()
     {
         if ( bIsDirectory )
         {
-            // at the moment no recursiv algorithm present
-            Directory::remove( aName );
+            comphelper::DirectoryHelper::deleteDirRecursively(aName);
         }
         else
         {
commit bd9f052b973eae66db2d6dff196dcfcaba038b62
Author:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
AuthorDate: Fri Jan 10 08:29:08 2020 +0100
Commit:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
CommitDate: Thu Jan 23 12:58:57 2020 +0100

    unopkg: Improve error message display
    
    Change-Id: Ic842a3be82094557efde6cc22b11b6567c2ad85b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86519
    Tested-by: Jenkins
    Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
    Tested-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
    (cherry picked from commit 95f947439638b47a2d1d1fa33b8f70e32293fce9)

diff --git a/desktop/source/pkgchk/unopkg/unopkg_app.cxx b/desktop/source/pkgchk/unopkg/unopkg_app.cxx
index 725067c20925..045ee94ec7ef 100644
--- a/desktop/source/pkgchk/unopkg/unopkg_app.cxx
+++ b/desktop/source/pkgchk/unopkg/unopkg_app.cxx
@@ -188,7 +188,7 @@ Reference<deployment::XPackage> findPackage(
 extern "C" int unopkg_main()
 {
     tools::extendApplicationEnvironment();
-    bool bNoOtherErrorMsg = false;
+    bool bShowFailedMsg = true;
     OUString subCommand;
     bool option_shared = false;
     bool option_force = false;
@@ -595,11 +595,11 @@ extern "C" int unopkg_main()
     catch (const ucb::CommandFailedException &e)
     {
         logger->log(LogLevel::SEVERE, "Exception occurred: $1$", e.Message);
-        bNoOtherErrorMsg = true;
     }
     catch (const ucb::CommandAbortedException &)
     {
         logger->log(LogLevel::SEVERE, "$1$ aborted.", APP_NAME);
+        bShowFailedMsg = false;
     }
     catch (const deployment::DeploymentException & exc)
     {
@@ -610,7 +610,7 @@ extern "C" int unopkg_main()
     {
         // No logger since it requires UNO which we don't have here
         dp_misc::writeConsoleError(e.Message + "\n");
-        bNoOtherErrorMsg = true;
+        bShowFailedMsg = false;
     }
     catch (const css::uno::Exception & e ) {
         Any exc( ::cppu::getCaughtException() );
@@ -618,7 +618,7 @@ extern "C" int unopkg_main()
         logger->log(LogLevel::SEVERE, "Exception occurred: $1$", e.Message);
         logger->log(LogLevel::INFO, "    Cause: $1$", comphelper::anyToString(exc));
     }
-    if (!bNoOtherErrorMsg)
+    if (bShowFailedMsg)
         logger->log(LogLevel::SEVERE, "$1$ failed.", APP_NAME);
     dp_misc::disposeBridges(xLocalComponentContext);
     return 1;
commit e662cb5e8d04292a2ea461f44bd67aaf33e9ac79
Author:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
AuthorDate: Thu Jan 9 16:57:16 2020 +0100
Commit:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
CommitDate: Thu Jan 23 12:58:37 2020 +0100

    unopkg: Remove too verbose logging
    
    This adds several lines of 'Extension x not found' when installing
    an extension with 'unopkg add'.
    Since it's expected that the extension is not yet there when installing it,
    remove this logging.
    
    Change-Id: Ifc2ea5fa04253a96fee60016a65505e0d1f2722c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86516
    Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
    Tested-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
    (cherry picked from commit 90cab308f52468edbf87a7f06a1ef99f146f03a5)

diff --git a/desktop/source/deployment/manager/dp_manager.cxx b/desktop/source/deployment/manager/dp_manager.cxx
index 25ca6cdcc2d1..ee8ab94bfb9f 100644
--- a/desktop/source/deployment/manager/dp_manager.cxx
+++ b/desktop/source/deployment/manager/dp_manager.cxx
@@ -1065,8 +1065,7 @@ Reference<deployment::XPackage> PackageManagerImpl::getDeployedPackage(
         const ::osl::MutexGuard guard( getMutex() );
         return getDeployedPackage_( id, fileName, xCmdEnv );
     }
-    catch (const lang::IllegalArgumentException & exc) {
-        logIntern( Any(exc) );
+    catch (const lang::IllegalArgumentException &) {
         throw;
     }
     catch (const RuntimeException &) {


More information about the Libreoffice-commits mailing list