sc/qa/unit/subsequent_export-test.cxx | 10 ++-------- svl/qa/unit/test_URIHelper.cxx | 5 ----- tools/qa/cppunit/test_urlobj.cxx | 34 +++++----------------------------- tools/source/fsys/urlobj.cxx | 11 ----------- ucb/Library_ucpfile1.mk | 1 + ucb/source/ucp/file/prov.cxx | 19 +++++++++++++++++++ 6 files changed, 27 insertions(+), 53 deletions(-)
New commits: commit 46c645bf4e9909f5296e75028f1f5434e83942d2 Author: Stephan Bergmann <sberg...@redhat.com> AuthorDate: Mon Feb 4 17:38:29 2019 +0100 Commit: Stephan Bergmann <sberg...@redhat.com> CommitDate: Tue Feb 5 19:55:04 2019 +0100 Move dubious file: -> smb: conversion from INetURLObject to file UCP The Linux-only conversion of file URLs with a non-empty (other than "localhost") authority to smb URLs had been added in 2010 with 0b9ef81ba5ff08d85f21275222458a5b9b9e484c "tools-urlobj-smb-scheme-patch.diff: migrated" (applying a Go-oo patch?) but giving no rationale beyond "process relative SMB paths (in hyperlinks) correctly". That makes it hard to tell whether that patch is (still) actively useful for anything, or was just a misguided hack from the beginning: * Why make this Linux only? What about other non-Windows OSs? (On Windows, such URLs can be resolved as UNC pathnames.) If the reason for Linux-only was that it is the only OS where LO can handle smb URLs via GIO, why not make it conditional on ENABLE_GIO? * Why map to smb? There are various remote file access protocols. Hardcoding smb looks arbitrary here. Anyway, INetURLObject is arguably at a wrong level for such a patch. To not drop the hack wholesale, reimplement it in the file UCP, forwarding to a potential other UCP that can handle smb URLs any file://<host>/... URLs (rewritten as smb URLs) that the file UCP cannot handle itself. (file://localhost/... URLs will already have been normalized to file:///... by INetURLObject when they reach the file UCP, and even if they were not, the osl/file.hxx functionality underlying fileaccess::TaskManager::getUnqFromUrl knows how to handle them, so they will not take the forward-to-smb code branch.) (The corresponding #ifdef WIN code from 0b9ef81ba5ff08d85f21275222458a5b9b9e484c has already been removed with 82034b04e81b74a048595b0eac0f73581ecbc9e4 "tdf#119326 crash when adding "Windows Share" File resource".) (I came across that 2010 patch while looking into <https://bugs.documentfoundation.org/show_bug.cgi?id=107461> "Does not support 'file://' scheme with actual hostname". A next step would be to make the file UCP actually handle any file://<host>/... URLs that denote the local host.) Change-Id: I77242705dc4c6c1e9cb3a4f32253224ac6cb13cb Reviewed-on: https://gerrit.libreoffice.org/67372 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sberg...@redhat.com> diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx index f99029dfcaef..1b44d58235c5 100644 --- a/sc/qa/unit/subsequent_export-test.cxx +++ b/sc/qa/unit/subsequent_export-test.cxx @@ -4163,18 +4163,12 @@ void ScExportTest::testTdf118990() // file:///share/lookupsource.xlsx - which is incorrect, since it points to local filesystem // and not to Windows network share. -#if defined LINUX // following INetURLObject::setAbsURIRef -#define TDF118990_SCHEME "smb:" -#else // for Windows and macOS -#define TDF118990_SCHEME "file:" -#endif - ASSERT_FORMULA_EQUAL(rDoc, ScAddress(0, 1, 0), - "VLOOKUP(B1,'" TDF118990_SCHEME "//192.168.1.1/share/lookupsource.xlsx'#$Sheet1.A1:B5,2)", + "VLOOKUP(B1,'file://192.168.1.1/share/lookupsource.xlsx'#$Sheet1.A1:B5,2)", "Wrong Windows share (using host IP) URL in A2"); ASSERT_FORMULA_EQUAL(rDoc, ScAddress(0, 2, 0), - "VLOOKUP(B1,'" TDF118990_SCHEME "//NETWORKHOST/share/lookupsource.xlsx'#$Sheet1.A1:B5,2)", + "VLOOKUP(B1,'file://NETWORKHOST/share/lookupsource.xlsx'#$Sheet1.A1:B5,2)", "Wrong Windows share (using hostname) URL in A3"); xDocSh->DoClose(); diff --git a/svl/qa/unit/test_URIHelper.cxx b/svl/qa/unit/test_URIHelper.cxx index 233b812a54c7..a30de1540af9 100644 --- a/svl/qa/unit/test_URIHelper.cxx +++ b/svl/qa/unit/test_URIHelper.cxx @@ -300,12 +300,7 @@ void Test::testFindFirstURLInText() { "ftp://bla.bla.bla/blubber/", 3, 29 }, { "..\\ftp://bla.bla.bla/blubber/...", nullptr, 0, 0 }, { "..\\ftp:\\\\bla.bla.bla\\blubber/...", -//Sync with tools/source/fsys/urlobj.cxx and changeScheme -#ifdef LINUX - "smb://bla.bla.bla/blubber%2F", 7, 29 }, -#else "file://bla.bla.bla/blubber%2F", 7, 29 }, -#endif { "http://sun.com", "http://sun.com/", 0, 14 }, { "http://sun.com/", "http://sun.com/", 0, 15 }, { "http://www.xerox....@www.pcworld.com/go/3990332.htm", nullptr, 0, 0 }, diff --git a/tools/qa/cppunit/test_urlobj.cxx b/tools/qa/cppunit/test_urlobj.cxx index 581a19478e67..2c391fbf513d 100644 --- a/tools/qa/cppunit/test_urlobj.cxx +++ b/tools/qa/cppunit/test_urlobj.cxx @@ -49,11 +49,7 @@ namespace tools_urlobj void urlobjTest_001( ) { INetURLObject aUrl( OUString( "file://10.10.1.1/sampledir/sample.file" ) ); -#ifdef LINUX - CPPUNIT_ASSERT_EQUAL(OUString("smb://10.10.1.1/sampledir/sample.file"), - aUrl.GetMainURL(INetURLObject::DecodeMechanism::NONE)); - CPPUNIT_ASSERT_EQUAL(INetProtocol::Smb, aUrl.GetProtocol()); -#endif + CPPUNIT_ASSERT_EQUAL(INetProtocol::File, aUrl.GetProtocol()); CPPUNIT_ASSERT_EQUAL(OUString("10.10.1.1"), aUrl.GetHost(INetURLObject::DecodeMechanism::NONE)); CPPUNIT_ASSERT_EQUAL(OUString("/sampledir/sample.file"), @@ -70,11 +66,7 @@ namespace tools_urlobj aUrl. setFSysPath( "\\\\137.65.170.24\\c$\\Img0001.jpg", FSysStyle::Detect ); -#ifdef LINUX - CPPUNIT_ASSERT_EQUAL(OUString("smb://137.65.170.24/c$/Img0001.jpg"), - aUrl.GetMainURL(INetURLObject::DecodeMechanism::NONE)); - CPPUNIT_ASSERT_EQUAL(INetProtocol::Smb, aUrl.GetProtocol()); -#endif + CPPUNIT_ASSERT_EQUAL(INetProtocol::File, aUrl.GetProtocol()); CPPUNIT_ASSERT_EQUAL(OUString("137.65.170.24"), aUrl.GetHost(INetURLObject::DecodeMechanism::NONE)); CPPUNIT_ASSERT_EQUAL(OUString("/c$/Img0001.jpg"), @@ -91,11 +83,7 @@ namespace tools_urlobj aUrl. setFSysPath( "\\\\hive-winxp-x86\\pmladek\\test2.odt", FSysStyle::Detect ); -#ifdef LINUX - CPPUNIT_ASSERT_EQUAL(OUString("smb://hive-winxp-x86/pmladek/test2.odt"), - aUrl.GetMainURL(INetURLObject::DecodeMechanism::NONE)); - CPPUNIT_ASSERT_EQUAL(INetProtocol::Smb, aUrl.GetProtocol()); -#endif + CPPUNIT_ASSERT_EQUAL(INetProtocol::File, aUrl.GetProtocol()); CPPUNIT_ASSERT_EQUAL(OUString("hive-winxp-x86"), aUrl.GetHost(INetURLObject::DecodeMechanism::NONE)); CPPUNIT_ASSERT_EQUAL(OUString("/pmladek/test2.odt"), @@ -105,11 +93,7 @@ namespace tools_urlobj void urlobjTest_004( ) { INetURLObject aUrl( OUString( "smb://10.10.1.1/sampledir/sample.file" ) ); -#ifdef LINUX - CPPUNIT_ASSERT_EQUAL(OUString("smb://10.10.1.1/sampledir/sample.file"), - aUrl.GetMainURL(INetURLObject::DecodeMechanism::NONE)); CPPUNIT_ASSERT_EQUAL( INetProtocol::Smb, aUrl.GetProtocol( ) ); -#endif CPPUNIT_ASSERT_EQUAL(OUString("10.10.1.1"), aUrl.GetHost(INetURLObject::DecodeMechanism::NONE)); CPPUNIT_ASSERT_EQUAL(OUString("/sampledir/sample.file"), @@ -124,11 +108,7 @@ namespace tools_urlobj INetURLObject aUrl; aUrl.setFSysPath( "//137.65.170.24/c$/Img0001.jpg", FSysStyle::Detect ); -#ifdef LINUX - CPPUNIT_ASSERT_EQUAL(OUString("smb://137.65.170.24/c$/Img0001.jpg"), - aUrl.GetMainURL(INetURLObject::DecodeMechanism::NONE)); - CPPUNIT_ASSERT_EQUAL(INetProtocol::Smb, aUrl.GetProtocol()); -#endif + CPPUNIT_ASSERT_EQUAL(INetProtocol::File, aUrl.GetProtocol()); CPPUNIT_ASSERT_EQUAL(OUString("137.65.170.24"), aUrl.GetHost(INetURLObject::DecodeMechanism::NONE)); CPPUNIT_ASSERT_EQUAL(OUString("/c$/Img0001.jpg"), @@ -144,11 +124,7 @@ namespace tools_urlobj INetURLObject aUrl; aUrl.setFSysPath( "//hive-winxp-x86/pmladek/test2.odt", FSysStyle::Detect ); -#ifdef LINUX - CPPUNIT_ASSERT_EQUAL(OUString("smb://hive-winxp-x86/pmladek/test2.odt"), - aUrl.GetMainURL(INetURLObject::DecodeMechanism::NONE)); - CPPUNIT_ASSERT_EQUAL(INetProtocol::Smb, aUrl.GetProtocol()); -#endif + CPPUNIT_ASSERT_EQUAL(INetProtocol::File, aUrl.GetProtocol()); CPPUNIT_ASSERT_EQUAL(OUString("hive-winxp-x86"), aUrl.GetHost(INetURLObject::DecodeMechanism::NONE)); CPPUNIT_ASSERT_EQUAL(OUString("/pmladek/test2.odt"), diff --git a/tools/source/fsys/urlobj.cxx b/tools/source/fsys/urlobj.cxx index 45bd5a0d283f..445e27772955 100644 --- a/tools/source/fsys/urlobj.cxx +++ b/tools/source/fsys/urlobj.cxx @@ -1444,17 +1444,6 @@ bool INetURLObject::setAbsURIRef(OUString const & rTheAbsURIRef, m_aAbsURIRef = aSynAbsURIRef; - // At this point references of type "\\server\paths" have - // been converted to file:://server/path". -#ifdef LINUX - if (m_eScheme==INetProtocol::File && !m_aHost.isEmpty()) { - // Change "file:://server/path" URIs to "smb:://server/path" on - // Linux - // Leave "file::path" URIs unchanged. - changeScheme(INetProtocol::Smb); - } -#endif - return true; } diff --git a/ucb/Library_ucpfile1.mk b/ucb/Library_ucpfile1.mk index 4505708cbac8..f676eacbde3f 100644 --- a/ucb/Library_ucpfile1.mk +++ b/ucb/Library_ucpfile1.mk @@ -21,6 +21,7 @@ $(eval $(call gb_Library_use_libraries,ucpfile1,\ cppu \ cppuhelper \ sal \ + tl \ ucbhelper \ )) diff --git a/ucb/source/ucp/file/prov.cxx b/ucb/source/ucp/file/prov.cxx index 22b77d8fadaf..a5b4c0d49c1f 100644 --- a/ucb/source/ucp/file/prov.cxx +++ b/ucb/source/ucp/file/prov.cxx @@ -21,6 +21,8 @@ #include <osl/file.hxx> #include <osl/socket.h> #include <sal/log.hxx> +#include <tools/urlobj.hxx> +#include <ucbhelper/content.hxx> #include <cppuhelper/queryinterface.hxx> #include <comphelper/processfactory.hxx> #include <com/sun/star/beans/PropertyAttribute.hpp> @@ -170,7 +172,24 @@ FileProvider::queryContent( aUnc ); if( err ) + { + // Hack to retry file://<host>/... URLs as smb URLs: + INetURLObject url(xIdentifier->getContentIdentifier()); + if (url.GetProtocol() == INetProtocol::File + && !url.GetHost(INetURLObject::DecodeMechanism::NONE).isEmpty()) + { + url.changeScheme(INetProtocol::Smb); + ucbhelper::Content content; + if (ucbhelper::Content::create( + url.GetMainURL(INetURLObject::DecodeMechanism::NONE), + css::uno::Reference<css::ucb::XCommandEnvironment>(), m_xContext, content)) + { + return content.get(); + } + } + throw IllegalIdentifierException( THROW_WHERE ); + } return Reference< XContent >( new BaseContent( m_pMyShell.get(), xIdentifier, aUnc ) ); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits