1 #include "GaudiKernel/PathResolver.h"
2 #include "GaudiKernel/System.h"
8 #pragma warning(disable:4996)
16 #include <boost/algorithm/string/split.hpp>
17 #include <boost/algorithm/string/classification.hpp>
18 #include <boost/filesystem.hpp>
20 namespace bf = boost::filesystem;
24 static const char* path_separator =
",;";
26 static const char* path_separator =
",:";
48 PR_find(
const bf::path&
file,
const string& search_list,
49 PR_file_type file_type, PathResolver::SearchType search_type,
58 ( file_type ==
PR_directory && is_directory( file ) ) ) {
59 result = bf::system_complete(file).string();
62 }
catch (bf::filesystem_error ) {
70 ( file_type ==
PR_directory && is_directory( local ) ) ) {
71 result = bf::system_complete(file).string();
74 }
catch (bf::filesystem_error ) {
80 split(spv, search_list, boost::is_any_of( path_separator), boost::token_compress_on);
81 for (
const auto& itr : spv ) {
88 result = bf::system_complete(fp).string();
91 }
catch (bf::filesystem_error ) {
96 if (search_type == PathResolver::RecursiveSearch &&
99 bf::recursive_directory_iterator end_itr;
101 for ( bf::recursive_directory_iterator ritr( itr );
102 ritr != end_itr; ++ritr) {
105 if (! is_directory(
bf::path(*ritr) ) ) {
continue; }
109 ( file_type ==
PR_directory && is_directory( fp2 ) ) ) {
110 result = bf::system_complete( fp2 ).string();
114 }
catch (bf::filesystem_error ) {
126 PathResolver::find_file(
const std::string& logical_file_name,
127 const std::string& search_path,
130 std::string path_list;
133 return (find_file_from_list (logical_file_name, path_list, search_type));
139 PathResolver::find_file_from_list (
const std::string& logical_file_name,
140 const std::string& search_list,
143 std::string result(
"");
165 string PathResolver::find_directory (
const std::string& logical_file_name,
166 const std::string& search_path,
169 std::string path_list;
172 return (find_directory_from_list (logical_file_name, path_list, search_type));
178 PathResolver::find_directory_from_list (
const std::string& logical_file_name,
179 const std::string& search_list,
184 if (!PR_find (logical_file_name, search_list,
PR_directory, search_type, result))
196 PathResolver::check_search_path (
const std::string& search_path)
198 std::string path_list;
200 return (EnvironmentVariableUndefined);
203 boost::split( spv, path_list, boost::is_any_of( path_separator ), boost::token_compress_on);
206 for (
const auto& itr : spv ) {
208 if (!is_directory(pp)) {
209 return (UnknownDirectory);
212 }
catch(bf::filesystem_error ) {
213 return (UnknownDirectory);
223 return PathResolver::find_file (logical_file_name,
"XMLPATH");
228 return PathResolver::find_file (logical_file_name,
"DATAPATH");
Note: OS specific details for environment resolution.
GAUDI_API std::string PathResolverFindXMLFile(const std::string &logical_file_name)
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
GAUDI_API std::string PathResolverFindDataFile(const std::string &logical_file_name)