From 2e169b34f79f0749d7b4bded86cf5a242e51092b Mon Sep 17 00:00:00 2001 From: dengzhongyuan365-dev Date: Tue, 17 Nov 2026 23:20:25 +0800 Subject: [PATCH] fix: skip backup recovery for explicitly opened files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. recoverFile() did not deduplicate backup records against files being explicitly opened, causing both a backup tab (with NUL bytes) and the real file tab to appear when opening from a zip archive 2. Add explicitFiles parameter to recoverFile() to skip backup records whose localPath matches any explicitly requested file path 3. Pass resolved file list from openFilesInTab() QTimer lambda to recoverFile() so session recovery skips already-requested files 4. The parameter has a default empty value, so existing callers that do not need dedup are unaffected Log: fix invalid character warning when opening txt from zip archive Influence: 1. Open a txt file from a zip archive after having a backup of the same file, verify no "invalid character" warning appears 2. Verify normal session recovery still works when no files are explicitly opened 3. Verify opening local files directly still deduplicates correctly fix: 跳过显式打开文件的备份恢复 1. recoverFile() 未对备份记录与显式打开文件做去重,从压缩包打开 txt 时同时出现备份标签页(含 NUL 字节)和真实文件标签页 2. 为 recoverFile() 新增 explicitFiles 参数,跳过 localPath 与显式 请求文件路径匹配的备份记录 3. openFilesInTab() 的 QTimer lambda 传入已解析文件列表,使会话 恢复跳过已请求打开的文件 4. 参数使用默认空值,不影响不需要去重的既有调用者 Log: 修复从压缩包打开 txt 文件时提示无效字符的问题 Influence: 1. 从压缩包打开已有备份的 txt 文件,验证不再出现"无效字符"提示 2. 验证无显式文件打开时会话恢复正常工作 3. 验证直接打开本地文件时去重逻辑仍正常 PMS: BUG-379437 --- src/startmanager.cpp | 17 +++++++++++++++-- src/startmanager.h | 3 ++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/startmanager.cpp b/src/startmanager.cpp index 044a1d6e..19c7a166 100644 --- a/src/startmanager.cpp +++ b/src/startmanager.cpp @@ -327,7 +327,7 @@ void StartManager::autoBackupFile() qCDebug(appLog) << "Exit autoBackupFile"; } -int StartManager::recoverFile(Window *window) +int StartManager::recoverFile(Window *window, const QStringList &explicitFiles) { qCDebug(appLog) << "Enter recoverFile"; @@ -420,6 +420,15 @@ int StartManager::recoverFile(Window *window) } } + // 跳过显式请求打开的文件的备份记录,避免会话恢复与显式打开之间路径去重失败 + if (!explicitFiles.isEmpty() && !localPath.isEmpty()) { + QString resolvedLocal = Utils::getFilePath(localPath); + if (explicitFiles.contains(resolvedLocal)) { + qCDebug(appLog) << "Skipping backup for explicitly opened file:" << localPath; + continue; + } + } + // 确定实际打开路径和显示名称 QString openPath; QString displayName; @@ -639,7 +648,11 @@ void StartManager::openFilesInTab(QStringList files) // 以 window 为 context:窗口在延时期间被销毁则不触发,避免悬空调用 QTimer::singleShot(50, window, [ = ] { qCDebug(appLog) << "Delayed file opening for:" << resolvedFile; - recoverFile(window); + QStringList resolvedFiles; + for (const QString &f : files) { + resolvedFiles << Utils::getFilePath(f); + } + recoverFile(window, resolvedFiles); window->addTab(resolvedFile); }); } diff --git a/src/startmanager.h b/src/startmanager.h index 1f6f94ba..d597d6ba 100644 --- a/src/startmanager.h +++ b/src/startmanager.h @@ -57,9 +57,10 @@ class StartManager : public QObject /** * @brief recoverFile 备份恢复 * @param window 从哪个窗口进行恢复 + * @param explicitFiles 显式请求打开的文件路径列表,恢复时跳过这些文件的备份记录 * @return 恢复完成的文件数量 */ - int recoverFile(Window *window); + int recoverFile(Window *window, const QStringList &explicitFiles = QStringList()); /** * @brief analyzeBookmakeInfo 解析书签信息