summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/tools/fileutil.hxx27
-rw-r--r--sfx2/source/doc/docfile.cxx9
-rw-r--r--tools/Library_tl.mk1
-rw-r--r--tools/source/fsys/fileutil.cxx78
4 files changed, 114 insertions, 1 deletions
diff --git a/include/tools/fileutil.hxx b/include/tools/fileutil.hxx
new file mode 100644
index 000000000000..06e7bf820992
--- /dev/null
+++ b/include/tools/fileutil.hxx
@@ -0,0 +1,27 @@
+/* -*- 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/.
+ */
+
+#ifndef INCLUDED_TOOLS_FILEUTIL_HXX
+#define INCLUDED_TOOLS_FILEUTIL_HXX
+
+#include <tools/toolsdllapi.h>
+
+class INetURLObject;
+
+namespace tools
+{
+// Tests if the path is a UNC or local (drive-based) path that redirects to
+// a WebDAV resource (e.g., using redirectors on Windows).
+// Currently only implemented for Windows; on other platforms, returns false.
+TOOLS_DLLPUBLIC bool IsMappedWebDAVPath(const INetURLObject& aURL);
+}
+
+#endif // INCLUDED_TOOLS_FILEUTIL_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index 757336c6ac1c..6b5429d8f989 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -66,6 +66,7 @@
#include <com/sun/star/security/DocumentSignatureInformation.hpp>
#include <com/sun/star/security/DocumentDigitalSignatures.hpp>
#include <tools/urlobj.hxx>
+#include <tools/fileutil.hxx>
#include <unotools/configmgr.hxx>
#include <unotools/tempfile.hxx>
#include <comphelper/fileurl.hxx>
@@ -1211,7 +1212,13 @@ void SfxMedium::LockOrigFileOnDemand( bool bLoading, bool bNoUI )
}
catch (const uno::Exception&)
{
- if (bLoading && !bNoUI)
+ if (tools::IsMappedWebDAVPath(GetURLObject()))
+ {
+ // This is a path that redirects to a WebDAV resource;
+ // so failure creating lockfile is not an error here.
+ bResult = true;
+ }
+ else if (bLoading && !bNoUI)
{
bIoErr = true;
ShowLockFileProblemDialog(MessageDlg::LockFileIgnore);
diff --git a/tools/Library_tl.mk b/tools/Library_tl.mk
index ec19ac5100c4..252692c86863 100644
--- a/tools/Library_tl.mk
+++ b/tools/Library_tl.mk
@@ -48,6 +48,7 @@ $(eval $(call gb_Library_add_exception_objects,tl,\
tools/source/datetime/tdate \
tools/source/datetime/ttime \
tools/source/debug/debug \
+ tools/source/fsys/fileutil \
tools/source/fsys/urlobj \
tools/source/fsys/wldcrd \
tools/source/generic/b3dtrans \
diff --git a/tools/source/fsys/fileutil.cxx b/tools/source/fsys/fileutil.cxx
new file mode 100644
index 000000000000..a24f82316813
--- /dev/null
+++ b/tools/source/fsys/fileutil.cxx
@@ -0,0 +1,78 @@
+/* -*- 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 <tools/fileutil.hxx>
+#include <tools/urlobj.hxx>
+#if defined _WIN32
+#include <osl/file.hxx>
+#include <string.h>
+#include <o3tl/char16_t2wchar_t.hxx>
+#include <o3tl/make_unique.hxx>
+#define WIN32_LEAN_AND_MEAN
+#include <Windows.h>
+#endif
+
+namespace tools
+{
+bool IsMappedWebDAVPath(const INetURLObject& aURL)
+{
+#if defined _WIN32
+ if (aURL.GetProtocol() == INetProtocol::File)
+ {
+ OUString sURL = aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE);
+ OUString aSystemPath;
+ if (osl::FileBase::getSystemPathFromFileURL(sURL, aSystemPath) == osl::FileBase::E_None)
+ {
+ DWORD nSize = MAX_PATH;
+ auto bufUNC(o3tl::make_unique<char[]>(nSize));
+ DWORD nResult = WNetGetUniversalNameW(o3tl::toW(aSystemPath.getStr()),
+ UNIVERSAL_NAME_INFO_LEVEL, bufUNC.get(), &nSize);
+ if (nResult == ERROR_MORE_DATA)
+ {
+ bufUNC = o3tl::make_unique<char[]>(nSize);
+ nResult = WNetGetUniversalNameW(o3tl::toW(aSystemPath.getStr()),
+ UNIVERSAL_NAME_INFO_LEVEL, bufUNC.get(), &nSize);
+ }
+ if (nResult == NO_ERROR || nResult == ERROR_BAD_DEVICE)
+ {
+ NETRESOURCEW aReq{};
+ if (nResult == ERROR_BAD_DEVICE) // The path could already be an UNC
+ aReq.lpRemoteName = const_cast<LPWSTR>(o3tl::toW(aSystemPath.getStr()));
+ else
+ {
+ auto pInfo = reinterpret_cast<LPUNIVERSAL_NAME_INFOW>(bufUNC.get());
+ aReq.lpRemoteName = pInfo->lpUniversalName;
+ }
+ nSize = 1024;
+ auto bufInfo(o3tl::make_unique<char[]>(nSize));
+ LPWSTR pSystem = nullptr;
+ nResult = WNetGetResourceInformationW(&aReq, bufInfo.get(), &nSize, &pSystem);
+ if (nResult == ERROR_MORE_DATA)
+ {
+ bufInfo = o3tl::make_unique<char[]>(nSize);
+ nResult = WNetGetResourceInformationW(&aReq, bufInfo.get(), &nSize, &pSystem);
+ }
+ if (nResult == NO_ERROR)
+ {
+ LPNETRESOURCEW pInfo = reinterpret_cast<LPNETRESOURCEW>(bufInfo.get());
+ if (wcscmp(pInfo->lpProvider, L"Web Client Network") == 0)
+ return true;
+ }
+ }
+ }
+ }
+#else
+ (void)aURL;
+#endif
+ return false;
+}
+
+} // namespace tools
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */