diff options
| author | LiGuilin <liguilin0522@qq.com> | 2016-10-08 08:34:12 +0800 |
|---|---|---|
| committer | LiGuilin <liguilin0522@qq.com> | 2016-10-08 08:34:12 +0800 |
| commit | c91da2b0c4c3d9218c0b4d1712d744bb35245a61 (patch) | |
| tree | e1ae0664a4f21f3948bde8c8f9f9e55dea0cb11f /toolsrc/src/vcpkg_Files.cpp | |
| parent | 280d88b34033ab728e02f725d8d8ff5f9250c6de (diff) | |
| parent | a0f621c0fca2c3de8bd5249f023979b800c543cf (diff) | |
| download | vcpkg-c91da2b0c4c3d9218c0b4d1712d744bb35245a61.tar.gz vcpkg-c91da2b0c4c3d9218c0b4d1712d744bb35245a61.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'toolsrc/src/vcpkg_Files.cpp')
| -rw-r--r-- | toolsrc/src/vcpkg_Files.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/toolsrc/src/vcpkg_Files.cpp b/toolsrc/src/vcpkg_Files.cpp index 49a661157..611aa7450 100644 --- a/toolsrc/src/vcpkg_Files.cpp +++ b/toolsrc/src/vcpkg_Files.cpp @@ -1,16 +1,24 @@ #include "vcpkg_Files.h" #include <fstream> #include <filesystem> +#include <regex> namespace fs = std::tr2::sys; namespace vcpkg {namespace Files { + static const std::regex FILESYSTEM_INVALID_CHARACTERS_REGEX = std::regex(R"([\/:*?"<>|])"); + void check_is_directory(const fs::path& dirpath) { Checks::check_throw(fs::is_directory(dirpath), "The path %s is not a directory", dirpath.string()); } + bool has_invalid_chars_for_filesystem(const std::string s) + { + return std::regex_search(s, FILESYSTEM_INVALID_CHARACTERS_REGEX); + } + expected<std::string> get_contents(const fs::path& file_path) noexcept { std::fstream file_stream(file_path, std::ios_base::in | std::ios_base::binary); @@ -35,4 +43,19 @@ namespace vcpkg {namespace Files return std::move(output); } + + fs::path find_file_recursively_up(const fs::path& starting_dir, const std::string& filename) + { + fs::path current_dir = starting_dir; + for (; !current_dir.empty(); current_dir = current_dir.parent_path()) + { + const fs::path candidate = current_dir / filename; + if (fs::exists(candidate)) + { + break; + } + } + + return current_dir; + } }} |
