75 using namespace boost::program_options;
76 using std::placeholders::_1;
78 static char const*
const kPathsOpt =
"paths";
79 static char const*
const kPathsCommandOpt =
"paths,p";
82 static char const*
const kHelpOpt =
"help";
86 descString +=
" [options] [[--";
87 descString += kPathsOpt;
88 descString +=
"] path [path]] \nAllowed options";
89 options_description desc(descString);
92 if(!defaultDirList.empty()) {
93 defaultDir = defaultDirList[0];
97 (kPathsCommandOpt,
value<std::vector<std::string> >()->default_value(
98 std::vector<std::string>(1, defaultDir))
99 ,
"a directory or a list of files to scan")
103 positional_options_description
p;
104 p.add(kPathsOpt, -1);
110 }
catch(
error const& iException) {
127 int returnValue = EXIT_SUCCESS;
130 std::vector<std::string> requestedPaths(vm[kPathsOpt].as<std::vector<std::string> >());
134 std::vector<std::string>
files;
135 bool removeMissingFiles =
false;
136 if(boost::filesystem::is_directory(
directory)) {
137 if (requestedPaths.size() > 1) {
138 std::cerr <<
"if a directory is given then only one argument is allowed" << std::endl;
143 removeMissingFiles =
true;
146 boost::filesystem::directory_iterator
end;
151 std::time_t cacheLastChange(0);
152 if(exists(cacheFile)) {
153 cacheLastChange = last_write_time(cacheFile);
159 path shortName(
file->path().filename());
163 if (stringName.size() < kPluginPrefix.size()) {
166 if(stringName.substr(0, kPluginPrefix.size()) != kPluginPrefix) {
170 if(last_write_time(
filename) > cacheLastChange) {
171 files.push_back(stringName);
177 for(std::vector<std::string>::iterator it = requestedPaths.begin(), itEnd = requestedPaths.end();
181 std::cerr <<
"the file '" <<
f.string() <<
"' does not exist" << std::endl;
184 if (is_directory(
f)) {
185 std::cerr <<
"either one directory or a list of files are allowed as arguments" << std::endl;
189 std::cerr <<
"all files must have be in the same directory (" <<
directory.string() <<
")\n"
190 " the file " <<
f.string() <<
" does not." << std::endl;
192 #if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 47
193 files.push_back(
f.filename().string());
195 files.push_back(
f.leaf());
203 CacheParser::LoadableToPlugins old;
204 if(exists(cacheFile)) {
205 std::ifstream cf(cacheFile.string().c_str());
207 cms::Exception(
"FailedToOpen") <<
"unable to open file '" << cacheFile.string() <<
"' for reading even though it is present.\n"
208 "Please check permissions on the file.";
217 pfm->
newFactory_.connect(std::bind(std::mem_fn(&Listener::newFactory), &listener, _1));
218 edm::for_all(*pfm, std::bind(std::mem_fn(&Listener::newFactory), &listener, _1));
222 std::string temporaryFilename = (cacheFile.string() +
".tmp");
223 std::ofstream cf(temporaryFilename.c_str());
226 << temporaryFilename <<
"' for writing.\n"
227 "Please check permissions on the file.";
235 CacheParser::LoadableToPlugins ltp;
236 pid_t worker = fork();
243 while (ci && fi != fe)
246 loadableFile /= (files[fi]);
247 listener.nameAndTypes_.clear();
255 ltp[files[fi]] = listener.nameAndTypes_;
258 if(iException.
category() ==
"PluginLibraryLoadError") {
259 std::cerr <<
"Caught exception " << iException.
what() <<
" will ignore " << files[fi] <<
" and continue." << std::endl;
265 std::cerr <<
"Caught exception " << iException.what() << std::endl;
279 waitpid(worker, &status, 0);
280 if (WIFEXITED(status) ==
true && status != 0)
282 std::cerr <<
"Error while processing." << std::endl;
291 CacheParser::LoadableToPlugins ltp;
292 std::ifstream icf(temporaryFilename.c_str());
294 cms::Exception(
"FailedToOpen") <<
"unable to open file '" << temporaryFilename.c_str() <<
"' for reading even though it is present.\n"
295 "Please check permissions on the file.";
299 for (CacheParser::LoadableToPlugins::iterator itFile = ltp.begin() ;
300 itFile != ltp.end() ;
303 old[itFile->first] = itFile->second;
308 if(removeMissingFiles) {
309 for(CacheParser::LoadableToPlugins::iterator itFile = old.begin();
313 loadableFile /= (itFile->first);
314 if(not exists(loadableFile)) {
315 std::cout <<
"removing file '" << temporaryFilename.c_str() <<
"'" << std::endl;
316 CacheParser::LoadableToPlugins::iterator itToItemBeingRemoved = itFile;
319 old.erase(itToItemBeingRemoved);
328 std::ofstream fcf(temporaryFilename.c_str());
330 cms::Exception(
"FailedToOpen") <<
"unable to open file '" << temporaryFilename.c_str() <<
"' for writing.\n"
331 "Please check permissions on the file.";
334 rename(temporaryFilename.c_str(), cacheFile.string().c_str());
336 std::cerr <<
"Caught exception " << iException.what() << std::endl;
337 returnValue = EXIT_FAILURE;
342 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
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()