tdf#158975 Add option to not write temp file next to local file

This causes permission issues in some setups.
See bug report for details.

Change-Id: If97030f95185ab96e21cec968b734fba8a811f9d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163003
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
index 3b66f6a..adfa422 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
@@ -5218,6 +5218,15 @@
        </info>
        <value>true</value>
      </prop>
      <prop oor:name="TempFileNextToLocalFile" oor:type="xs:boolean" oor:nillable="false">
        <info>
          <desc>Determines if temp files are placed next to the local file when a file is saved.
          If this is false, the temp file will be placed in the default temp directory.
          Placing the temp file next to the local file will increase performance, but it might lead
          to permission issues such as described in this bug: https://bugs.documentfoundation.org/show_bug.cgi?id=158975</desc>
        </info>
        <value>true</value>
      </prop>
      <prop oor:name="UseDocumentOOoLockFile" oor:type="xs:boolean" oor:nillable="false">
        <info>
          <desc>Allows to specify whether the OOo document file locking
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index fe1f5d0..88f712e 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -4006,6 +4006,8 @@ OUString GetLogicBase(const INetURLObject& rURL, std::unique_ptr<SfxMedium_Impl>
    (void) rURL;
    (void) pImpl;
#else
    if (!officecfg::Office::Common::Misc::TempFileNextToLocalFile::get())
        return aLogicBase;

    if (!pImpl->m_bHasEmbeddedObjects // Embedded objects would mean a special base, ignore that.
        && rURL.GetProtocol() == INetProtocol::File && !pImpl->m_pInStream)