From 39f0928de7fa4bb0f3e444e4f1eb7893594559d3 Mon Sep 17 00:00:00 2001 From: yuanyuanxiang <962914132@qq.com> Date: Sun, 25 Oct 2026 14:16:46 +0100 Subject: [PATCH] Fix: Finish a directory-only download instead of waiting for the timeout The completion check compared filesDone against totalFiles minus directoryCount and only ran on COMMAND_FILE_COMPLETE_V2. The client sends no COMPLETE for directory entries, so a download of an empty directory, or of a tree that holds only subdirectories, had zero expected files and could never satisfy the check. The call sat there until timeout_ms expired (600 s by default) and then reported 1002. Mark the session done as soon as the directory entries account for every entry the client declared. Verified with the debug client: an empty directory returns in 0.2 s with zero files, a tree of nested subdirectories returns in 0.2 s with the directories created, and a directory holding three files still downloads them with the same sizes and hashes as before. Co-Authored-By: deepseek-flash --- docs/Mcp_FileTransfer_Design.md | 6 ++++++ server/2015Remote/McpServer.cpp | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/docs/Mcp_FileTransfer_Design.md b/docs/Mcp_FileTransfer_Design.md index 2b57122..51d8e77 100644 --- a/docs/Mcp_FileTransfer_Design.md +++ b/docs/Mcp_FileTransfer_Design.md @@ -394,3 +394,9 @@ int n = RecvFileChunkV2((char*)szBuffer, ulLength, m_conn, nullptr, m_hash, m_hm | U7 | 实施验证发现:客户端主连接 `g_status==0`,`RecvFileChunkV2` 逐 chunk `return -1`(上传落盘 0 字节/截断) | 客户端 `COMMAND_SEND_FILE_V2` 分支加懒初始化(§7.8):`static` 一次 + 永久引用计数、析构不 `Uninit`;与 `FileManager.cpp:40` 参数一致,独立评审确认无稳定性风险 | **判定**:7 项均已写入 §7 对应小节,无阻塞项,**定稿**。 + +### 13.2 实施后修复记录(2026-10-25) + +| # | 问题 | 修复 | +|---|---|---| +| R1 | **纯目录树下载必超时**:完成判定 `filesDone >= totalFiles - directoryCount` 只在 `OnFileCompleteV2` 里跑,而客户端对目录项不发 `COMMAND_FILE_COMPLETE_V2`。空目录/只有子目录的树期望文件数为 0,永远等不到 COMPLETE → 只能干等 `timeout_ms`(默认 600s)后报 `1002` | `OnFileChunkV2` 的目录分支里,`directoryCount >= totalFiles`(即全部条目都是目录)时直接置 `done` + notify。实测空目录 0.2s 返回、3 文件目录树回归正常 | diff --git a/server/2015Remote/McpServer.cpp b/server/2015Remote/McpServer.cpp index 14359ab..f46ea6c 100644 --- a/server/2015Remote/McpServer.cpp +++ b/server/2015Remote/McpServer.cpp @@ -7068,6 +7068,13 @@ void CMcpServer::OnFileChunkV2(uint64_t device_id, context* streamSubCtx, const } s.directoryCount++; RecvFileChunkV2((char*)buf, len, nullptr, nullptr, hash, hmac, 0); + // 纯目录树(空目录、只有子目录):期望文件数 = totalFiles - directoryCount = 0, + // 而客户端对目录项不发 COMPLETE 包,完成判定永远等不到 → 只能干等到超时。 + // 目录项数已覆盖全部条目时直接判完成(totalFiles 含目录项,见 F4)。 + if (s.totalFiles > 0 && s.directoryCount >= s.totalFiles) { + s.done = true; + m_FileXferCv.notify_one(); + } return; }