Feature: query the remote SHA-256 before previewing

When the main connection advertises CLIENT_CAP_FILE_HASH, double-click
sends COMMAND_FILE_HASH first and continues from the async
TOKEN_FILE_HASH response (posted to the UI thread). A matching SHA-256
opens the cached copy without a transfer, including content found under
a different remote path; the new path is added to the index. Too-large
and error responses are handled, and a 5 second timeout falls back to the
P1 size/mtime path.

The response parser is based on FileHashResponseHeader and the echoed
request path; pending state is cleared on close and the hash timer is
killed with the dialog.

Verified with the Debug server and client: a 1 MiB file was hashed,
transferred and cached under its SHA-256; an identical copy at a second
path hit the cache with no new transfer or stream connection.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-12-05 15:43:12 +01:00
1 parent ea5d69d1c0
commit 6cb779ef70
7 files changed
+168 -5

No files matched your search

+16
View File
@@ -157,6 +157,22 @@ CFilePreviewMgr::PrepareResult CFilePreviewMgr::Prepare(
if (m.remotePath == hit.remotePath && m.localName == hit.localName)
m.lastUsed = now;
}
// 按 SHA 命中另一条远程路径(跨路径去重):把当前路径补进索引,
// 下次同一路径可直接按 remotePath/size/mtime 命中,不必再查哈希。
if (hit.remotePath != remotePath) {
Meta m;
m.remotePath = remotePath;
m.size = hit.size;
m.mtimeMs = mtimeMs;
m.sha256 = hit.sha256;
m.localName = hit.localName;
m.lastUsed = now;
bool replaced = false;
for (auto& e : index) {
if (e.remotePath == remotePath) { e = m; replaced = true; break; }
}
if (!replaced) index.push_back(m);
}
SaveIndex(clientDir, index);
outPath = localPath;
if (outSha) *outSha = hit.sha256;