X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/b48c66514f3b7040f5f1c62a05f0489f2ebd7741..beaf9ae26adc71c458f7eb3465d5ac3fa0bf9646:/projects/stargazer/plugins/store/files/file_store.cpp diff --git a/projects/stargazer/plugins/store/files/file_store.cpp b/projects/stargazer/plugins/store/files/file_store.cpp index 555020b7..5fadbd4d 100644 --- a/projects/stargazer/plugins/store/files/file_store.cpp +++ b/projects/stargazer/plugins/store/files/file_store.cpp @@ -47,10 +47,10 @@ #include "stg/user_ips.h" #include "stg/user_conf.h" #include "stg/user_stat.h" -#include "stg/stg_const.h" +#include "stg/const.h" #include "stg/blowfish.h" -#include "stg/stg_logger.h" -#include "stg/stg_locker.h" +#include "stg/logger.h" +#include "stg/locker.h" #include "file_store.h" #define DELETED_USERS_DIR "deleted_users" @@ -561,40 +561,62 @@ return 0; //----------------------------------------------------------------------------- int FILES_STORE::RemoveDir(const char * path) const { -vector fileList; +DIR * d = opendir(path); -GetFileList(&fileList, path, S_IFREG, ""); +if (!d) + { + errorStr = "failed to open dir. Message: '"; + errorStr += strerror(errno); + errorStr += "'"; + printfd(__FILE__, "FILE_STORE::RemoveDir() - Failed to open dir '%s': '%s'\n", path, strerror(errno)); + return -1; + } -for (unsigned i = 0; i < fileList.size(); i++) +dirent * entry; +while ((entry = readdir(d))) { - string file = path + string("/") + fileList[i]; - if (unlink(file.c_str())) + if (!(strcmp(entry->d_name, ".") && strcmp(entry->d_name, ".."))) + continue; + + string str = path; + str += "/" + string(entry->d_name); + + struct stat st; + if (stat(str.c_str(), &st)) + continue; + + if ((st.st_mode & S_IFREG)) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = "unlink failed. Message: '"; - errorStr += strerror(errno); - errorStr += "'"; - printfd(__FILE__, "FILES_STORE::RemoveDir - unlink failed. Message: '%s'\n", strerror(errno)); - return -1; + if (unlink(str.c_str())) + { + STG_LOCKER lock(&mutex, __FILE__, __LINE__); + errorStr = "unlink failed. Message: '"; + errorStr += strerror(errno); + errorStr += "'"; + printfd(__FILE__, "FILES_STORE::RemoveDir() - unlink failed. Message: '%s'\n", strerror(errno)); + return -1; + } } - } -fileList.clear(); -GetFileList(&fileList, path, S_IFDIR, ""); + if (!(st.st_mode & S_IFDIR)) + { + if (RemoveDir(str.c_str())) + { + return -1; + } -for (unsigned i = 0; i < fileList.size(); i++) - { - string dir = string(path) + "/" + fileList[i]; - RemoveDir(dir.c_str()); + } } +closedir(d); + if (rmdir(path)) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); errorStr = "rmdir failed. Message: '"; errorStr += strerror(errno); errorStr += "'"; - printfd(__FILE__, "FILES_STORE::RemoveDir - rmdir failed. Message: '%s'\n", strerror(errno)); + printfd(__FILE__, "FILES_STORE::RemoveDir() - rmdir failed. Message: '%s'\n", strerror(errno)); return -1; } @@ -1362,8 +1384,6 @@ if (cf.ReadString("password", &p, "*")) memset(passwordE, 0, sizeof(passwordE)); strncpy(passwordE, p.c_str(), 2*ADM_PASSWD_LEN); -//printfd(__FILE__, "passwordE %s\n", passwordE); - memset(pass, 0, sizeof(pass)); if (passwordE[0] != 0)