Feature(mcp): add read_file for byte-accurate remote text reads
read_file fetches a single remote file through the existing V2 download channel into a per-call temp directory, decodes it, and deletes the temp files on every exit path. It returns the file size, detected encoding, EOL style, total line count, the requested slice (negative offset counts from the end), a truncation flag and the whole file's SHA-256. Encoding auto-detection follows BOM -> UTF-8 validity -> GBK fallback, and utf-8/gbk/gb18030/latin1 can be forced. Files above 2MB and directories are rejected from the first chunk, so nothing is written to disk for them. The tool is gated by McpFileTransfer only: it never writes to the remote host, so it stays available in readonly mode. The V2 receive path now serves both download_file and read_file. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
0378e96470
commit
697044d84b
4 files changed
+663
-10
No files matched your search
@@ -392,9 +392,10 @@ public:
|
||||
bool IsC2CTransferPending(uint64_t src_id, uint64_t dst_id);
|
||||
|
||||
// 登记文件传输会话(false = 该 host 已有文件会话或一次性挂起请求)。
|
||||
// maxFileBytes 仅 read_file 使用:首包文件尺寸超过它就拒收(0=不限)。
|
||||
bool BeginFileTransferPending(uint64_t device_id, const std::string& tool,
|
||||
const std::string& localDir, const std::string& remotePath,
|
||||
bool overwrite);
|
||||
bool overwrite, uint64_t maxFileBytes = 0);
|
||||
|
||||
// 登记上传会话(false = 该 host 已有文件会话或一次性挂起请求)。upload 走主连接、
|
||||
// 工具线程同步驱动 FileBatchTransferWorkerV2。会话同时用于单设备单传输互斥与
|
||||
@@ -918,7 +919,10 @@ private:
|
||||
uint32_t filesDone = 0; // 已完成的文件数(含跳过的)
|
||||
bool done = false; // 全部完成或出错
|
||||
int error = 0; // 0=ok;8=哈希不匹配;1001=路径逃逸;1002=超时;1003=流式子连接断线;
|
||||
// 1004=停滞(看门狗);1005=远端路径不存在;1006=拒绝访问;1007=其他下载失败
|
||||
// 1004=停滞(看门狗);1005=远端路径不存在;1006=拒绝访问;1007=其他下载失败;
|
||||
// 1008=read_file 拒绝:文件大于 maxFileBytes;1009=read_file 拒绝:路径是目录或命中多个文件
|
||||
// read_file 专用:只收单个普通文件,首包文件尺寸超过该值直接拒收(0=不限,download_file 用)
|
||||
uint64_t maxFileBytes = 0;
|
||||
DWORD errorDetail = 0; // error=1005/1006/1007 时的 win32 码(原样带进文案,便于分支/排查)
|
||||
std::map<uint32_t, FileTransferEntry> fileEntries; // fileIndex → {path,size,sha256}
|
||||
std::set<uint32_t> skipIndexes; // overwrite=false 跳过的 fileIndex
|
||||
|
||||
Reference in new issue
Block a user