From d380db8a1f408fd190e0b60ff2bd8094c167cac4 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Mon, 11 Nov 2024 22:02:47 +0100 Subject: [PATCH] Fixed an issue where placing a directory with no access permissions inside a system folder crashed the application on startup --- es-core/src/utils/FileSystemUtil.cpp | 43 ++++++++++++++++++---------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/es-core/src/utils/FileSystemUtil.cpp b/es-core/src/utils/FileSystemUtil.cpp index 309efce85..1bf55bc3f 100644 --- a/es-core/src/utils/FileSystemUtil.cpp +++ b/es-core/src/utils/FileSystemUtil.cpp @@ -67,29 +67,42 @@ namespace Utils if (!isDirectory(genericPath)) return contentList; - if (recursive) { + try { + if (recursive) { #if defined(_WIN64) - for (auto& entry : std::filesystem::recursive_directory_iterator( - Utils::String::stringToWideString(genericPath))) { - contentList.emplace_back( - Utils::String::wideStringToString(entry.path().generic_wstring())); + for (auto& entry : std::filesystem::recursive_directory_iterator( + Utils::String::stringToWideString(genericPath))) { + contentList.emplace_back( + Utils::String::wideStringToString(entry.path().generic_wstring())); #else - for (auto& entry : std::filesystem::recursive_directory_iterator(genericPath)) { - contentList.emplace_back(entry.path().generic_string()); + for (auto& entry : std::filesystem::recursive_directory_iterator(genericPath)) { + contentList.emplace_back(entry.path().generic_string()); #endif + } + } + else { +#if defined(_WIN64) + for (auto& entry : std::filesystem::directory_iterator( + Utils::String::stringToWideString(genericPath))) { + contentList.emplace_back( + Utils::String::wideStringToString(entry.path().generic_wstring())); +#else + for (auto& entry : std::filesystem::directory_iterator(genericPath)) { + contentList.emplace_back(entry.path().generic_string()); +#endif + } } } - else { + catch (...) { #if defined(_WIN64) - for (auto& entry : std::filesystem::directory_iterator( - Utils::String::stringToWideString(genericPath))) { - contentList.emplace_back( - Utils::String::wideStringToString(entry.path().generic_wstring())); + LOG(LogError) << "FileSystemUtil::getDirContent(): Couldn't read directory " << "\"" + << Utils::String::replace(path, "/", "\\") + << "\", permission problems?"; #else - for (auto& entry : std::filesystem::directory_iterator(genericPath)) { - contentList.emplace_back(entry.path().generic_string()); + LOG(LogError) << "FileSystemUtil::getDirContent(): Couldn't read directory " << "\"" + << path << "\", permission problems?"; #endif - } + return contentList; } contentList.sort();