Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b3d0e7f

Browse files
authored
Merge pull request #57 from linuxdeploy/fix-plugin-detection
Fix plugin detection
2 parents 786a24c + 1329317 commit b3d0e7f

File tree

1 file changed

+39
-20
lines changed

1 file changed

+39
-20
lines changed

src/plugin/plugin.cpp

+39-20
Original file line numberDiff line numberDiff line change
@@ -64,30 +64,49 @@ namespace linuxdeploy {
6464

6565
ldLog() << LD_DEBUG << "Searching for plugins in directory" << dir << std::endl;
6666

67+
bool extendedDebugLoggingEnabled = (getenv("DEBUG_PLUGIN_DETECTION") != nullptr);
68+
6769
for (bf::directory_iterator i(dir); i != bf::directory_iterator(); ++i) {
70+
// must be a file, and not a directory
71+
if (bf::is_directory(bf::absolute(*i))) {
72+
if (extendedDebugLoggingEnabled)
73+
ldLog() << LD_DEBUG << "Entry is a directory, skipping:" << i->path() << std::endl;
74+
75+
continue;
76+
}
77+
6878
// file must be executable...
69-
if (bf::status(*i).permissions() & (bf::owner_exe | bf::group_exe | bf::others_exe)) {
70-
// ... and filename must match regular expression
71-
boost::cmatch res;
72-
if (boost::regex_match(i->path().filename().string().c_str(), res, PLUGIN_EXPR)) {
73-
try {
74-
auto name = res[1].str();
75-
auto* plugin = createPluginInstance(*i);
76-
if (plugin == nullptr) {
77-
ldLog() << LD_DEBUG << "Failed to create instance for plugin" << i->path();
78-
} else {
79-
ldLog() << LD_DEBUG << "Found plugin '" << LD_NO_SPACE << name << LD_NO_SPACE << "':" << plugin->path() << std::endl;
80-
81-
if (foundPlugins.find(name) != foundPlugins.end()) {
82-
ldLog() << LD_DEBUG << "Already found" << name << "plugin in" << foundPlugins[name]->path() << std::endl;
83-
} else {
84-
foundPlugins[name] = plugin;
85-
}
86-
}
87-
} catch (const PluginError& e) {
88-
ldLog() << LD_WARNING << "Could not load plugin" << i->path() << LD_NO_SPACE << ": " << e.what();
79+
if (!(bf::status(*i).permissions() & (bf::owner_exe | bf::group_exe | bf::others_exe))) {
80+
if (extendedDebugLoggingEnabled)
81+
ldLog() << LD_DEBUG << "File/symlink is not executable, skipping:" << i->path() << std::endl;
82+
83+
continue;
84+
}
85+
86+
// entry name must match regular expression
87+
boost::cmatch res;
88+
89+
if (!boost::regex_match(i->path().filename().string().c_str(), res, PLUGIN_EXPR)) {
90+
ldLog() << LD_DEBUG << "Doesn't match plugin regex, skipping:" << i->path() << std::endl;
91+
continue;
92+
}
93+
94+
try {
95+
auto name = res[1].str();
96+
auto* plugin = createPluginInstance(*i);
97+
if (plugin == nullptr) {
98+
ldLog() << LD_DEBUG << "Failed to create instance for plugin" << i->path() << std::endl;;
99+
} else {
100+
ldLog() << LD_DEBUG << "Found plugin '" << LD_NO_SPACE << name << LD_NO_SPACE << "':" << plugin->path() << std::endl;
101+
102+
if (foundPlugins.find(name) != foundPlugins.end()) {
103+
ldLog() << LD_DEBUG << "Already found" << name << "plugin in" << foundPlugins[name]->path() << std::endl;
104+
} else {
105+
foundPlugins[name] = plugin;
89106
}
90107
}
108+
} catch (const PluginError& e) {
109+
ldLog() << LD_WARNING << "Could not load plugin" << i->path() << LD_NO_SPACE << ": " << e.what();
91110
}
92111
}
93112
}

0 commit comments

Comments
 (0)