summaryrefslogtreecommitdiff
path: root/zen/file_traverser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'zen/file_traverser.cpp')
-rw-r--r--zen/file_traverser.cpp32
1 files changed, 12 insertions, 20 deletions
diff --git a/zen/file_traverser.cpp b/zen/file_traverser.cpp
index 7fd6c596..aa39e508 100644
--- a/zen/file_traverser.cpp
+++ b/zen/file_traverser.cpp
@@ -102,9 +102,6 @@ void zen::traverseFolder(const Zstring& dirPath,
entryp = malloc(len); */
const size_t nameMax = std::max<long>(::pathconf(dirPath.c_str(), _PC_NAME_MAX), 10000); //::pathconf may return long(-1)
std::vector<char> buffer(offsetof(struct ::dirent, d_name) + nameMax + 1);
-#ifdef ZEN_MAC
- std::vector<char> bufferUtfDecomposed;
-#endif
DIR* folder = ::opendir(dirPath.c_str()); //directory must NOT end with path separator, except "/"
if (!folder)
@@ -131,26 +128,21 @@ void zen::traverseFolder(const Zstring& dirPath,
(itemNameRaw[1] == 0 || (itemNameRaw[1] == '.' && itemNameRaw[2] == 0)))
continue;
#ifdef ZEN_MAC
- //some file system abstraction layers fail to properly return decomposed UTF8: http://developer.apple.com/library/mac/#qa/qa1173/_index.html
- //so we need to do it ourselves; perf: ~600 ns per conversion
- //note: it's not sufficient to apply this in z_impl::compareFilenamesNoCase: if UTF8 forms differ, FFS assumes a rename in case sensitivity and
- // will try to propagate the rename => this won't work if target drive reports a particular UTF8 form only!
- if (CFStringRef cfStr = osx::createCFString(itemNameRaw))
+ //see native_traverser_impl.h:
+ Zstring itemName;
+ try
{
- ZEN_ON_SCOPE_EXIT(::CFRelease(cfStr));
-
- CFIndex lenMax = ::CFStringGetMaximumSizeOfFileSystemRepresentation(cfStr); //"could be much larger than the actual space required" => don't store in Zstring
- if (lenMax > 0)
- {
- bufferUtfDecomposed.resize(lenMax);
- if (::CFStringGetFileSystemRepresentation(cfStr, &bufferUtfDecomposed[0], lenMax)) //get decomposed UTF form (verified!) despite ambiguous documentation
- itemNameRaw = &bufferUtfDecomposed[0];
- }
+ itemName = osx::convertToPrecomposedUtf(itemNameRaw); //throw SysError
}
- //const char* sampleDecomposed = "\x6f\xcc\x81.txt";
- //const char* samplePrecomposed = "\xc3\xb3.txt";
-#endif
+ catch (const SysError& e) //failure is not an item-level error since wo don't have the proper decomposed name!!!
+ {
+ throw FileError(replaceCpy(_("Cannot enumerate directory %x."), L"%x", fmtPath(dirPath)),
+ L"Failed to generate precomposed file name: " + fmtPath(itemNameRaw) + L"\n" + e.toString()); //too obscure to warrant translation
+ }
+ const Zstring& itemPath = appendSeparator(dirPath) + itemName;
+#else
const Zstring& itemPath = appendSeparator(dirPath) + itemNameRaw;
+#endif
struct ::stat statData = {};
try
bgstack15