vcpkg/toolsrc/include/vcpkg_Files.h

61 lines
2.2 KiB
C
Raw Normal View History

2016-09-19 11:50:08 +08:00
#pragma once
2017-04-01 07:33:10 +08:00
#include "vcpkg_expected.h"
2016-11-30 10:08:53 +08:00
#include "filesystem_fs.h"
2016-11-30 09:04:41 +08:00
#include <iterator>
2016-09-19 11:50:08 +08:00
2017-01-06 04:47:08 +08:00
namespace vcpkg::Files
2016-09-19 11:50:08 +08:00
{
__interface Filesystem
{
virtual Expected<std::string> read_contents(const fs::path& file_path) noexcept = 0;
};
Filesystem& get_real_filesystem();
static const char* FILESYSTEM_INVALID_CHARACTERS = R"(\/:*?"<>|)";
2016-12-17 11:38:02 +08:00
bool has_invalid_chars_for_filesystem(const std::string& s);
2016-09-22 12:43:59 +08:00
2017-04-04 07:26:54 +08:00
Expected<std::vector<std::string>> read_all_lines(const fs::path& file_path);
void write_all_lines(const fs::path& file_path, const std::vector<std::string>& lines);
2016-11-30 10:08:53 +08:00
fs::path find_file_recursively_up(const fs::path& starting_dir, const std::string& filename);
2016-11-30 09:04:41 +08:00
template <class Pred>
void non_recursive_find_matching_paths_in_dir(const fs::path& dir, const Pred predicate, std::vector<fs::path>* output)
{
std::copy_if(fs::directory_iterator(dir), fs::directory_iterator(), std::back_inserter(*output), predicate);
}
template <class Pred>
void recursive_find_matching_paths_in_dir(const fs::path& dir, const Pred predicate, std::vector<fs::path>* output)
{
std::copy_if(fs::recursive_directory_iterator(dir), fs::recursive_directory_iterator(), std::back_inserter(*output), predicate);
}
template <class Pred>
std::vector<fs::path> recursive_find_matching_paths_in_dir(const fs::path& dir, const Pred predicate)
{
std::vector<fs::path> v;
recursive_find_matching_paths_in_dir(dir, predicate, &v);
return v;
}
void recursive_find_files_with_extension_in_dir(const fs::path& dir, const std::string& extension, std::vector<fs::path>* output);
std::vector<fs::path> recursive_find_files_with_extension_in_dir(const fs::path& dir, const std::string& extension);
void recursive_find_all_files_in_dir(const fs::path& dir, std::vector<fs::path>* output);
std::vector<fs::path> recursive_find_all_files_in_dir(const fs::path& dir);
void non_recursive_find_all_files_in_dir(const fs::path& dir, std::vector<fs::path>* output);
std::vector<fs::path> non_recursive_find_all_files_in_dir(const fs::path& dir);
2016-12-01 06:08:43 +08:00
void print_paths(const std::vector<fs::path>& paths);
2017-01-06 04:47:08 +08:00
}