diff options
author | Adam <Adam@anope.org> | 2010-06-21 00:02:57 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2010-06-21 00:02:57 -0400 |
commit | 16854ae7932aca4e603e9db5ba18ebf33fd24ca9 (patch) | |
tree | d038ac4c9359c5a01cf1901563d6f7c8110ea4f7 /src | |
parent | 17040c088a00a83094359382b9add202e3749db7 (diff) |
Fixed a few Windows problems with cleaning out the runtime directory
Diffstat (limited to 'src')
-rw-r--r-- | src/module.cpp | 2 | ||||
-rw-r--r-- | src/modulemanager.cpp | 30 | ||||
-rw-r--r-- | src/modules.cpp | 32 |
3 files changed, 32 insertions, 32 deletions
diff --git a/src/module.cpp b/src/module.cpp index 7f9e7fd0d..0556abc4e 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -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); diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp index 878c041dd..9c646c4a8 100644 --- a/src/modulemanager.cpp +++ b/src/modulemanager.cpp @@ -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) diff --git a/src/modules.cpp b/src/modules.cpp index cf5fd245f..9ca850b57 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -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"; } |