[Libreoffice-commits] core.git: shell/source

Takeshi Abe (via logerrit) logerrit at kemper.freedesktop.org
Sat Apr 13 13:00:26 UTC 2019


 shell/source/backends/desktopbe/desktopbackend.cxx |   21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

New commits:
commit 88d46ba32e4a03d848d82210071c42208e0d6eca
Author:     Takeshi Abe <tabe at fixedpoint.jp>
AuthorDate: Thu Mar 28 19:04:30 2019 +0900
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Sat Apr 13 14:59:48 2019 +0200

    tdf#119890 followup: Forbid HOME to be the default dir
    
    ... of user templates
    
    This is kludgy yet better than making innocent users waiting for
    the template dialog ~forever as pointed out in the comments in
    <https://gerrit.libreoffice.org/#/c/67741/>.
    
    Change-Id: I6dfdc0408effb06cc9175cd976ea6687e52a7136
    Reviewed-on: https://gerrit.libreoffice.org/69883
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/shell/source/backends/desktopbe/desktopbackend.cxx b/shell/source/backends/desktopbe/desktopbackend.cxx
index 4f3c2940869b..14b22b033fb1 100644
--- a/shell/source/backends/desktopbe/desktopbackend.cxx
+++ b/shell/source/backends/desktopbe/desktopbackend.cxx
@@ -127,7 +127,7 @@ void Default::setPropertyValue(OUString const &, css::uno::Any const &)
         static_cast< cppu::OWeakObject * >(this), -1);
 }
 
-OUString xdg_user_dir_lookup (const char *type)
+OUString xdg_user_dir_lookup (const char *type, bool bAllowHomeDir)
 {
     size_t nLenType = strlen(type);
     char *config_home;
@@ -218,16 +218,20 @@ OUString xdg_user_dir_lookup (const char *type)
     if (aUserDirBuf.getLength()>0 && !bError)
     {
         aDocumentsDirURL = aUserDirBuf.makeStringAndClear();
-        osl::Directory aDocumentsDir( aDocumentsDirURL );
-        if( osl::FileBase::E_None == aDocumentsDir.open() )
-            return aDocumentsDirURL;
+        if ( bAllowHomeDir ||
+             (aDocumentsDirURL != aHomeDirURL && aDocumentsDirURL != aHomeDirURL + "/") )
+        {
+            osl::Directory aDocumentsDir( aDocumentsDirURL );
+            if( osl::FileBase::E_None == aDocumentsDir.open() )
+                return aDocumentsDirURL;
+        }
     }
     /* Use fallbacks historical compatibility if nothing else exists */
     return aHomeDirURL + "/" + OUString::createFromAscii(type);
 }
 
-css::uno::Any xdgDirectoryIfExists(char const * type) {
-    auto url = xdg_user_dir_lookup(type);
+css::uno::Any xdgDirectoryIfExists(char const * type, bool bAllowHomeDir) {
+    auto url = xdg_user_dir_lookup(type, bAllowHomeDir);
     return css::uno::Any(
         osl::Directory(url).open() == osl::FileBase::E_None
         ? css::beans::Optional<css::uno::Any>(true, css::uno::Any(url))
@@ -238,12 +242,13 @@ css::uno::Any Default::getPropertyValue(OUString const & PropertyName)
 {
     if (PropertyName == "TemplatePathVariable")
     {
-        return xdgDirectoryIfExists("Templates");
+        // Never pick up the HOME directory as the default location of user's templates
+        return xdgDirectoryIfExists("Templates", false);
     }
 
     if (PropertyName == "WorkPathVariable")
     {
-        return xdgDirectoryIfExists("Documents");
+        return xdgDirectoryIfExists("Documents", true);
     }
 
     if ( PropertyName == "EnableATToolSupport" ||


More information about the Libreoffice-commits mailing list