diff options
| author | Phil Christensen <philc@microsoft.com> | 2019-03-15 10:30:16 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-03-15 10:30:16 -0700 |
| commit | ee957d9170d12f9d15b2195c8b0bdaca7e78829f (patch) | |
| tree | 3d432da02a04a9c675c6e0243279abf5f4c8e008 | |
| parent | 532528903c437ca59a1b7fcd3841b668ef6892cc (diff) | |
| parent | 184fd3a1b1b57720562729906ae341c801382d56 (diff) | |
| download | vcpkg-ee957d9170d12f9d15b2195c8b0bdaca7e78829f.tar.gz vcpkg-ee957d9170d12f9d15b2195c8b0bdaca7e78829f.zip | |
Merge pull request #5679 from ras0219-msft/dev/roschuma/fix-recursive-find-up
[vcpkg] Fix infinite loop bug on certain filesystem implementations when searching up
| -rw-r--r-- | toolsrc/src/vcpkg/base/files.cpp | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/toolsrc/src/vcpkg/base/files.cpp b/toolsrc/src/vcpkg/base/files.cpp index 1740b6f6d..34a6489a8 100644 --- a/toolsrc/src/vcpkg/base/files.cpp +++ b/toolsrc/src/vcpkg/base/files.cpp @@ -71,18 +71,42 @@ namespace vcpkg::Files virtual fs::path find_file_recursively_up(const fs::path& starting_dir, const std::string& filename) const override { - static const fs::path UNIX_ROOT = "/"; fs::path current_dir = starting_dir; - for (; !current_dir.empty() && current_dir != UNIX_ROOT; current_dir = current_dir.parent_path()) + if (exists(current_dir / filename)) { + return current_dir; + } + + int counter = 10000; + for (;;) + { + // This is a workaround for VS2015's experimental filesystem implementation + if (!current_dir.has_relative_path()) + { + current_dir.clear(); + return current_dir; + } + + auto parent = current_dir.parent_path(); + if (parent == current_dir) + { + current_dir.clear(); + return current_dir; + } + + current_dir = std::move(parent); + const fs::path candidate = current_dir / filename; if (exists(candidate)) { return current_dir; } - } - return fs::path(); + --counter; + Checks::check_exit(VCPKG_LINE_INFO, + counter > 0, + "infinite loop encountered while trying to find_file_recursively_up()"); + } } virtual std::vector<fs::path> get_files_recursive(const fs::path& dir) const override |
