74 using namespace boost::program_options;
76 static char const*
const kPathsOpt =
"paths";
77 static char const*
const kPathsCommandOpt =
"paths,p";
80 static char const*
const kHelpOpt =
"help";
84 descString +=
" [options] [[--";
85 descString += kPathsOpt;
86 descString +=
"] path [path]] \nAllowed options";
87 options_description desc(descString);
90 if(!defaultDirList.empty()) {
91 defaultDir = defaultDirList[0];
95 (kPathsCommandOpt,
value<std::vector<std::string> >()->default_value(
96 std::vector<std::string>(1, defaultDir))
97 ,
"a directory or a list of files to scan")
101 positional_options_description
p;
102 p.add(kPathsOpt, -1);
108 }
catch(
error const& iException) {
125 int returnValue = EXIT_SUCCESS;
128 std::vector<std::string> requestedPaths(vm[kPathsOpt].as<std::vector<std::string> >());
132 std::vector<std::string>
files;
133 bool removeMissingFiles =
false;
134 if(boost::filesystem::is_directory(
directory)) {
135 if (requestedPaths.size() > 1) {
136 std::cerr <<
"if a directory is given then only one argument is allowed" << std::endl;
141 removeMissingFiles =
true;
144 boost::filesystem::directory_iterator
end;
149 std::time_t cacheLastChange(0);
150 if(exists(cacheFile)) {
151 cacheLastChange = last_write_time(cacheFile);
157 path shortName(
file->path().filename());
161 if (stringName.size() < kPluginPrefix.size()) {
164 if(stringName.substr(0, kPluginPrefix.size()) != kPluginPrefix) {
168 if(last_write_time(
filename) > cacheLastChange) {
169 files.push_back(stringName);
175 for(std::vector<std::string>::iterator it = requestedPaths.begin(), itEnd = requestedPaths.end();
179 std::cerr <<
"the file '" <<
f.string() <<
"' does not exist" << std::endl;
182 if (is_directory(
f)) {
183 std::cerr <<
"either one directory or a list of files are allowed as arguments" << std::endl;
187 std::cerr <<
"all files must have be in the same directory (" <<
directory.string() <<
")\n"
188 " the file " <<
f.string() <<
" does not." << std::endl;
190 #if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 47
191 files.push_back(
f.filename().string());
193 files.push_back(
f.leaf());
201 CacheParser::LoadableToPlugins old;
202 if(exists(cacheFile)) {
203 std::ifstream cf(cacheFile.string().c_str());
205 cms::Exception(
"FailedToOpen") <<
"unable to open file '" << cacheFile.string() <<
"' for reading even though it is present.\n"
206 "Please check permissions on the file.";
215 pfm->
newFactory_.connect(boost::bind(boost::mem_fn(&Listener::newFactory), &listener, _1));
216 edm::for_all(*pfm, boost::bind(boost::mem_fn(&Listener::newFactory), &listener, _1));
220 std::string temporaryFilename = (cacheFile.string() +
".tmp");
221 std::ofstream cf(temporaryFilename.c_str());
224 << temporaryFilename <<
"' for writing.\n"
225 "Please check permissions on the file.";
233 CacheParser::LoadableToPlugins ltp;
234 pid_t worker = fork();
241 while (ci && fi != fe)
244 loadableFile /= (files[fi]);
245 listener.nameAndTypes_.clear();
253 ltp[files[fi]] = listener.nameAndTypes_;
256 if(iException.
category() ==
"PluginLibraryLoadError") {
257 std::cerr <<
"Caught exception " << iException.
what() <<
" will ignore " << files[fi] <<
" and continue." << std::endl;
263 std::cerr <<
"Caught exception " << iException.what() << std::endl;
277 waitpid(worker, &status, 0);
278 if (WIFEXITED(status) ==
true && status != 0)
280 std::cerr <<
"Error while processing." << std::endl;
289 CacheParser::LoadableToPlugins ltp;
290 std::ifstream icf(temporaryFilename.c_str());
292 cms::Exception(
"FailedToOpen") <<
"unable to open file '" << temporaryFilename.c_str() <<
"' for reading even though it is present.\n"
293 "Please check permissions on the file.";
297 for (CacheParser::LoadableToPlugins::iterator itFile = ltp.begin() ;
298 itFile != ltp.end() ;
301 old[itFile->first] = itFile->second;
306 if(removeMissingFiles) {
307 for(CacheParser::LoadableToPlugins::iterator itFile = old.begin();
311 loadableFile /= (itFile->first);
312 if(not exists(loadableFile)) {
313 std::cout <<
"removing file '" << temporaryFilename.c_str() <<
"'" << std::endl;
314 CacheParser::LoadableToPlugins::iterator itToItemBeingRemoved = itFile;
317 old.erase(itToItemBeingRemoved);
326 std::ofstream fcf(temporaryFilename.c_str());
328 cms::Exception(
"FailedToOpen") <<
"unable to open file '" << temporaryFilename.c_str() <<
"' for writing.\n"
329 "Please check permissions on the file.";
332 rename(temporaryFilename.c_str(), cacheFile.string().c_str());
334 std::cerr <<
"Caught exception " << iException.what() << std::endl;
335 returnValue = EXIT_FAILURE;
340 std::cerr << iException.what() << std::endl;
virtual char const * what() const
const boost::filesystem::path & cachefileName()
std::string const & category() const
const std::string & pluginPrefix()
Func for_all(ForwardSequence &s, Func f)
wrapper for std::for_each
tuple path
else: Piece not in the list, fine.
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()