Lowercase windows/mac paths to avoid plugin duplicate loadings (Bug 6491) (#709)

This commit is contained in:
Michael Flaherty 2017-10-28 04:44:25 -07:00 committed by Asher Baker
parent c3b25e54f8
commit 90ddc16a4b

View File

@ -46,6 +46,7 @@
#include "frame_tasks.h" #include "frame_tasks.h"
#include <amtl/am-string.h> #include <amtl/am-string.h>
#include <amtl/am-linkedlist.h> #include <amtl/am-linkedlist.h>
#include <amtl/am-uniqueptr.h>
#include <bridge/include/IVEngineServerBridge.h> #include <bridge/include/IVEngineServerBridge.h>
#include <bridge/include/CoreProvider.h> #include <bridge/include/CoreProvider.h>
@ -932,16 +933,38 @@ void CPluginManager::LoadPluginsFromDir(const char *basedir, const char *localpa
libsys->CloseDirectory(dir); libsys->CloseDirectory(dir);
} }
#if defined PLATFORM_WINDOWS || defined PLATFORM_APPLE
char *strdup_tolower(const char *input)
{
char *str = strdup(input);
for (char *c = str; *c; c++)
{
*c = tolower((unsigned char)*c);
}
return str;
}
#endif
LoadRes CPluginManager::LoadPlugin(CPlugin **aResult, const char *path, bool debug, PluginType type) LoadRes CPluginManager::LoadPlugin(CPlugin **aResult, const char *path, bool debug, PluginType type)
{ {
if (m_LoadingLocked) if (m_LoadingLocked)
return LoadRes_NeverLoad; return LoadRes_NeverLoad;
/* For windows & mac, we convert the path to lower-case in order to avoid duplicate plugin loading */
#if defined PLATFORM_WINDOWS || defined PLATFORM_APPLE
ke::UniquePtr<char> finalPath = ke::UniquePtr<char>(strdup_tolower(path));
#else
ke::UniquePtr<char> finalPath = ke::UniquePtr<char>(strdup(path));
#endif
/** /**
* Does this plugin already exist? * Does this plugin already exist?
*/ */
CPlugin *pPlugin; CPlugin *pPlugin;
if (m_LoadLookup.retrieve(path, &pPlugin)) if (m_LoadLookup.retrieve(finalPath.get(), &pPlugin))
{ {
/* Check to see if we should try reloading it */ /* Check to see if we should try reloading it */
if (pPlugin->GetStatus() == Plugin_BadLoad if (pPlugin->GetStatus() == Plugin_BadLoad
@ -954,11 +977,12 @@ LoadRes CPluginManager::LoadPlugin(CPlugin **aResult, const char *path, bool deb
{ {
if (aResult) if (aResult)
*aResult = pPlugin; *aResult = pPlugin;
return LoadRes_AlreadyLoaded; return LoadRes_AlreadyLoaded;
} }
} }
CPlugin *plugin = CompileAndPrep(path); CPlugin *plugin = CompileAndPrep(finalPath.get());
// Assign our outparam so we can return early. It must be set. // Assign our outparam so we can return early. It must be set.
*aResult = plugin; *aResult = plugin;