Changed most try/catch statements in FileSystemUtil to actually output the std::filesystem error messages

This commit is contained in:
Leon Styhre 2023-08-02 20:28:29 +02:00
parent 05cfbb55bd
commit c22bdae16e

View file

@ -70,30 +70,25 @@ namespace Utils
if (!isDirectory(genericPath)) if (!isDirectory(genericPath))
return contentList; return contentList;
try { if (recursive) {
if (recursive) { for (auto& entry : std::filesystem::recursive_directory_iterator(genericPath)) {
for (auto& entry : std::filesystem::recursive_directory_iterator(genericPath)) {
#if defined(_WIN64) #if defined(_WIN64)
contentList.emplace_back( contentList.emplace_back(
Utils::String::wideStringToString(entry.path().generic_wstring())); Utils::String::wideStringToString(entry.path().generic_wstring()));
#else #else
contentList.emplace_back(entry.path().generic_string()); contentList.emplace_back(entry.path().generic_string());
#endif #endif
}
}
else {
for (auto& entry : std::filesystem::directory_iterator(genericPath)) {
#if defined(_WIN64)
contentList.emplace_back(
Utils::String::wideStringToString(entry.path().generic_wstring()));
#else
contentList.emplace_back(entry.path().generic_string());
#endif
}
} }
} }
catch (...) { else {
return contentList; for (auto& entry : std::filesystem::directory_iterator(genericPath)) {
#if defined(_WIN64)
contentList.emplace_back(
Utils::String::wideStringToString(entry.path().generic_wstring()));
#else
contentList.emplace_back(entry.path().generic_string());
#endif
}
} }
contentList.sort(); contentList.sort();
@ -583,7 +578,8 @@ namespace Utils
return static_cast<long>(std::filesystem::file_size(path)); return static_cast<long>(std::filesystem::file_size(path));
#endif #endif
} }
catch (...) { catch (std::filesystem::filesystem_error& error) {
LOG(LogError) << "FileSystemUtil::getFileSize(): " << error.what();
return -1; return -1;
} }
} }
@ -897,7 +893,8 @@ namespace Utils
return std::filesystem::exists(genericPath); return std::filesystem::exists(genericPath);
#endif #endif
} }
catch (...) { catch (std::filesystem::filesystem_error& error) {
LOG(LogError) << "FileSystemUtil::exists(): " << error.what();
return false; return false;
} }
} }
@ -945,7 +942,8 @@ namespace Utils
return std::filesystem::is_regular_file(genericPath); return std::filesystem::is_regular_file(genericPath);
#endif #endif
} }
catch (...) { catch (std::filesystem::filesystem_error& error) {
LOG(LogError) << "FileSystemUtil::isRegularFile(): " << error.what();
return false; return false;
} }
} }
@ -961,7 +959,8 @@ namespace Utils
return std::filesystem::is_directory(genericPath); return std::filesystem::is_directory(genericPath);
#endif #endif
} }
catch (...) { catch (std::filesystem::filesystem_error& error) {
LOG(LogError) << "FileSystemUtil::isDirectory(): " << error.what();
return false; return false;
} }
} }
@ -976,7 +975,8 @@ namespace Utils
return std::filesystem::is_symlink(genericPath); return std::filesystem::is_symlink(genericPath);
#endif #endif
} }
catch (...) { catch (std::filesystem::filesystem_error& error) {
LOG(LogError) << "FileSystemUtil::isSymlink(): " << error.what();
return false; return false;
} }
} }