11894c4
From 30d696d0a1b43b279a92d387557ade33b9212880 Mon Sep 17 00:00:00 2001
11894c4
From: Takeshi Abe <tabe@fixedpoint.jp>
11894c4
Date: Thu, 28 Mar 2019 19:04:30 +0900
11894c4
Subject: [PATCH] tdf#119890 followup: Forbid HOME to be the default dir
11894c4
11894c4
... of user templates
11894c4
11894c4
This is kludgy yet better than making innocent users waiting for
11894c4
the template dialog ~forever as pointed out in the comments in
11894c4
<https://gerrit.libreoffice.org/#/c/67741/>.
11894c4
11894c4
Change-Id: I6dfdc0408effb06cc9175cd976ea6687e52a7136
11894c4
---
11894c4
 .../backends/desktopbe/desktopbackend.cxx     | 21 ++++++++++++-------
11894c4
 1 file changed, 13 insertions(+), 8 deletions(-)
11894c4
11894c4
diff --git a/shell/source/backends/desktopbe/desktopbackend.cxx b/shell/source/backends/desktopbe/desktopbackend.cxx
11894c4
index 5923c6583fb7..4b1d0c44b182 100644
11894c4
--- a/shell/source/backends/desktopbe/desktopbackend.cxx
11894c4
+++ b/shell/source/backends/desktopbe/desktopbackend.cxx
11894c4
@@ -127,7 +127,7 @@ void Default::setPropertyValue(OUString const &, css::uno::Any const &)
11894c4
         static_cast< cppu::OWeakObject * >(this), -1);
11894c4
 }
11894c4
 
11894c4
-OUString xdg_user_dir_lookup (const char *type)
11894c4
+OUString xdg_user_dir_lookup (const char *type, bool bAllowHomeDir)
11894c4
 {
11894c4
     size_t nLenType = strlen(type);
11894c4
     char *config_home;
11894c4
@@ -218,16 +218,20 @@ OUString xdg_user_dir_lookup (const char *type)
11894c4
     if (aUserDirBuf.getLength()>0 && !bError)
11894c4
     {
11894c4
         aDocumentsDirURL = aUserDirBuf.makeStringAndClear();
11894c4
-        osl::Directory aDocumentsDir( aDocumentsDirURL );
11894c4
-        if( osl::FileBase::E_None == aDocumentsDir.open() )
11894c4
-            return aDocumentsDirURL;
11894c4
+        if ( bAllowHomeDir ||
11894c4
+             (aDocumentsDirURL != aHomeDirURL && aDocumentsDirURL != aHomeDirURL + "/") )
11894c4
+        {
11894c4
+            osl::Directory aDocumentsDir( aDocumentsDirURL );
11894c4
+            if( osl::FileBase::E_None == aDocumentsDir.open() )
11894c4
+                return aDocumentsDirURL;
11894c4
+        }
11894c4
     }
11894c4
     /* Use fallbacks historical compatibility if nothing else exists */
11894c4
     return aHomeDirURL + "/" + OUString::createFromAscii(type);
11894c4
 }
11894c4
 
11894c4
-css::uno::Any xdgDirectoryIfExists(char const * type) {
11894c4
-    auto url = xdg_user_dir_lookup(type);
11894c4
+css::uno::Any xdgDirectoryIfExists(char const * type, bool bAllowHomeDir) {
11894c4
+    auto url = xdg_user_dir_lookup(type, bAllowHomeDir);
11894c4
     return css::uno::Any(
11894c4
         osl::Directory(url).open() == osl::FileBase::E_None
11894c4
         ? css::beans::Optional<css::uno::Any>(true, css::uno::Any(url))
11894c4
@@ -238,12 +242,13 @@ css::uno::Any Default::getPropertyValue(OUString const & PropertyName)
11894c4
 {
11894c4
     if (PropertyName == "TemplatePathVariable")
11894c4
     {
11894c4
-        return xdgDirectoryIfExists("Templates");
11894c4
+        // Never pick up the HOME directory as the default location of user's templates
11894c4
+        return xdgDirectoryIfExists("Templates", false);
11894c4
     }
11894c4
 
11894c4
     if (PropertyName == "WorkPathVariable")
11894c4
     {
11894c4
-        return xdgDirectoryIfExists("Documents");
11894c4
+        return xdgDirectoryIfExists("Documents", true);
11894c4
     }
11894c4
 
11894c4
     if ( PropertyName == "EnableATToolSupport" ||
11894c4
-- 
11894c4
2.20.1
11894c4