11 #include <boost/filesystem/operations.hpp> 12 #include <boost/program_options.hpp> 39 #define PER_PROCESS_DSO 20 40 #elif defined(__aarch64__) 41 #define PER_PROCESS_DSO 10 43 #define PER_PROCESS_DSO 2000 47 ostream& operator<<(std::ostream& o, vector<std::string>
const& iValue) {
50 for(std::vector<std::string>::const_iterator it = iValue.begin(), itEnd = iValue.end();
65 using std::placeholders::_1;
66 using std::placeholders::_2;
67 iBase->
newPluginAdded_.connect(std::bind(std::mem_fn(&Listener::newPlugin),
this, _1, _2));
70 nameAndTypes_.push_back(NameAndType(iInfo.
name_, iCategory));
73 NameAndTypes nameAndTypes_;
77 using namespace boost::program_options;
78 using std::placeholders::_1;
80 static char const*
const kPathsOpt =
"paths";
81 static char const*
const kPathsCommandOpt =
"paths,p";
84 static char const*
const kHelpOpt =
"help";
88 descString +=
" [options] [[--";
89 descString += kPathsOpt;
90 descString +=
"] path [path]] \nAllowed options";
91 options_description desc(descString);
94 if(!defaultDirList.empty()) {
95 defaultDir = defaultDirList[0];
99 (kPathsCommandOpt,
value<std::vector<std::string> >()->default_value(
100 std::vector<std::string>(1, defaultDir))
101 ,
"a directory or a list of files to scan")
105 positional_options_description
p;
106 p.add(kPathsOpt, -1);
110 store(command_line_parser(argc, argv).
options(desc).positional(p).
run(), vm);
112 }
catch(
error const& iException) {
117 if(vm.count(kHelpOpt)) {
129 int returnValue = EXIT_SUCCESS;
132 std::vector<std::string> requestedPaths(vm[kPathsOpt].as<std::vector<std::string> >());
136 std::vector<std::string>
files;
137 bool removeMissingFiles =
false;
138 if(boost::filesystem::is_directory(directory)) {
139 if (requestedPaths.size() > 1) {
140 std::cerr <<
"if a directory is given then only one argument is allowed" << std::endl;
145 removeMissingFiles =
true;
147 boost::filesystem::directory_iterator
file (directory);
148 boost::filesystem::directory_iterator
end;
150 path cacheFile(directory);
153 std::time_t cacheLastChange(0);
154 if(exists(cacheFile)) {
155 cacheLastChange = last_write_time(cacheFile);
161 path shortName(file->path().filename());
162 const std::string& stringName = shortName.string();
165 if (stringName.size() < kPluginPrefix.size()) {
168 if(stringName.substr(0, kPluginPrefix.size()) != kPluginPrefix) {
172 if(last_write_time(filename) > cacheLastChange) {
173 files.push_back(stringName);
178 directory = directory.branch_path();
179 for(std::vector<std::string>::iterator it = requestedPaths.begin(), itEnd = requestedPaths.end();
183 std::cerr <<
"the file '" << f.string() <<
"' does not exist" << std::endl;
186 if (is_directory(f)) {
187 std::cerr <<
"either one directory or a list of files are allowed as arguments" << std::endl;
190 if(directory != f.branch_path()) {
191 std::cerr <<
"all files must have be in the same directory (" << directory.string() <<
")\n" 192 " the file " << f.string() <<
" does not." << std::endl;
194 #if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 47 195 files.push_back(f.filename().string());
197 files.push_back(f.leaf());
202 path cacheFile(directory);
206 if(exists(cacheFile)) {
207 std::ifstream cf(cacheFile.string().c_str());
209 cms::Exception(
"FailedToOpen") <<
"unable to open file '" << cacheFile.string() <<
"' for reading even though it is present.\n" 210 "Please check permissions on the file.";
219 pfm->
newFactory_.connect(std::bind(std::mem_fn(&Listener::newFactory), &listener, _1));
220 edm::for_all(*pfm, std::bind(std::mem_fn(&Listener::newFactory), &listener, _1));
224 std::string temporaryFilename = (cacheFile.string() +
".tmp");
225 std::ofstream cf(temporaryFilename.c_str());
228 << temporaryFilename <<
"' for writing.\n" 229 "Please check permissions on the file.";
233 std::sort(files.begin(), files.end());
238 pid_t worker = fork();
245 while (ci && fi != fe)
247 path loadableFile(directory);
248 loadableFile /= (files[fi]);
249 listener.nameAndTypes_.clear();
257 ltp[files[fi]] = listener.nameAndTypes_;
260 if(iException.
category() ==
"PluginLibraryLoadError") {
261 std::cerr <<
"Caught exception " << iException.
what() <<
" will ignore " << files[fi] <<
" and continue." << std::endl;
267 std::cerr <<
"Caught exception " << iException.what() << std::endl;
281 waitpid(worker, &status, 0);
282 if (WIFEXITED(status) ==
true && status != 0)
284 std::cerr <<
"Error while processing." << std::endl;
294 std::ifstream icf(temporaryFilename.c_str());
296 cms::Exception(
"FailedToOpen") <<
"unable to open file '" << temporaryFilename.c_str() <<
"' for reading even though it is present.\n" 297 "Please check permissions on the file.";
301 for (CacheParser::LoadableToPlugins::iterator itFile = ltp.begin() ;
302 itFile != ltp.end() ;
305 old[itFile->first] = itFile->second;
310 if(removeMissingFiles) {
311 for(CacheParser::LoadableToPlugins::iterator itFile = old.begin();
314 path loadableFile(directory);
315 loadableFile /= (itFile->first);
316 if(not exists(loadableFile)) {
317 std::cout <<
"removing file '" << temporaryFilename.c_str() <<
"'" << std::endl;
318 CacheParser::LoadableToPlugins::iterator itToItemBeingRemoved = itFile;
321 old.erase(itToItemBeingRemoved);
330 std::ofstream fcf(temporaryFilename.c_str());
332 cms::Exception(
"FailedToOpen") <<
"unable to open file '" << temporaryFilename.c_str() <<
"' for writing.\n" 333 "Please check permissions on the file.";
336 rename(temporaryFilename.c_str(), cacheFile.string().c_str());
338 std::cerr <<
"Caught exception " << iException.what() << std::endl;
339 returnValue = EXIT_FAILURE;
344 std::cerr << iException.what() << std::endl;
const boost::filesystem::path & cachefileName()
std::pair< std::string, std::string > NameAndType
int main(int argc, char **argv)
bool tryToFind(const SharedLibrary &iLoadable)
Check to see if any capabilities are in the file, returns 'true' if found.
std::string const & category() const
char const * what() const override
const std::string & pluginPrefix()
Func for_all(ForwardSequence &s, Func f)
wrapper for std::for_each
std::map< boost::filesystem::path, NameAndTypes > LoadableToPlugins
PluginManager::Config config()
edm::signalslot::Signal< void(const PluginFactoryBase *)> newFactory_
std::vector< NameAndType > NameAndTypes
edm::signalslot::Signal< void(const std::string &, const PluginInfo &)> newPluginAdded_
signal containing plugin category, and plugin info for newly added plugin
static PluginCapabilities * get()
static void write(const CategoryToInfos &, std::ostream &)
static const char *const kHelpCommandOpt
Config & searchPath(const SearchPath &iPath)
static void read(std::istream &, const boost::filesystem::path &iDirectory, CategoryToInfos &oOut)
static const char *const kHelpOpt
static PluginFactoryManager * get()