Skip to content

fix: skip backup recovery for explicitly opened files - #736

Draft
dengzhongyuan365-dev wants to merge 1 commit into
linuxdeepin:masterfrom
dengzhongyuan365-dev:agent/bugfix/379437
Draft

dengzhongyuan365-dev wants to merge 1 commit into
linuxdeepin:masterfrom
dengzhongyuan365-dev:agent/bugfix/379437

Conversation

@dengzhongyuan365-dev

@dengzhongyuan365-dev dengzhongyuan365-dev commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

fix: skip backup recovery for explicitly opened files

  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

Summary by Sourcery

Skip recovery of backups that correspond to files being explicitly opened to avoid duplicate tabs and invalid-character warnings.

Bug Fixes:

  • Prevent session backup recovery from opening duplicate tabs for files explicitly requested by the user, including files opened from archives.

Enhancements:

  • Extend backup recovery to account for explicitly opened file paths while preserving existing behavior for other callers.

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
@dengzhongyuan365-dev
dengzhongyuan365-dev marked this pull request as draft November 17, 2026 15:21
@deepin-ci-robot

Copy link
Copy Markdown

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai

sourcery-ai Bot commented Nov 17, 2026

Copy link
Copy Markdown

Reviewer's Guide

API

Add an optional explicit-file list to the recovery interface so callers can request deduplication without changing existing callers.

  • src/startmanager.h L60-63

Uses of the API

Resolve the requested file paths in the delayed-open callback and pass them to recovery before adding the requested tab.

  • src/startmanager.cpp L651-655

Implementation

Update the recovery function signature and skip backup records whose resolved local path matches an explicitly requested file.

  • src/startmanager.cpp L330, L423-431

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/startmanager.cpp
QString resolvedLocal = Utils::getFilePath(localPath);
if (explicitFiles.contains(resolvedLocal)) {
qCDebug(appLog) << "Skipping backup for explicitly opened file:" << localPath;
continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 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`.

Comment thread src/startmanager.h
* @return 恢复完成的文件数量
*/
int recoverFile(Window *window);
int recoverFile(Window *window, const QStringList &explicitFiles = QStringList());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 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`.

Comment thread src/startmanager.cpp
QString resolvedLocal = Utils::getFilePath(localPath);
if (explicitFiles.contains(resolvedLocal)) {
qCDebug(appLog) << "Skipping backup for explicitly opened file:" << localPath;
continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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`.

Comment thread src/startmanager.cpp
for (const QString &f : files) {
resolvedFiles << Utils::getFilePath(f);
}
recoverFile(window, resolvedFiles);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants