Repository navigation
fix: skip backup recovery for explicitly opened files - #736
dengzhongyuan365-dev wants to merge 1 commit into
Conversation
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
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: dengzhongyuan365-dev The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideAPIAdd an optional explicit-file list to the recovery interface so callers can request deduplication without changing existing callers.
Uses of the APIResolve the requested file paths in the delayed-open callback and pass them to recovery before adding the requested tab.
ImplementationUpdate the recovery function signature and skip backup records whose resolved local path matches an explicitly requested file.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/startmanager.cpp" line_range="428" />
<code_context>
+ QString resolvedLocal = Utils::getFilePath(localPath);
+ if (explicitFiles.contains(resolvedLocal)) {
+ qCDebug(appLog) << "Skipping backup for explicitly opened file:" << localPath;
+ continue;
+ }
+ }
</code_context>
<issue_to_address>
**Unsaved recovery edits disappear**
When an explicitly opened file has a modified recovery backup, `recoverFile` skips the backup, so `openFilesInTab` opens the on-disk contents instead or, if the file is unreadable, leaves no tab with the valid backup. A later `autoBackupFile` can overwrite the saved session record with the opened file's current contents.
Preserve and restore the modified backup for explicitly opened files, including when opening the on-disk file fails.
Also at `src/startmanager.cpp:429`.
</issue_to_address>
### Comment 2
<location path="src/startmanager.h" line_range="63" />
<code_context>
* @return 恢复完成的文件数量
*/
- int recoverFile(Window *window);
+ int recoverFile(Window *window, const QStringList &explicitFiles = QStringList());
/**
</code_context>
<issue_to_address>
**Test target no longer compiles**
When the test target is compiled, `recoverFile` has a two-parameter member-function type despite its default argument, so the existing one-parameter `static_cast` stubs in `test_startmanager` fail and the test target does not build.
Preserve the one-parameter overload and add a separate overload that accepts the explicit-file list.
Also at `src/startmanager.cpp:330`, `src/startmanager.h:64`.
</issue_to_address>
### Comment 3
<location path="src/startmanager.cpp" line_range="428" />
<code_context>
+ QString resolvedLocal = Utils::getFilePath(localPath);
+ if (explicitFiles.contains(resolvedLocal)) {
+ qCDebug(appLog) << "Skipping backup for explicitly opened file:" << localPath;
+ continue;
+ }
+ }
</code_context>
<issue_to_address>
**Restored tabs lose window separation**
When all saved records in the first window match explicitly opened files and a later saved window has records to restore, `recoverFile` skips the first window's records before updating `windowIndex`, so the first later-window record initializes the index without creating a window and its tabs are added to the supplied window alongside the explicitly opened files.
Update the saved window index and create the corresponding window before skipping an explicitly opened record.
Also at `src/startmanager.cpp:429`.
</issue_to_address>
### Comment 4
<location path="src/startmanager.cpp" line_range="655" />
<code_context>
+ for (const QString &f : files) {
+ resolvedFiles << Utils::getFilePath(f);
+ }
+ recoverFile(window, resolvedFiles);
window->addTab(resolvedFile);
});
</code_context>
<issue_to_address>
**Recovery opens duplicate tabs**
When a second `openFilesInTab` request arrives during the first request's 50 ms delay and includes a file with a saved backup, `openFilesInTab` opens the second request's file immediately, but the first request's delayed recovery passes only its own file list to `recoverFile`, which restores the second file's backup as another tab.
Pass recovery the combined list of files opened by requests received before the delayed recovery runs.
</issue_to_address>| QString resolvedLocal = Utils::getFilePath(localPath); | ||
| if (explicitFiles.contains(resolvedLocal)) { | ||
| qCDebug(appLog) << "Skipping backup for explicitly opened file:" << localPath; | ||
| continue; |
There was a problem hiding this comment.
🔴 Critical · Unsaved recovery edits disappear
When an explicitly opened file has a modified recovery backup, recoverFile skips the backup, so openFilesInTab opens the on-disk contents instead or, if the file is unreadable, leaves no tab with the valid backup. A later autoBackupFile can overwrite the saved session record with the opened file's current contents.
Preserve and restore the modified backup for explicitly opened files, including when opening the on-disk file fails.
Also at src/startmanager.cpp:429.
Prompt for AI agents
In `src/startmanager.cpp` at line 428:
**Unsaved recovery edits disappear**
When an explicitly opened file has a modified recovery backup, `recoverFile` skips the backup, so `openFilesInTab` opens the on-disk contents instead or, if the file is unreadable, leaves no tab with the valid backup. A later `autoBackupFile` can overwrite the saved session record with the opened file's current contents.
Preserve and restore the modified backup for explicitly opened files, including when opening the on-disk file fails.
Also at `src/startmanager.cpp:429`.| * @return 恢复完成的文件数量 | ||
| */ | ||
| int recoverFile(Window *window); | ||
| int recoverFile(Window *window, const QStringList &explicitFiles = QStringList()); |
There was a problem hiding this comment.
🔴 Critical · Test target no longer compiles
When the test target is compiled, recoverFile has a two-parameter member-function type despite its default argument, so the existing one-parameter static_cast stubs in test_startmanager fail and the test target does not build.
Preserve the one-parameter overload and add a separate overload that accepts the explicit-file list.
Also at src/startmanager.cpp:330, src/startmanager.h:64.
Prompt for AI agents
In `src/startmanager.h` at line 63:
**Test target no longer compiles**
When the test target is compiled, `recoverFile` has a two-parameter member-function type despite its default argument, so the existing one-parameter `static_cast` stubs in `test_startmanager` fail and the test target does not build.
Preserve the one-parameter overload and add a separate overload that accepts the explicit-file list.
Also at `src/startmanager.cpp:330`, `src/startmanager.h:64`.| QString resolvedLocal = Utils::getFilePath(localPath); | ||
| if (explicitFiles.contains(resolvedLocal)) { | ||
| qCDebug(appLog) << "Skipping backup for explicitly opened file:" << localPath; | ||
| continue; |
There was a problem hiding this comment.
🟡 Medium · Restored tabs lose window separation
When all saved records in the first window match explicitly opened files and a later saved window has records to restore, recoverFile skips the first window's records before updating windowIndex, so the first later-window record initializes the index without creating a window and its tabs are added to the supplied window alongside the explicitly opened files.
Update the saved window index and create the corresponding window before skipping an explicitly opened record.
Also at src/startmanager.cpp:429.
Prompt for AI agents
In `src/startmanager.cpp` at line 428:
**Restored tabs lose window separation**
When all saved records in the first window match explicitly opened files and a later saved window has records to restore, `recoverFile` skips the first window's records before updating `windowIndex`, so the first later-window record initializes the index without creating a window and its tabs are added to the supplied window alongside the explicitly opened files.
Update the saved window index and create the corresponding window before skipping an explicitly opened record.
Also at `src/startmanager.cpp:429`.| for (const QString &f : files) { | ||
| resolvedFiles << Utils::getFilePath(f); | ||
| } | ||
| recoverFile(window, resolvedFiles); |
There was a problem hiding this comment.
🟡 Medium · Recovery opens duplicate tabs
When a second openFilesInTab request arrives during the first request's 50 ms delay and includes a file with a saved backup, openFilesInTab opens the second request's file immediately, but the first request's delayed recovery passes only its own file list to recoverFile, which restores the second file's backup as another tab.
Pass recovery the combined list of files opened by requests received before the delayed recovery runs.
Prompt for AI agents
In `src/startmanager.cpp` at line 655:
**Recovery opens duplicate tabs**
When a second `openFilesInTab` request arrives during the first request's 50 ms delay and includes a file with a saved backup, `openFilesInTab` opens the second request's file immediately, but the first request's delayed recovery passes only its own file list to `recoverFile`, which restores the second file's backup as another tab.
Pass recovery the combined list of files opened by requests received before the delayed recovery runs.
fix: skip backup recovery for explicitly opened 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
whose localPath matches any explicitly requested file path
recoverFile() so session recovery skips already-requested files
do not need dedup are unaffected
Log: fix invalid character warning when opening txt from zip archive
Influence:
same file, verify no "invalid character" warning appears
explicitly opened
fix: 跳过显式打开文件的备份恢复
txt 时同时出现备份标签页(含 NUL 字节)和真实文件标签页
请求文件路径匹配的备份记录
恢复跳过已请求打开的文件
Log: 修复从压缩包打开 txt 文件时提示无效字符的问题
Influence:
PMS: BUG-379437
Summary by Sourcery
Skip recovery of backups that correspond to files being explicitly opened to avoid duplicate tabs and invalid-character warnings.
Bug Fixes:
Enhancements: