11 #include <boost/filesystem/operations.hpp> 12 #include <boost/program_options.hpp> 39 #define PER_PROCESS_DSO 20 41 #define PER_PROCESS_DSO 2000 45 ostream& operator<<(std::ostream& o, vector<std::string>
const& iValue) {
48 for(std::vector<std::string>::const_iterator it = iValue.begin(), itEnd = iValue.end();
63 using std::placeholders::_1;
64 using std::placeholders::_2;
65 iBase->
newPluginAdded_.connect(std::bind(std::mem_fn(&Listener::newPlugin),
this, _1, _2));
68 nameAndTypes_.push_back(NameAndType(iInfo.
name_, iCategory));
71 NameAndTypes nameAndTypes_;
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);
108 store(command_line_parser(argc, argv).
options(desc).positional(p).
run(), vm);
110 }
catch(
error const& iException) {
115 if(vm.count(kHelpOpt)) {
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;
145 boost::filesystem::directory_iterator
file (directory);
146 boost::filesystem::directory_iterator
end;
148 path cacheFile(directory);
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);
176 directory = directory.branch_path();
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;
188 if(directory != f.branch_path()) {
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());
200 path cacheFile(directory);
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.";
231 std::sort(files.begin(), files.end());
236 pid_t worker = fork();
243 while (ci && fi != fe)
245 path loadableFile(directory);
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;
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();
312 path loadableFile(directory);
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;
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()