Fix: handle preview download errors and Unix metadata keys

Consume TOKEN_DOWNLOAD_ERROR in the file manager and fail the matching
preview request with the client's win32 code instead of sending
COMMAND_EXCEPTION and leaving the request to the 15 s watchdog.

Key the exact size/mtime metadata by the list's displayed ANSI/GBK text,
not the raw protocol bytes: Linux/macOS send UTF-8 names while GetItemText
returns the process ACP, so non-ASCII files previously missed the metadata
lookup and could not start a preview.

Bind the Unix progress dialog to the preview request so a stalled transfer
closes it on timeout; save the index after LRU eviction; make the local
right-click Open honour search-result paths; reject over-long received
names; and defer abandoned temp-dir deletion to the watchdog.

The new download-error and hash-error strings are added to en_US, zh_TW
and de_DE.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-12-05 15:44:36 +01:00
1 parent 6cb779ef70
commit bcd7ee692a
6 files changed
+70 -9

No files matched your search

+29 -3
View File
@@ -274,12 +274,23 @@ void CFilePreviewMgr::CancelForHwnd(HWND hwnd)
if (req.progressHwnd && ::IsWindow(req.progressHwnd))
::PostMessage(req.progressHwnd, WM_CLOSE, 0, 0);
TombstoneLocked(req.tempDir);
RemoveTempDir(req.tempDir);
req.ctx = nullptr;
req.recvName.clear();
}
}
void CFilePreviewMgr::FailForHwnd(HWND hwnd, const std::string& message)
{
std::lock_guard<std::mutex> lk(m_mtx);
for (auto& req : m_reqs) {
if (req.notifyHwnd != hwnd) continue;
if (req.state == Request::WaitFirst || req.state == Request::Transferring) {
FailLocked(req, message);
return;
}
}
}
bool CFilePreviewMgr::ObserveChunk(CONTEXT_OBJECT* ctx, const FileChunkPacketV2* pkt,
const char* name, ULONG len, uint64_t* transferID)
{
@@ -302,6 +313,10 @@ bool CFilePreviewMgr::ObserveChunk(CONTEXT_OBJECT* ctx, const FileChunkPacketV2*
if (req->state == Request::Failed || req->state == Request::Abandoned ||
req->state == Request::Done)
return false; // 迟到/已失败:调用方取消连接,不能变回普通下载
if (safeName.size() > MAX_PATH - 64) {
FailLocked(*req, AsStd(_TR("预览文件名越界")));
return false;
}
if (!IsSingleFileUnder(req->tempDir, safeName)) {
FailLocked(*req, AsStd(_TR("预览文件名越界")));
return false;
@@ -320,6 +335,10 @@ bool CFilePreviewMgr::ObserveChunk(CONTEXT_OBJECT* ctx, const FileChunkPacketV2*
(int)req->state, safeName.c_str());
return false;
}
if (safeName.size() > MAX_PATH - 64) {
FailLocked(*req, AsStd(_TR("预览文件名越界")));
return false;
}
if (!IsSingleFileUnder(req->tempDir, safeName)) {
Mprintf("[Preview] observe path reject temp=%s name=%s\n",
@@ -504,10 +523,13 @@ void CFilePreviewMgr::WatchdogLoop()
for (auto it = m_reqs.begin(); it != m_reqs.end(); ) {
bool finished = (it->state == Request::Done || it->state == Request::Failed ||
it->state == Request::Abandoned);
if (finished && now - it->lastDataAt > std::chrono::seconds(kFinishedKeepSec))
if (finished && now - it->lastDataAt > std::chrono::seconds(kFinishedKeepSec)) {
// 延迟到请求结束后再删临时目录:CancelForHwnd 时网络侧可能还在写。
RemoveTempDir(it->tempDir);
it = m_reqs.erase(it);
else
} else {
++it;
}
}
}
}
@@ -858,16 +880,20 @@ void CFilePreviewMgr::EnforceCacheLimits(const std::string& clientDir, std::vect
std::sort(index.begin(), index.end(), [](const Meta& a, const Meta& b) {
return a.lastUsed < b.lastUsed;
});
bool changed = false;
while ((int)index.size() > maxFiles || uniqueBytes() > limitBytes) {
if (index.empty()) break;
std::string name = index.front().localName;
index.erase(index.begin());
changed = true;
bool referenced = false;
for (const auto& m : index)
if (m.localName == name) { referenced = true; break; }
if (!referenced)
DeleteFileA((clientDir + "\\" + name).c_str());
}
if (changed)
SaveIndex(clientDir, index); // 淘汰后必须落盘,否则 index.txt 会一直持有已删条目
}
bool CFilePreviewMgr::MoveOrCopy(const std::string& from, const std::string& to)