diff options
| -rw-r--r-- | toolsrc/include/vcpkg_Files.h | 4 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg_Files.cpp | 8 |
2 files changed, 12 insertions, 0 deletions
diff --git a/toolsrc/include/vcpkg_Files.h b/toolsrc/include/vcpkg_Files.h index 2c24f9508..445713965 100644 --- a/toolsrc/include/vcpkg_Files.h +++ b/toolsrc/include/vcpkg_Files.h @@ -5,8 +5,12 @@ namespace vcpkg {namespace Files { + static const char* FILESYSTEM_INVALID_CHARACTERS = R"(\/:*?"<>|)"; + void check_is_directory(const std::tr2::sys::path& dirpath); + bool has_invalid_chars_for_filesystem(const std::string s); + expected<std::string> get_contents(const std::tr2::sys::path& file_path) noexcept; std::tr2::sys::path find_file_recursively_up(const std::tr2::sys::path& starting_dir, const std::string& filename); diff --git a/toolsrc/src/vcpkg_Files.cpp b/toolsrc/src/vcpkg_Files.cpp index ef330ea27..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); |
