summaryrefslogtreecommitdiff
path: root/src/modulemanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modulemanager.cpp')
-rw-r--r--src/modulemanager.cpp50
1 files changed, 20 insertions, 30 deletions
diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp
index f5f93a937..38ed130f7 100644
--- a/src/modulemanager.cpp
+++ b/src/modulemanager.cpp
@@ -15,11 +15,12 @@
#include <sys/types.h>
#include <sys/stat.h>
#ifndef _WIN32
-#include <dirent.h>
#include <sys/types.h>
#include <dlfcn.h>
#endif
+#include <filesystem>
+
std::list<Module *> ModuleManager::Modules;
std::vector<Module *> ModuleManager::EventHandlers[I_SIZE];
@@ -29,25 +30,18 @@ void ModuleManager::CleanupRuntimeDirectory()
Anope::string dirbuf = Anope::DataDir + "/runtime";
Log(LOG_DEBUG) << "Cleaning out Module run time directory (" << dirbuf << ") - this may take a moment, please wait";
-
- DIR *dirp = opendir(dirbuf.c_str());
- if (!dirp)
+ try
{
- Log(LOG_DEBUG) << "Cannot open directory (" << dirbuf << ")";
- return;
+ for (const auto &entry : std::filesystem::directory_iterator(dirbuf.str()))
+ {
+ if (entry.is_regular_file())
+ std::filesystem::remove(entry);
+ }
}
-
- for (dirent *dp; (dp = readdir(dirp));)
+ catch (const std::filesystem::filesystem_error &err)
{
- if (!dp->d_ino)
- continue;
- if (Anope::string(dp->d_name).equals_cs(".") || Anope::string(dp->d_name).equals_cs(".."))
- continue;
- Anope::string filebuf = dirbuf + "/" + dp->d_name;
- unlink(filebuf.c_str());
+ Log(LOG_DEBUG) << "Cannot open directory (" << dirbuf << "): " << err.what();
}
-
- closedir(dirp);
}
/**
@@ -273,8 +267,8 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u)
Log(LOG_DEBUG) << "Module " << modname << " loaded.";
/* Attach module to all events */
- for (unsigned i = 0; i < I_SIZE; ++i)
- EventHandlers[i].push_back(m);
+ for (auto &mods : EventHandlers)
+ mods.push_back(m);
m->Prioritize();
@@ -313,10 +307,8 @@ ModuleReturn ModuleManager::UnloadModule(Module *m, User *u)
Module *ModuleManager::FindModule(const Anope::string &name)
{
- for (std::list<Module *>::const_iterator it = Modules.begin(), it_end = Modules.end(); it != it_end; ++it)
+ for (auto *m : Modules)
{
- Module *m = *it;
-
if (m->name.equals_ci(name))
return m;
}
@@ -326,10 +318,8 @@ Module *ModuleManager::FindModule(const Anope::string &name)
Module *ModuleManager::FindFirstOf(ModType type)
{
- for (std::list<Module *>::const_iterator it = Modules.begin(), it_end = Modules.end(); it != it_end; ++it)
+ for (auto *m : Modules)
{
- Module *m = *it;
-
if (m->type & type)
return m;
}
@@ -395,9 +385,8 @@ ModuleReturn ModuleManager::DeleteModule(Module *m)
void ModuleManager::DetachAll(Module *mod)
{
- for (unsigned i = 0; i < I_SIZE; ++i)
+ for (auto &mods : EventHandlers)
{
- std::vector<Module *> &mods = EventHandlers[i];
std::vector<Module *>::iterator it2 = std::find(mods.begin(), mods.end(), mod);
if (it2 != mods.end())
mods.erase(it2);
@@ -510,16 +499,17 @@ void ModuleManager::UnloadAll()
{
std::vector<Anope::string> modules;
for (size_t i = 1, j = 0; i != MT_END; j |= i, i <<= 1)
- for (std::list<Module *>::iterator it = Modules.begin(), it_end = Modules.end(); it != it_end; ++it)
+ {
+ for (auto *m : Modules)
{
- Module *m = *it;
if ((m->type & j) == m->type)
modules.push_back(m->name);
}
+ }
- for (unsigned i = 0; i < modules.size(); ++i)
+ for (auto &module : modules)
{
- Module *m = FindModule(modules[i]);
+ Module *m = FindModule(module);
if (m != NULL)
UnloadModule(m, NULL);
}