OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
shared::anonymous_namespace{file_path_util.cpp} Namespace Reference

Functions

std::vector< std::string > glob_local_recursive_files (const std::string &file_path, const bool recurse)
 
std::vector< std::string > regex_file_filter (const std::string &pattern, const std::vector< std::string > &file_paths)
 

Function Documentation

std::vector<std::string> shared::anonymous_namespace{file_path_util.cpp}::glob_local_recursive_files ( const std::string &  file_path,
const bool  recurse 
)

Definition at line 58 of file file_path_util.cpp.

References heavyai::glob(), and shared::throw_file_not_found().

Referenced by shared::local_glob_filter_sort_files().

59  {
60 #if 107200 <= BOOST_VERSION
61  constexpr auto options = boost::filesystem::directory_options::follow_directory_symlink;
62 #else
63  constexpr auto options = boost::filesystem::symlink_option::recurse;
64 #endif
65  std::vector<std::string> file_paths;
66 
67  if (boost::filesystem::is_regular_file(file_path)) {
68  file_paths.emplace_back(file_path);
69  } else if (recurse && boost::filesystem::is_directory(file_path)) {
70  for (boost::filesystem::recursive_directory_iterator it(file_path, options), eit;
71  it != eit;
72  ++it) {
73  if (!boost::filesystem::is_directory(it->path())) {
74  file_paths.emplace_back(it->path().string());
75  }
76  }
77  // empty directories will not throw an error
78  } else {
79  auto glob_results = heavyai::glob(file_path);
80  for (const auto& path : glob_results) {
81  if (recurse && boost::filesystem::is_directory(path)) {
82  auto expanded_paths = glob_local_recursive_files(path, true);
83  file_paths.insert(file_paths.end(), expanded_paths.begin(), expanded_paths.end());
84  } else {
85  file_paths.emplace_back(path);
86  }
87  }
88  if (file_paths.empty()) {
89  throw_file_not_found(file_path);
90  }
91  }
92  return file_paths;
93 }
void throw_file_not_found(const std::string &file_path)
std::vector< std::string > glob_local_recursive_files(const std::string &file_path, const bool recurse)
std::vector< std::string > glob(const std::string &pattern)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector<std::string> shared::anonymous_namespace{file_path_util.cpp}::regex_file_filter ( const std::string &  pattern,
const std::vector< std::string > &  file_paths 
)

Definition at line 95 of file file_path_util.cpp.

References shared::throw_no_filter_match().

Referenced by shared::local_glob_filter_sort_files().

96  {
97  boost::regex regex_pattern(pattern);
98  std::vector<std::string> matched_file_paths;
99  for (const auto& path : file_paths) {
100  if (boost::regex_match(path, regex_pattern)) {
101  matched_file_paths.emplace_back(path);
102  }
103  }
104  if (matched_file_paths.empty()) {
105  throw_no_filter_match(pattern);
106  }
107  return matched_file_paths;
108 }
void throw_no_filter_match(const std::string &pattern)

+ Here is the call graph for this function:

+ Here is the caller graph for this function: