OmniSciDB  a987f07e93
 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  std::vector<std::string> file_paths;
61 
62  if (boost::filesystem::is_regular_file(file_path)) {
63  file_paths.emplace_back(file_path);
64  } else if (recurse && boost::filesystem::is_directory(file_path)) {
65  for (boost::filesystem::recursive_directory_iterator
66  it(file_path, boost::filesystem::symlink_option::recurse),
67  eit;
68  it != eit;
69  ++it) {
70  if (!boost::filesystem::is_directory(it->path())) {
71  file_paths.emplace_back(it->path().string());
72  }
73  }
74  // empty directories will not throw an error
75  } else {
76  auto glob_results = heavyai::glob(file_path);
77  for (const auto& path : glob_results) {
78  if (recurse && boost::filesystem::is_directory(path)) {
79  auto expanded_paths = glob_local_recursive_files(path, true);
80  file_paths.insert(file_paths.end(), expanded_paths.begin(), expanded_paths.end());
81  } else {
82  file_paths.emplace_back(path);
83  }
84  }
85  if (file_paths.empty()) {
86  throw_file_not_found(file_path);
87  }
88  }
89  return file_paths;
90 }
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 92 of file file_path_util.cpp.

References shared::throw_no_filter_match().

Referenced by shared::local_glob_filter_sort_files().

93  {
94  boost::regex regex_pattern(pattern);
95  std::vector<std::string> matched_file_paths;
96  for (const auto& path : file_paths) {
97  if (boost::regex_match(path, regex_pattern)) {
98  matched_file_paths.emplace_back(path);
99  }
100  }
101  if (matched_file_paths.empty()) {
102  throw_no_filter_match(pattern);
103  }
104  return matched_file_paths;
105 }
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: