add:添加保留原传输文件权限的功能。

This commit is contained in:
taynpg 2025-02-10 16:54:43 +08:00
parent 0f9a5bed45
commit fdd18882d8
4 changed files with 35 additions and 8 deletions

View File

@ -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"

View File

@ -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<fs::perms>(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<uint16_t>(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<uint16_t>(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);

View File

@ -9,6 +9,7 @@
#include <string>
#include <util.h>
#include <vector>
#include <cstdint>
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};
};

View File

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