Some updated for 1.4.13

This commit is contained in:
WolverinDEV 2020-04-18 12:54:29 +02:00
parent 271d79bb64
commit 4914b1fbd3
5 changed files with 45 additions and 33 deletions

@ -1 +1 @@
Subproject commit c4f7fdb5d692ea376ac2b7bef4fbb0b81c6ea6c5
Subproject commit a3dca4c4cdfb229b7d7fa2f773cada37b614675e

View File

@ -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);

View File

@ -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();

View File

@ -35,20 +35,23 @@ inline fs::path buildPath(std::string rootPath, std::shared_ptr<file::FileEntry>
std::shared_ptr<file::Directory> FileServer::createDirectory(std::string name, std::shared_ptr<file::Directory> 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<file::Directory>(this->findFile(path.string()));
}
bool FileServer::fileExists(std::shared_ptr<file::Directory> 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::File> file) {
return fs::exists(buildPath(this->rootPath, file));
std::error_code code{};
return fs::exists(buildPath(this->rootPath, file), code);
}
std::shared_ptr<file::FileEntry> FileServer::findFile(std::string path, std::shared_ptr<file::Directory> parent) {
@ -61,23 +64,24 @@ std::shared_ptr<file::FileEntry> 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<file::FileEntry> entry;
if(fs::is_directory(absPath))
if(fs::is_directory(absPath, code))
entry = std::make_shared<file::Directory>();
else entry = std::make_shared<file::File>();
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<file::File>(entry)->fileSize = entry->type == FileType::FILE ? fs::file_size(absPath) : 0;
static_pointer_cast<file::File>(entry)->fileSize = entry->type == FileType::FILE ? fs::file_size(absPath, code) : 0;
return entry;
}
@ -85,32 +89,37 @@ std::vector<std::shared_ptr<file::FileEntry>> 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<std::shared_ptr<file::FileEntry>> result;
deque<fs::directory_entry> 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<file::File>();
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<file::Directory>();
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<std::shared_ptr<file::FileEntry>> FileServer::listFiles(std::shared_
}
bool FileServer::deleteFile(std::shared_ptr<file::FileEntry> 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<file::Directory> FileServer::resolveDirectory(const shared_ptr<V
std::shared_ptr<file::Directory> FileServer::iconDirectory(const shared_ptr<VirtualServer> &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<file::Directory>(findFile(path.string()));
@ -251,9 +262,10 @@ void FileServer::setupServer(const shared_ptr<VirtualServer> &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<ts::server::Virtu
void FileServer::deleteServer(const shared_ptr<VirtualServer> &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() + ")");
}

2
shared

@ -1 +1 @@
Subproject commit c31cc9d0ee8fbcd04ff3a76e8fc4ab8723127a84
Subproject commit edc0a9db2b564f1967dbf1955daccac43e7f9e1a