add:添加保留原传输文件权限的功能。
This commit is contained in:
		
							parent
							
								
									0f9a5bed45
								
							
						
					
					
						commit
						fdd18882d8
					
				
							
								
								
									
										4
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
								
							@ -145,7 +145,9 @@
 | 
				
			|||||||
        "text_encoding": "cpp",
 | 
					        "text_encoding": "cpp",
 | 
				
			||||||
        "*.in": "cpp",
 | 
					        "*.in": "cpp",
 | 
				
			||||||
        "hash_map": "cpp",
 | 
					        "hash_map": "cpp",
 | 
				
			||||||
        "stdfloat": "cpp"
 | 
					        "stdfloat": "cpp",
 | 
				
			||||||
 | 
					        "unordered_set": "cpp",
 | 
				
			||||||
 | 
					        "cfenv": "cpp"
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "makefile.configureOnOpen": false,
 | 
					    "makefile.configureOnOpen": false,
 | 
				
			||||||
    "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools"
 | 
					    "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools"
 | 
				
			||||||
 | 
				
			|||||||
@ -600,6 +600,11 @@ void CClient::handle_frame(CFrameBuffer* buf)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    case TYPE_TRANS_DONE: {
 | 
					    case TYPE_TRANS_DONE: {
 | 
				
			||||||
        report_trans_ret(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;
 | 
					        break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    case TYPE_OPEN_FAILED: {
 | 
					    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_);
 | 
					        mpinfo("remote {} are busy, will not exec task {}", buf->fid_, list_file_);
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    case TYPE_FILE_SIZE: {
 | 
					    case TYPE_FILE_INFO: {
 | 
				
			||||||
        std::string str_size(buf->data_, buf->len_);
 | 
					        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);
 | 
					        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;
 | 
					        cur_file_size_ = size;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    default:
 | 
					    default:
 | 
				
			||||||
@ -706,15 +719,25 @@ void CClient::send_file_data_th(const char* keys)
 | 
				
			|||||||
    buf->data_ = new char[g_BuffSize]{};
 | 
					    buf->data_ = new char[g_BuffSize]{};
 | 
				
			||||||
    buf->tid_ = str_key;
 | 
					    buf->tid_ = str_key;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // ********************************************************
 | 
				
			||||||
 | 
					    // TYPE_FILE_INFO格式:大小,权限
 | 
				
			||||||
 | 
					    // ********************************************************
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // seekg 用于读,seekp 用于写。
 | 
					    // seekg 用于读,seekp 用于写。
 | 
				
			||||||
    t->file_.seekg(0, std::ios::end);
 | 
					    t->file_.seekg(0, std::ios::end);
 | 
				
			||||||
    long long size = t->file_.tellg();
 | 
					    long long size = t->file_.tellg();
 | 
				
			||||||
    t->file_.seekg(0, std::ios::beg);
 | 
					    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);
 | 
					    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())) {
 | 
					    if (!send_frame(buf.get())) {
 | 
				
			||||||
        report_trans_ret(TRANS_FAILED, str_key);
 | 
					        report_trans_ret(TRANS_FAILED, str_key);
 | 
				
			||||||
        mperror("Stop Trans {} To {} failed.", t->cur_file_, str_key);
 | 
					        mperror("Stop Trans {} To {} failed.", t->cur_file_, str_key);
 | 
				
			||||||
 | 
				
			|||||||
@ -9,6 +9,7 @@
 | 
				
			|||||||
#include <string>
 | 
					#include <string>
 | 
				
			||||||
#include <util.h>
 | 
					#include <util.h>
 | 
				
			||||||
#include <vector>
 | 
					#include <vector>
 | 
				
			||||||
 | 
					#include <cstdint>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
using namespace ofen;
 | 
					using namespace ofen;
 | 
				
			||||||
struct DownClientInfo {
 | 
					struct DownClientInfo {
 | 
				
			||||||
@ -29,6 +30,7 @@ struct TransInfomation {
 | 
				
			|||||||
    std::string cur_remote_file_;
 | 
					    std::string cur_remote_file_;
 | 
				
			||||||
    std::string cur_file_;
 | 
					    std::string cur_file_;
 | 
				
			||||||
    std::fstream file_{};
 | 
					    std::fstream file_{};
 | 
				
			||||||
 | 
					    uint16_t permissions{};
 | 
				
			||||||
    TransState trans_state_{TRANS_FAILED};
 | 
					    TransState trans_state_{TRANS_FAILED};
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -33,7 +33,7 @@ enum FrameType : int16_t {
 | 
				
			|||||||
    TYPE_BUSY_UPDATE_LIST,
 | 
					    TYPE_BUSY_UPDATE_LIST,
 | 
				
			||||||
    TYPE_FAILED_UPDATE_LIST,
 | 
					    TYPE_FAILED_UPDATE_LIST,
 | 
				
			||||||
    TYPE_GET_ID,
 | 
					    TYPE_GET_ID,
 | 
				
			||||||
    TYPE_FILE_SIZE
 | 
					    TYPE_FILE_INFO
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
using namespace ofen;
 | 
					using namespace ofen;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user