diff options
| author | Thomas Fussell <thomas.fussell@gmail.com> | 2017-01-01 18:28:56 -0500 |
|---|---|---|
| committer | Thomas Fussell <thomas.fussell@gmail.com> | 2017-01-01 18:28:56 -0500 |
| commit | 32dd084deadecd726172b85239c30bbbf683f62b (patch) | |
| tree | 492044fa3bce12e930d6c565d92095d71fac68e5 /toolsrc/src/vcpkg_Files.cpp | |
| parent | 937c246ac2aa6ec11a02d0cb36a4e50919842c8a (diff) | |
| parent | bc8cca82a297e37bf9dde387991c1d51618273b7 (diff) | |
| download | vcpkg-32dd084deadecd726172b85239c30bbbf683f62b.tar.gz vcpkg-32dd084deadecd726172b85239c30bbbf683f62b.zip | |
Merge branch 'master' of http://github.com/Microsoft/vcpkg
Diffstat (limited to 'toolsrc/src/vcpkg_Files.cpp')
| -rw-r--r-- | toolsrc/src/vcpkg_Files.cpp | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/toolsrc/src/vcpkg_Files.cpp b/toolsrc/src/vcpkg_Files.cpp index 698579736..48283e43f 100644 --- a/toolsrc/src/vcpkg_Files.cpp +++ b/toolsrc/src/vcpkg_Files.cpp @@ -9,15 +9,15 @@ namespace vcpkg {namespace Files void check_is_directory(const fs::path& dirpath) { - Checks::check_throw(fs::is_directory(dirpath), "The path %s is not a directory", dirpath.string()); + Checks::check_exit(fs::is_directory(dirpath), "The path %s is not a directory", dirpath.string()); } - bool has_invalid_chars_for_filesystem(const std::string s) + 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 + expected<std::string> read_contents(const fs::path& file_path) noexcept { std::fstream file_stream(file_path, std::ios_base::in | std::ios_base::binary); if (file_stream.fail()) @@ -42,6 +42,35 @@ namespace vcpkg {namespace Files return std::move(output); } + expected<std::vector<std::string>> read_all_lines(const fs::path& file_path) + { + std::fstream file_stream(file_path, std::ios_base::in | std::ios_base::binary); + if (file_stream.fail()) + { + return std::errc::no_such_file_or_directory; + } + + std::vector<std::string> output; + std::string line; + while (std::getline(file_stream, line)) + { + output.push_back(line); + } + file_stream.close(); + + return std::move(output); + } + + void write_all_lines(const fs::path& file_path, const std::vector<std::string>& lines) + { + std::fstream output(file_path, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc); + for (const std::string& line : lines) + { + output << line << "\n"; + } + output.close(); + } + fs::path find_file_recursively_up(const fs::path& starting_dir, const std::string& filename) { fs::path current_dir = starting_dir; |
