Feature: Make Linux a copy_files_c2c destination
The C2C file transfer tool required both ends to be Windows clients. A Linux client can already land the files: the Windows source worker builds every entry name by plain string concatenation of dst_dir and the relative path, so a POSIX dst_dir such as /tmp/recv arrives as "/tmp/recv\sub\file", which the POSIX receiver normalizes to "/" and writes below an absolute path. What was missing was the server gate and any way to tell whether the writes succeeded. The server now accepts LNX/MAC destinations instead of rejecting them, and validates dst_dir by destination type: an absolute Windows path for Windows targets, an absolute POSIX path without backslashes for POSIX targets. The paths and dst_dir arguments also reject embedded NULs, and a POSIX dst_dir is converted to CP936 exactly so unencodable characters fail loudly instead of silently becoming '?'. To make receiver_ack meaningful, a Linux client that receives a C2C transfer now reports what it wrote. It tracks the outcome per transferID, counting a directory entry, the last chunk of a file and the completion packet of an empty file as the three ways an item is settled, with done sets so that source retries and the trailing completion packet never double count. When every item is settled it sends one C2CSendResultPacket back on its main connection under the new TOKEN_C2C_RECV_RESULT (176), with the first errno in the win32err field and the mapped FEV2_* status. A dedicated token is used instead of reusing 175 because a host can be the destination of one transfer while being the source of another, and a destination result must never latch the source side's done flag. The server waits up to five seconds for that acknowledgement after the source reports success, and only for destinations advertising the new CLIENT_CAP_C2C_RECV_ACK capability bit (Linux only, macOS reports nothing). A failed acknowledgement becomes -32011 with the status, errno and received file count; a missing acknowledgement stays an error only for transfers that actually moved bytes, since a transfer of empty files alone gives the receiver nothing to learn totalFiles from. Windows destinations are unchanged and skip the wait entirely. Verified on the debug instance: Windows to Linux (WSL Ubuntu 24.04) with subdirectories, an empty directory, a Chinese file name and a 3 MB binary lands with matching SHA-256 and receiver_ack true; a Windows-style dst_dir returns -32602; an unwritable POSIX destination returns -32011; the existing Windows to Windows cases still pass with receiver_ack false and the same latency. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
4c0e86dcc5
commit
4146c73657
11 files changed
+384
-48
No files matched your search
@@ -298,6 +298,12 @@ public:
|
||||
int32_t workerRc = 0; // FileBatchTransferWorkerV2 返回值
|
||||
uint32_t fileCount = 0;
|
||||
uint64_t totalBytes = 0;
|
||||
// 目标端回执(只有 POSIX 接收端会发;Windows 目标恒为 false)
|
||||
bool recvAck = false; // 收到了目标端回执
|
||||
uint32_t recvStatus = 0; // 回执 status(0=写入成功,FEV2_* = 失败原因)
|
||||
DWORD recvErrno = 0; // 回执 win32err(POSIX 端放 errno)
|
||||
uint32_t recvFileCount = 0; // 回执 fileCount(实收文件数)
|
||||
uint64_t recvBytes = 0; // 回执 totalBytes(实收字节数)
|
||||
};
|
||||
|
||||
// 登记 C2C 会话(false = 源设备已有文件会话/挂起请求,或源==目标)。
|
||||
@@ -307,9 +313,18 @@ public:
|
||||
// 无对应会话(迟到的结果、MFC 侧手写包)直接忽略。
|
||||
void OnC2CResult(uint64_t src_id, const BYTE* buf, ULONG len);
|
||||
|
||||
// TOKEN_C2C_RECV_RESULT:目标客户端(目前只有 Linux)回传落盘回执。
|
||||
// 目标端在服务端没有自己的会话条目(会话键在源端),所以按 dstClientID + transferID 反查;
|
||||
// 回执可能早于源端结果到达,两条 latch 互相独立,这里绝不置 done。
|
||||
void OnC2CRecvResult(uint64_t dst_id, const BYTE* buf, ULONG len);
|
||||
|
||||
// 工具线程:等源客户端回传结果;true=全部发出(error=0)。调用方随后 ClearFileTransfer(src)。
|
||||
bool WaitC2CDone(uint64_t src_id, int timeoutMs, C2CResult& out);
|
||||
|
||||
// 工具线程:源端报告发出后再等目标端回执(仅声明 CLIENT_CAP_C2C_RECV_ACK 的端会回);
|
||||
// true=收到回执(out.recvStatus 判断成败),false=没有回执(老客户端/超时)。
|
||||
bool WaitC2CReceiver(uint64_t src_id, int timeoutMs, C2CResult& out);
|
||||
|
||||
// TOKEN_DRIVE_LIST:识别 download_file,存文件管理器子链接并下发 CMD_DOWN_FILES_V2。
|
||||
// 返回 true=已接管(保持子链接,收尾由 ClearFileTransfer);false=会话已清理(调用方 CancelIO)。
|
||||
bool OnDownloadDriveList(uint64_t device_id, context* fmSubCtx);
|
||||
@@ -686,6 +701,12 @@ private:
|
||||
int32_t c2cWorkerRc = 0; // 结果包 workerRc
|
||||
uint32_t c2cFileCount = 0; // 结果包 fileCount
|
||||
uint64_t c2cBytes = 0; // 结果包 totalBytes
|
||||
// 目标端回执(POSIX 接收端写完最后一包后发的同一个 175 包,dstClientID = 自己)
|
||||
bool recvAck = false; // 已收到目标端回执
|
||||
uint32_t recvStatus = 0; // 回执 status(0=写入成功)
|
||||
DWORD recvErrno = 0; // 回执 win32err(POSIX 端放 errno)
|
||||
uint32_t recvFileCount = 0; // 回执 fileCount(实收文件数)
|
||||
uint64_t recvBytes = 0; // 回执 totalBytes(实收字节数)
|
||||
std::string localDir; // download:本机保存目录(ANSI,结尾 '\')
|
||||
std::string remotePath; // 客户端远程路径(ANSI,发 CMD_DOWN_FILES_V2 用)
|
||||
bool overwrite = false; // 是否覆盖已存在文件
|
||||
|
||||
Reference in new issue
Block a user