1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-28 20:39:41 +00:00

Merge branch 'recursive_directory_iteration_errors' into 'master'

Add context to the errors on recursive iteration over directory

See merge request OpenMW/openmw!3872
This commit is contained in:
psi29a 2024-02-19 10:00:24 +00:00
commit e88e92d3aa

View file

@ -20,11 +20,14 @@ namespace VFS
if (prefix > 0 && str[prefix - 1] != '\\' && str[prefix - 1] != '/') if (prefix > 0 && str[prefix - 1] != '\\' && str[prefix - 1] != '/')
++prefix; ++prefix;
for (const auto& i : std::filesystem::recursive_directory_iterator(mPath)) std::filesystem::recursive_directory_iterator iterator(mPath);
{
if (std::filesystem::is_directory(i))
continue;
for (auto it = std::filesystem::begin(iterator), end = std::filesystem::end(iterator); it != end;)
{
const auto& i = *it;
if (!std::filesystem::is_directory(i))
{
const std::filesystem::path& filePath = i.path(); const std::filesystem::path& filePath = i.path();
const std::string proper = Files::pathToUnicodeString(filePath); const std::string proper = Files::pathToUnicodeString(filePath);
VFS::Path::Normalized searchable(std::string_view{ proper }.substr(prefix)); VFS::Path::Normalized searchable(std::string_view{ proper }.substr(prefix));
@ -36,6 +39,18 @@ namespace VFS
<< "Found duplicate file for '" << proper << "Found duplicate file for '" << proper
<< "', please check your file system for two files with the same name in different cases."; << "', please check your file system for two files with the same name in different cases.";
} }
// Exception thrown by the operator++ may not contain the context of the error like what exact path caused
// the problem which makes it hard to understand what's going on when iteration happens over a directory
// with thousands of files and subdirectories.
const std::filesystem::path prevPath = i.path();
std::error_code ec;
it.increment(ec);
if (ec != std::error_code())
throw std::runtime_error("Failed to recursively iterate over \"" + Files::pathToUnicodeString(mPath)
+ "\" when incrementing to the next item from \"" + Files::pathToUnicodeString(prevPath)
+ "\": " + ec.message());
}
} }
void FileSystemArchive::listResources(FileMap& out) void FileSystemArchive::listResources(FileMap& out)