From 4a2e69f99094f5c95c827ce65cfa07fe6c161c0c Mon Sep 17 00:00:00 2001 From: Vladimir Serbinenko Date: Fri, 9 Dec 2022 06:14:03 +0100 Subject: [PATCH] COMMON: conflate : and / in mac names. When using mounted images on OSX or with fusehfs : and / are swapped. When using dumper-companion it encodes / in punycode and preserves it. --- common/path.cpp | 24 +++++++++++++++++++++--- common/path.h | 1 + 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/common/path.cpp b/common/path.cpp index 82a596f6eb5..2c2e7b2a646 100644 --- a/common/path.cpp +++ b/common/path.cpp @@ -208,6 +208,24 @@ Path Path::punycodeDecode() const { return Path(res, DIR_SEPARATOR); } +String Path::getIdentifierString() const { + StringTokenizer tok(rawString(), String(DIR_SEPARATOR)); + String res; + + while (!tok.empty()) { + String part = punycode_decodefilename(tok.nextToken()); + for (uint i = 0; i < part.size(); i++) + if (part[i] == '/') + res += ':'; + else + res += part[i]; + if (!tok.empty()) + res += DIR_SEPARATOR; + } + + return res; +} + Path Path::punycodeEncode() const { StringTokenizer tok(rawString(), String(DIR_SEPARATOR)); String res; @@ -230,15 +248,15 @@ bool Path::matchPattern(const Path& pattern) const { // Prevent wildcards from matching the directory separator. const char wildcardExclusions[] = { DIR_SEPARATOR, '\0' }; - return punycodeDecode()._str.matchString(pattern.punycodeDecode()._str, true, wildcardExclusions); + return getIdentifierString().matchString(pattern.getIdentifierString(), true, wildcardExclusions); } bool Path::IgnoreCaseAndMac_EqualsTo::operator()(const Path& x, const Path& y) const { - return x.punycodeDecode()._str.equalsIgnoreCase(y.punycodeDecode()._str); + return x.getIdentifierString().equalsIgnoreCase(y.getIdentifierString()); } uint Path::IgnoreCaseAndMac_Hash::operator()(const Path& x) const { - return hashit_lower(x.punycodeDecode()._str.c_str()); + return hashit_lower(x.getIdentifierString().c_str()); } } // End of namespace Common diff --git a/common/path.h b/common/path.h index 1e0f1a6addf..db98ba6a10e 100644 --- a/common/path.h +++ b/common/path.h @@ -51,6 +51,7 @@ class Path { private: String _str; + String getIdentifierString() const; public: /** * Hash and comparator for Path with following changes: