From fdd18882d88f59d41cfe249d20974d7887016717 Mon Sep 17 00:00:00 2001 From: taynpg Date: Mon, 10 Feb 2025 16:54:43 +0800 Subject: [PATCH] =?UTF-8?q?add=EF=BC=9A=E6=B7=BB=E5=8A=A0=E4=BF=9D?= =?UTF-8?q?=E7=95=99=E5=8E=9F=E4=BC=A0=E8=BE=93=E6=96=87=E4=BB=B6=E6=9D=83?= =?UTF-8?q?=E9=99=90=E7=9A=84=E5=8A=9F=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 4 +++- client/client.cpp | 35 +++++++++++++++++++++++++++++------ client/client.h | 2 ++ util/util.h | 2 +- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 84c40f6..1af970f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -145,7 +145,9 @@ "text_encoding": "cpp", "*.in": "cpp", "hash_map": "cpp", - "stdfloat": "cpp" + "stdfloat": "cpp", + "unordered_set": "cpp", + "cfenv": "cpp" }, "makefile.configureOnOpen": false, "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools" diff --git a/client/client.cpp b/client/client.cpp index c52388e..704722c 100644 --- a/client/client.cpp +++ b/client/client.cpp @@ -600,6 +600,11 @@ void CClient::handle_frame(CFrameBuffer* buf) } case TYPE_TRANS_DONE: { report_trans_ret(TRANS_DONE); + if (down_) { + mpinfo("recovery permissions {}.", down_->permissions); + fs::perms perms = static_cast(down_->permissions); + fs::permissions(down_->cur_file_, perms); + } break; } case TYPE_OPEN_FAILED: { @@ -675,11 +680,19 @@ void CClient::handle_frame(CFrameBuffer* buf) mpinfo("remote {} are busy, will not exec task {}", buf->fid_, list_file_); break; } - case TYPE_FILE_SIZE: { + case TYPE_FILE_INFO: { std::string str_size(buf->data_, buf->len_); - long long size = std::stoll(str_size); + auto vec = COfStr::split(str_size, ","); + if (vec.size() < 2) { + mperror("invalid file information:{}", str_size); + break; + } + long long size = std::stoll(vec[0]); std::string show_str = OfUtil::get_file_size(size); - mpinfo("Ready Down Size: {}", show_str); + mpinfo("Ready Down Size: {}, permissions:{}", show_str, vec[1]); + if (down_) { + down_->permissions = static_cast(std::stoul(vec[1])); + } cur_file_size_ = size; } default: @@ -706,15 +719,25 @@ void CClient::send_file_data_th(const char* keys) buf->data_ = new char[g_BuffSize]{}; buf->tid_ = str_key; + // ******************************************************** + // TYPE_FILE_INFO格式:大小,权限 + // ******************************************************** + // seekg 用于读,seekp 用于写。 t->file_.seekg(0, std::ios::end); long long size = t->file_.tellg(); t->file_.seekg(0, std::ios::beg); - buf->type_ = TYPE_FILE_SIZE; + buf->type_ = TYPE_FILE_INFO; std::string str_size = std::to_string(size); - mpinfo("To {} File Size: {} [{}]", str_key, ofen::OfUtil::get_file_size(size), size); - buf->len_ = std::snprintf(buf->data_, g_BuffSize, "%s", str_size.c_str()); + // 文件权限 + auto perms = fs::status(t->cur_file_).permissions(); + std::string str_perm = std::to_string(static_cast(perms)); + std::string info_result = str_size + "," + str_perm; + + mpinfo("To {} File Size: {} [{}], permissions:{}", str_key, ofen::OfUtil::get_file_size(size), size, + str_perm); + buf->len_ = std::snprintf(buf->data_, g_BuffSize, "%s", info_result.c_str()); if (!send_frame(buf.get())) { report_trans_ret(TRANS_FAILED, str_key); mperror("Stop Trans {} To {} failed.", t->cur_file_, str_key); diff --git a/client/client.h b/client/client.h index b486862..ea2a6fc 100644 --- a/client/client.h +++ b/client/client.h @@ -9,6 +9,7 @@ #include #include #include +#include using namespace ofen; struct DownClientInfo { @@ -29,6 +30,7 @@ struct TransInfomation { std::string cur_remote_file_; std::string cur_file_; std::fstream file_{}; + uint16_t permissions{}; TransState trans_state_{TRANS_FAILED}; }; diff --git a/util/util.h b/util/util.h index ba98657..6a527db 100644 --- a/util/util.h +++ b/util/util.h @@ -33,7 +33,7 @@ enum FrameType : int16_t { TYPE_BUSY_UPDATE_LIST, TYPE_FAILED_UPDATE_LIST, TYPE_GET_ID, - TYPE_FILE_SIZE + TYPE_FILE_INFO }; using namespace ofen;