diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2016-09-23 17:57:18 -0700 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2016-09-23 17:57:18 -0700 |
| commit | 1cd1f6a46bdd2eb8a27dabb8e8eb69d36694d6d6 (patch) | |
| tree | 09dbdbe6b0d31b719fe56b04a47571d6721bf327 | |
| parent | c7a7d062a750bce13a9db3fa8af5018d38554565 (diff) | |
| download | vcpkg-1cd1f6a46bdd2eb8a27dabb8e8eb69d36694d6d6.tar.gz vcpkg-1cd1f6a46bdd2eb8a27dabb8e8eb69d36694d6d6.zip | |
Add Files::has_invalid_chars_for_filesystem()
| -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); |
