11 #include "cetlib_except/exception.h" 25 string const exception_category{
"search_path"};
28 get_env_if_colon_present(
string const& arg)
32 return arg.find(
':') == string::npos ? arg :
string{};
39 cet::split(path_to_split,
':', back_inserter(dirs));
50 return get_dirs(env.empty() ? paths :
cet::getenv(env));
62 search_path::search_path(
string const& env_name_or_path)
63 : env_{get_env_if_colon_present(env_name_or_path)}
102 <<
"Can't find file \"" << filename <<
'"';
108 if (filename.empty())
113 for (
size_t k; (
k = fullpath.find(
"//")) != string::npos;) {
114 fullpath.erase(
k, 1);
131 unique_ptr<DIR, function<int(DIR*)>> dd(opendir(
dir.c_str()), closedir);
132 if (dd.get() ==
nullptr) {
141 auto entry = readdir(dd.get());
144 <<
"Failed to read directory \"" <<
dir 145 <<
"\"; error num = " <<
errno;
147 if (
entry ==
nullptr) {
151 if (regex_match(
entry->d_name, re)) {
152 out.push_back(
dir +
'/' +
entry->d_name);
163 std::ostringstream oss;
173 auto const sz = path.
size();
177 for (
size_t k{1};
k != sz; ++
k) {
178 os <<
":" << path[
k];
std::string to_string() const
std::vector< std::string > dirs_
std::ostream & operator<<(std::ostream &, map_vector_key const &)
path_tag_t const path_tag
int errno
Contains the last error code.
std::string getenv(std::string const &name)
std::size_t find_files(std::string const &filename_pattern, std::vector< std::string > &result) const
std::string const & operator[](std::size_t k) const
std::string find_file(std::string const &filename) const
search_path(std::string const &env_name_or_path)
bool file_exists(std::string const &qualified_filename)
void split(std::string const &s, char c, OutIter dest)
cet::coded_exception< error, detail::translate > exception