diff --git a/src/plugin/plugin.cpp b/src/plugin/plugin.cpp index 0defbf9c..4b34943b 100644 --- a/src/plugin/plugin.cpp +++ b/src/plugin/plugin.cpp @@ -64,30 +64,49 @@ namespace linuxdeploy { ldLog() << LD_DEBUG << "Searching for plugins in directory" << dir << std::endl; + bool extendedDebugLoggingEnabled = (getenv("DEBUG_PLUGIN_DETECTION") != nullptr); + for (bf::directory_iterator i(dir); i != bf::directory_iterator(); ++i) { + // must be a file, and not a directory + if (bf::is_directory(bf::absolute(*i))) { + if (extendedDebugLoggingEnabled) + ldLog() << LD_DEBUG << "Entry is a directory, skipping:" << i->path() << std::endl; + + continue; + } + // file must be executable... - if (bf::status(*i).permissions() & (bf::owner_exe | bf::group_exe | bf::others_exe)) { - // ... and filename must match regular expression - boost::cmatch res; - if (boost::regex_match(i->path().filename().string().c_str(), res, PLUGIN_EXPR)) { - try { - auto name = res[1].str(); - auto* plugin = createPluginInstance(*i); - if (plugin == nullptr) { - ldLog() << LD_DEBUG << "Failed to create instance for plugin" << i->path(); - } else { - ldLog() << LD_DEBUG << "Found plugin '" << LD_NO_SPACE << name << LD_NO_SPACE << "':" << plugin->path() << std::endl; - - if (foundPlugins.find(name) != foundPlugins.end()) { - ldLog() << LD_DEBUG << "Already found" << name << "plugin in" << foundPlugins[name]->path() << std::endl; - } else { - foundPlugins[name] = plugin; - } - } - } catch (const PluginError& e) { - ldLog() << LD_WARNING << "Could not load plugin" << i->path() << LD_NO_SPACE << ": " << e.what(); + if (!(bf::status(*i).permissions() & (bf::owner_exe | bf::group_exe | bf::others_exe))) { + if (extendedDebugLoggingEnabled) + ldLog() << LD_DEBUG << "File/symlink is not executable, skipping:" << i->path() << std::endl; + + continue; + } + + // entry name must match regular expression + boost::cmatch res; + + if (!boost::regex_match(i->path().filename().string().c_str(), res, PLUGIN_EXPR)) { + ldLog() << LD_DEBUG << "Doesn't match plugin regex, skipping:" << i->path() << std::endl; + continue; + } + + try { + auto name = res[1].str(); + auto* plugin = createPluginInstance(*i); + if (plugin == nullptr) { + ldLog() << LD_DEBUG << "Failed to create instance for plugin" << i->path() << std::endl;; + } else { + ldLog() << LD_DEBUG << "Found plugin '" << LD_NO_SPACE << name << LD_NO_SPACE << "':" << plugin->path() << std::endl; + + if (foundPlugins.find(name) != foundPlugins.end()) { + ldLog() << LD_DEBUG << "Already found" << name << "plugin in" << foundPlugins[name]->path() << std::endl; + } else { + foundPlugins[name] = plugin; } } + } catch (const PluginError& e) { + ldLog() << LD_WARNING << "Could not load plugin" << i->path() << LD_NO_SPACE << ": " << e.what(); } } }