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);
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;
148 boost::filesystem::directory_iterator
end;
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);
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;
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());
205 CacheParser::LoadableToPlugins old;
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.";
212 CacheParser::read(cf, old);
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());
237 CacheParser::LoadableToPlugins ltp;
238 pid_t worker = fork();
245 while (ci && fi != fe)
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;
293 CacheParser::LoadableToPlugins ltp;
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.";
299 CacheParser::read(icf, ltp);
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();
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::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
PluginManager::Config config()
edm::signalslot::Signal< void(const PluginFactoryBase *)> newFactory_
static const char *const kHelpCommandOpt
Config & searchPath(const SearchPath &iPath)
static const char *const kHelpOpt
T get(const Candidate &c)
static PluginFactoryManager * get()