Make file search deterministic in FindFileInPath.

Collect all entries from the recursive directory iterator, sort them, and then check for the filename. This ensures that if multiple files with the same name exist in different subdirectories, the one found is always the same, regardless of the filesystem's directory iteration order.

PiperOrigin-RevId: 902487291
Change-Id: Ia4c45cd2e3cab4a4e3825c267fc47c3134f99f76
This commit is contained in:
Matija Kecman
2026-04-20 01:26:54 -07:00
committed by Copybara-Service
parent f3f12bfad6
commit cf3f6ccf1f
+8 -1
View File
@@ -14,6 +14,7 @@
#include "experimental/platform/helpers.h"
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <cstdio>
@@ -23,6 +24,7 @@
#include <ios>
#include <iterator>
#include <string>
#include <vector>
#include "webp/encode.h"
#include "webp/types.h"
@@ -77,8 +79,13 @@ std::string ResolveFile(const std::string& filename,
return resolved;
}
std::vector<std::filesystem::path> entries;
for (const auto& it : std::filesystem::recursive_directory_iterator(path)) {
resolved = CheckPathForFile(it.path(), filename);
entries.push_back(it.path());
}
std::sort(entries.begin(), entries.end());
for (const auto& entry : entries) {
resolved = CheckPathForFile(entry, filename);
if (!resolved.empty()) {
return resolved;
}