[Libreoffice-commits] core.git: sc/source
Mike Kaganski (via logerrit)
logerrit at kemper.freedesktop.org
Sun Jan 3 13:55:27 UTC 2021
sc/source/filter/orcus/orcusfiltersimpl.cxx | 36 ++++++++++++++++++++++++----
1 file changed, 32 insertions(+), 4 deletions(-)
New commits:
commit 75252e58d9b5d020bf7bd6ca66b3a9d780463051
Author: Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Tue Dec 29 11:35:12 2020 +0300
Commit: Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Sun Jan 3 14:54:49 2021 +0100
Try GetShortPathNameW workaround for Unicode paths with orcus
It doesn't yet allow to pass a Unicode path to file_content ctor;
so in case of a filesystem error try to use a short path, which
should only contain ASCII characters.
This workarounds the failure when installation directory contains
characters not representable in ACP.
The previous code that used RTL_TEXTENCODING_UTF8 for encoding the
path string was wrong, since orcus does not use file APIs expecting
UTF-8, but rather expecting current thread encoding. It failed for
any path that contained non-ASCII characters on Windows, even those
that may be represented in ACP.
Change-Id: Id956f550f3b0fa19d9f2c0178c3f7ae9553b7458
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108483
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
diff --git a/sc/source/filter/orcus/orcusfiltersimpl.cxx b/sc/source/filter/orcus/orcusfiltersimpl.cxx
index d3211c6dfa2b..f063bd3b5524 100644
--- a/sc/source/filter/orcus/orcusfiltersimpl.cxx
+++ b/sc/source/filter/orcus/orcusfiltersimpl.cxx
@@ -11,6 +11,9 @@
#include <orcusinterface.hxx>
#include <tokenarray.hxx>
+#include <memory>
+
+#include <osl/thread.hxx>
#include <sfx2/docfile.hxx>
#include <sfx2/frame.hxx>
#include <sfx2/sfxsids.hrc>
@@ -27,6 +30,13 @@
#include <orcus/stream.hpp>
#include <com/sun/star/task/XStatusIndicator.hpp>
+#if defined _WIN32
+#include <boost/filesystem/operations.hpp> // for boost::filesystem::filesystem_error
+#include <o3tl/char16_t2wchar_t.hxx>
+#include <prewin.h>
+#include <postwin.h>
+#endif
+
using namespace com::sun::star;
namespace
@@ -119,15 +129,33 @@ bool ScOrcusFiltersImpl::importODS(ScDocument& rDoc, SfxMedium& rMedium) const
bool ScOrcusFiltersImpl::importODS_Styles(ScDocument& rDoc, OUString& aPath) const
{
- OString aUrl = OUStringToOString(aPath, RTL_TEXTENCODING_UTF8);
- const char* path = aUrl.getStr();
+ OString aPath8 = OUStringToOString(aPath, osl_getThreadTextEncoding());
try
{
- orcus::file_content content(path);
+#if defined _WIN32
+ std::unique_ptr<orcus::file_content> content;
+ try
+ {
+ content = std::make_unique<orcus::file_content>(aPath8.getStr());
+ }
+ catch (const boost::filesystem::filesystem_error&)
+ {
+ // Maybe the path contains characters not representable in ACP. It's not
+ // yet possible to pass Unicode path to orcus::file_content ctor - see
+ // https://gitlab.com/orcus/orcus/-/issues/30; try short path.
+ wchar_t buf[32767];
+ if (GetShortPathNameW(o3tl::toW(aPath.getStr()), buf, std::size(buf)) == 0)
+ throw;
+ aPath8 = OUStringToOString(o3tl::toU(buf), osl_getThreadTextEncoding());
+ content = std::make_unique<orcus::file_content>(aPath8.getStr());
+ }
+#else
+ auto content = std::make_unique<orcus::file_content>(aPath8.getStr());
+#endif
ScOrcusFactory aFactory(rDoc);
ScOrcusStyles aStyles(aFactory);
- orcus::import_ods::read_styles(content.data(), content.size(), &aStyles);
+ orcus::import_ods::read_styles(content->data(), content->size(), &aStyles);
}
catch (const std::exception& e)
{
More information about the Libreoffice-commits
mailing list