1
0
mirror of https://github.com/anope/anope.git synced 2026-06-30 05:36:38 +02:00

Fixed a few Windows problems with cleaning out the runtime directory

This commit is contained in:
Adam
2010-06-21 00:02:57 -04:00
parent 17040c088a
commit 16854ae793
3 changed files with 32 additions and 32 deletions
-2
View File
@@ -36,8 +36,6 @@ Module::~Module()
for (i = 0; i < NUM_LANGS; ++i)
this->DeleteLanguage(i);
remove(this->filename.c_str());
/* Clear any active callbacks this module has */
ModuleManager::ClearCallBacks(this);
+17 -13
View File
@@ -17,9 +17,7 @@ void ModuleManager::LoadModuleList(std::list<std::string> &ModuleList)
{
for (std::list<std::string>::iterator it = ModuleList.begin(), it_end = ModuleList.end(); it != it_end; ++it)
{
Module *m = FindModule(*it);
if (!m)
ModuleManager::LoadModule(*it, NULL);
ModuleManager::LoadModule(*it, NULL);
}
}
@@ -27,9 +25,7 @@ void ModuleManager::LoadModuleList(std::list<ci::string> &ModuleList)
{
for (std::list<ci::string>::iterator it = ModuleList.begin(), it_end = ModuleList.end(); it != it_end; ++it)
{
Module *m = FindModule(*it);
if (!m)
ModuleManager::LoadModule(*it, NULL);
ModuleManager::LoadModule(*it, NULL);
}
}
@@ -61,11 +57,13 @@ static int moduleCopyFile(const char *name, const char *output)
#ifndef _WIN32
if ((srcfp = mkstemp(const_cast<char *>(output))) == -1)
return MOD_ERR_FILE_IO;
#else
if (!mktemp(const_cast<char *>(output)))
return MOD_ERR_FILE_IO;
#endif
{
fclose(source);
return MOD_ERR_FILE_IO;
}
Alog(LOG_DEBUG) << "Runtime module location: " << output;
@@ -74,7 +72,10 @@ static int moduleCopyFile(const char *name, const char *output)
#else
if (!(target = fopen(output, "wb")))
#endif
{
fclose(source);
return MOD_ERR_FILE_IO;
}
while ((ch = fgetc(source)) != EOF)
fputc(ch, target);
fclose(source);
@@ -281,15 +282,15 @@ int ModuleManager::UnloadModule(Module *m, User *u)
void ModuleManager::DeleteModule(Module *m)
{
if (!m || !m->handle)
return;
const char *err;
void (*destroy_func)(Module *m);
ano_module_t handle;
if (!m || !m->handle) /* check m is least possibly valid */
return;
DetachAll(m);
handle = m->handle;
ano_module_t handle = m->handle;
std::string filename = m->filename;
ano_modclearerr();
destroy_func = function_cast<void (*)(Module *)>(dlsym(m->handle, "AnopeFini"));
@@ -306,6 +307,9 @@ void ModuleManager::DeleteModule(Module *m)
if (dlclose(handle))
Alog() << dlerror();
}
if (!filename.empty())
DeleteFile(filename.c_str());
}
bool ModuleManager::Attach(Implementation i, Module *mod)
+15 -17
View File
@@ -346,16 +346,6 @@ void Module::DeleteLanguage(int langNumber)
void ModuleRunTimeDirCleanUp()
{
#ifndef _WIN32
DIR *dirp;
struct dirent *dp;
#else
BOOL fFinished;
HANDLE hList;
TCHAR szDir[MAX_PATH + 1];
WIN32_FIND_DATA FileData;
char buffer[_MAX_PATH];
#endif
char dirbuf[BUFSIZE];
char filebuf[BUFSIZE];
@@ -364,9 +354,12 @@ void ModuleRunTimeDirCleanUp()
Alog(LOG_DEBUG) << "Cleaning out Module run time directory (" << dirbuf << ") - this may take a moment please wait";
#ifndef _WIN32
DIR *dirp;
struct dirent *dp;
if (!(dirp = opendir(dirbuf)))
{
Alog(LOG_DEBUG) << "cannot open directory (" << dirbuf << ")";
Alog(LOG_DEBUG) << "Cannot open directory (" << dirbuf << ")";
return;
}
while ((dp = readdir(dirp)))
@@ -376,14 +369,16 @@ void ModuleRunTimeDirCleanUp()
if (!stricmp(dp->d_name, ".") || !stricmp(dp->d_name, ".."))
continue;
snprintf(filebuf, BUFSIZE, "%s/%s", dirbuf, dp->d_name);
unlink(filebuf);
DeleteFile(filebuf);
}
closedir(dirp);
#else
/* Get the current working directory: */
if (!_getcwd(buffer, _MAX_PATH))
Alog(LOG_DEBUG) << "Unable to set Current working directory";
snprintf(szDir, sizeof(szDir), "%s\\%s\\*", buffer, dirbuf);
BOOL fFinished;
HANDLE hList;
TCHAR szDir[MAX_PATH + 1];
WIN32_FIND_DATA FileData;
snprintf(szDir, sizeof(szDir), "%s/*", dirbuf);
hList = FindFirstFile(szDir, &FileData);
if (hList != INVALID_HANDLE_VALUE)
@@ -394,7 +389,8 @@ void ModuleRunTimeDirCleanUp()
if (!(FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
snprintf(filebuf, BUFSIZE, "%s/%s", dirbuf, FileData.cFileName);
DeleteFile(filebuf);
if (!DeleteFile(filebuf))
Alog(LOG_DEBUG) << "Error deleting file " << filebuf << " - GetLastError() reports " << dlerror();
}
if (!FindNextFile(hList, &FileData))
{
@@ -405,7 +401,9 @@ void ModuleRunTimeDirCleanUp()
}
else
Alog(LOG_DEBUG) << "Invalid File Handle. GetLastError() reports "<< static_cast<int>(GetLastError());
FindClose(hList);
#endif
Alog(LOG_DEBUG) << "Module run time directory has been cleaned out";
}