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
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-10-25 14:16:46 +01:00
1 parent 8f718d9b39
commit 39f0928de7
2 files changed
+13

No files matched your search

+6
View File
@@ -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 文件目录树回归正常 |
+7
View File
@@ -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;
}