From 4914b1fbd3420ae5ca30e60da6ff068315caa95f Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sat, 18 Apr 2020 12:54:29 +0200 Subject: [PATCH] Some updated for 1.4.13 --- git-teaspeak | 2 +- license/shared/src/client.cpp | 2 +- server/src/ShutdownHelper.cpp | 2 +- server/src/server/file/FileServer.cpp | 70 ++++++++++++++++----------- shared | 2 +- 5 files changed, 45 insertions(+), 33 deletions(-) diff --git a/git-teaspeak b/git-teaspeak index c4f7fdb..a3dca4c 160000 --- a/git-teaspeak +++ b/git-teaspeak @@ -1 +1 @@ -Subproject commit c4f7fdb5d692ea376ac2b7bef4fbb0b81c6ea6c5 +Subproject commit a3dca4c4cdfb229b7d7fa2f773cada37b614675e diff --git a/license/shared/src/client.cpp b/license/shared/src/client.cpp index 31eb00b..0ccceab 100644 --- a/license/shared/src/client.cpp +++ b/license/shared/src/client.cpp @@ -169,7 +169,7 @@ void LicenseServerClient::cleanup_network_resources() { auto buffer = TAILQ_FIRST(&this->buffers.write); while(buffer) { auto next = TAILQ_NEXT(buffer, tail); - Buffer::free(next); + Buffer::free(buffer); buffer = next; } TAILQ_INIT(&this->buffers.write); diff --git a/server/src/ShutdownHelper.cpp b/server/src/ShutdownHelper.cpp index 4fb2776..062d15b 100644 --- a/server/src/ShutdownHelper.cpp +++ b/server/src/ShutdownHelper.cpp @@ -30,7 +30,7 @@ void ts::server::shutdownInstance(const std::string& message) { threads::name(force_kill, "force stopper"); force_kill.detach(); - exit(2); + kill(0, SIGKILL); }); threads::name(hangup_controller, "stop controller"); hangup_controller.detach(); diff --git a/server/src/server/file/FileServer.cpp b/server/src/server/file/FileServer.cpp index 585d051..7214fc3 100644 --- a/server/src/server/file/FileServer.cpp +++ b/server/src/server/file/FileServer.cpp @@ -35,20 +35,23 @@ inline fs::path buildPath(std::string rootPath, std::shared_ptr std::shared_ptr FileServer::createDirectory(std::string name, std::shared_ptr parent) { auto path = buildPath(this->rootPath, parent); path += name; - if(!fs::exists(path)) - if(!fs::create_directories(path)) return nullptr; + std::error_code code{}; + if(!fs::exists(path, code)) + if(!fs::create_directories(path, code)) return nullptr; else ; - else if(!fs::is_directory(path)) return nullptr; + else if(!fs::is_directory(path, code)) return nullptr; return static_pointer_cast(this->findFile(path.string())); } bool FileServer::fileExists(std::shared_ptr dir) { - return fs::exists(buildPath(this->rootPath, dir)); + std::error_code code{}; + return fs::exists(buildPath(this->rootPath, dir), code); } bool FileServer::fileExists(std::shared_ptr file) { - return fs::exists(buildPath(this->rootPath, file)); + std::error_code code{}; + return fs::exists(buildPath(this->rootPath, file), code); } std::shared_ptr FileServer::findFile(std::string path, std::shared_ptr parent) { @@ -61,23 +64,24 @@ std::shared_ptr FileServer::findFile(std::string path, std::sha else path = strPath + path; } + std::error_code code{}; fs::path absPath = fs::u8path(path); - if(!fs::is_regular_file(absPath) && !fs::is_directory(absPath)){ + if(!fs::is_regular_file(absPath, code) && !fs::is_directory(absPath, code)){ debugMessage(LOG_FT, "Could not find requested file. Abs path: {} | {}. (path={}, parent={})", absPath.string(), path, path, (parent ? parent->path + "/" + parent->name : "./")); return nullptr; } std::shared_ptr entry; - if(fs::is_directory(absPath)) + if(fs::is_directory(absPath, code)) entry = std::make_shared(); else entry = std::make_shared(); entry->name = absPath.filename(); - entry->type = fs::is_directory(absPath) ? FileType::DIRECTORY : FileType::FILE; + entry->type = fs::is_directory(absPath, code) ? FileType::DIRECTORY : FileType::FILE; entry->path = absPath.parent_path().string(); - entry->lastChanged = fs::last_write_time(absPath); + entry->lastChanged = fs::last_write_time(absPath, code); if(entry->type == FileType::FILE) - static_pointer_cast(entry)->fileSize = entry->type == FileType::FILE ? fs::file_size(absPath) : 0; + static_pointer_cast(entry)->fileSize = entry->type == FileType::FILE ? fs::file_size(absPath, code) : 0; return entry; } @@ -85,32 +89,37 @@ std::vector> FileServer::listFiles(std::shared_ if(!dir) return {}; auto directory = buildPath(this->rootPath, dir); - if(!fs::exists(directory)) return {}; - if(!fs::is_directory(directory)) return {}; + std::error_code code{}; + if(!fs::exists(directory, code) || code) return {}; + if(!fs::is_directory(directory, code) || code) return {}; std::vector> result; deque files; - for(const auto& elm : fs::directory_iterator(directory)) { + for(const auto& elm : fs::directory_iterator(directory, code)) { files.push_back(elm); } - std::sort(files.begin(), files.end(), [](const fs::directory_entry& a, const fs::directory_entry& b) { - return fs::last_write_time(a.path()) > fs::last_write_time(b.path()); + if(code) { + logWarning(LOG_FT, "Failed to iterate over directory {}: {}", directory.string(), code.message()); + return {}; + } + std::stable_sort(files.begin(), files.end(), [&](const fs::directory_entry& a, const fs::directory_entry& b) { + return fs::last_write_time(a.path(), code) > fs::last_write_time(b.path(), code); }); for(const auto& elm : files) { - if(fs::is_regular_file(elm.path())){ + if(fs::is_regular_file(elm.path(), code)){ auto entry = make_shared(); entry->name = elm.path().filename(); entry->type = FileType::FILE; entry->path = elm.path().parent_path().string(); - entry->lastChanged = fs::last_write_time(elm.path()); - entry->fileSize = fs::file_size(elm.path()); + entry->lastChanged = fs::last_write_time(elm.path(), code); + entry->fileSize = fs::file_size(elm.path(), code); result.push_back(entry); - } else if(fs::is_directory(elm.path())){ + } else if(fs::is_directory(elm.path(), code)){ auto entry = make_shared(); entry->name = elm.path().filename(); entry->type = FileType::DIRECTORY; entry->path = elm.path().parent_path().string(); - entry->lastChanged = fs::last_write_time(elm.path()); + entry->lastChanged = fs::last_write_time(elm.path(), code); result.push_back(entry); } else { logError(LOG_FT, "Invalid file in file tree. File path: " + elm.path().string()); @@ -121,7 +130,8 @@ std::vector> FileServer::listFiles(std::shared_ } bool FileServer::deleteFile(std::shared_ptr file) { - return fs::remove_all(fs::u8path(file->path + "/" + file->name)) > 0; + std::error_code code{}; + return fs::remove_all(fs::u8path(file->path + "/" + file->name), code) > 0 && !code; } inline std::string randomString(uint length = 15, std::string charIndex = "abcdefghijklmnaoqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890") @@ -225,8 +235,9 @@ std::shared_ptr FileServer::resolveDirectory(const shared_ptr FileServer::iconDirectory(const shared_ptr &server) { fs::path root = fs::u8path(this->rootPath); fs::path path = fs::u8path("server_" + to_string(server ? server->getServerId() : 0) + "/icons"); - if(!fs::exists(root / path)) { - if(!fs::create_directories(root / path)) + std::error_code code{}; + if(!fs::exists(root / path, code)) { + if(!fs::create_directories(root / path, code) || code) return nullptr; } return static_pointer_cast(findFile(path.string())); @@ -251,9 +262,10 @@ void FileServer::setupServer(const shared_ptr &server) { if(!dir) { logError(LOG_FT,"Failed to find icon directory for server {}", server ? server->getServerId() : 0); } else { - if(!fs::exists(fs::u8path(dir->path + "/" + dir->name + "/" TS3_ICON_HASH))) { + std::error_code code{}; + if(!fs::exists(fs::u8path(dir->path + "/" + dir->name + "/" TS3_ICON_HASH), code)) { try { - fs::copy(fs::u8path("resources/teaspeak16px.png"), fs::u8path(dir->path + "/" + dir->name + "/" + TS3_ICON_HASH)); + fs::copy(fs::u8path("resources/teaspeak16px.png"), fs::u8path(dir->path + "/" + dir->name + "/" + TS3_ICON_HASH), code); } catch(std::exception& ex) { logError(LOG_FT, "Failed to copy default path: {}", ex.what()); } @@ -267,10 +279,10 @@ std::string FileServer::server_file_base(const std::shared_ptr &server) { fs::path path = fs::u8path(rootPath + "/server_" + to_string(server ? server->getServerId() : 0)); - if(fs::exists(path)) { - error_code error; - if(fs::remove_all(path, error) == 0) - logError(LOG_FT, "Could not delete server directory {} ({} | {})", path.string(), error.value(), error.message()); + std::error_code code{}; + if(fs::exists(path, code) && !code) { + if(fs::remove_all(path, code) == 0) + logError(LOG_FT, "Could not delete server directory {} ({} | {})", path.string(), code.value(), code.message()); } else { logError(LOG_FT, "Could not delete missing server directory (" + path.string() + ")"); } diff --git a/shared b/shared index c31cc9d..edc0a9d 160000 --- a/shared +++ b/shared @@ -1 +1 @@ -Subproject commit c31cc9d0ee8fbcd04ff3a76e8fc4ab8723127a84 +Subproject commit edc0a9db2b564f1967dbf1955daccac43e7f9e1a