Skip to content

fix: mark index changed in removeFile - #293

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/snipefrom
Johnson-zs:agent/bugfix/4c03bde1c7f4
Oct 27, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/snipefrom
Johnson-zs:agent/bugfix/4c03bde1c7f4

Conversation

@Johnson-zs

@Johnson-zs Johnson-zs commented Oct 27, 2026 •

Copy link
Copy Markdown

Root Cause Analysis

removeFile() in src/index/task/taskhandler.cpp deleted index documents via writer->deleteDocuments(term) but only called reporter->increment(), missing reporter->markIndexChanged(). This left indexChanged=false, so TaskManager::updateIndexStatusOnSuccess() skipped saveLastUpdateTime() after file deletion, while the indexStatusChanged signal was still emitted unconditionally — the UI refreshed but the index update time stayed unchanged. Sibling functions updateFile(), cleanupIndexs(), and removeDirectoryIndex() all correctly call markIndexChanged(); removeFile() is the only one that omits it (introduced missing in migration commit 8d481bc). Key evidence: taskhandler.cpp:466-468 (the omission), taskmanager.cpp:1050-1058 (the skip logic), demo verification confirmed indexChanged=false before fix and true after.

Fix

Add reporter->markIndexChanged() in removeFile(), after writer->deleteDocuments(term) and before reporter->increment(), matching the pattern used by updateFile() and removeDirectoryIndex(). A single-line change, fully consistent with the stage-2 analysis report's recommended root-cause fix (section 10).

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • The change adds a single markIndexChanged() call inside the existing if (reporter) block of removeFile(). markIndexChanged() only sets m_indexChanged = true (taskhandler.cpp:201) with no side effects; no signature, public member, or call-site change.
  • The target lines originate from migration commit 8d481bc (one-time migration), not a prior bug fix — this change does not revert any historical fix. Only 2 callers (taskhandler.cpp:1322, :1327), both ≤5 references, both compatible: the directory-deletion path already marks indexChanged via removeDirectoryIndex() (idempotent, no conflict); the file-deletion path is the intended fix target.

Business Impact Scope

Affects the file index deletion module: deleting files/directories from the index and refreshing index status. Callers RemoveFileListHandler (taskhandler.cpp:1322 directory path, :1327 file path) map to the user scenario where deleting a file in the desktop should refresh the dde-file-manager index "update time". After the fix, file deletion correctly triggers saveLastUpdateTime() so the timestamp refreshes; directory deletion remains correct (already marked).

Verification Suggestion

Verify: (1) delete a single file → index "update time" refreshes; (2) delete a directory → update time still refreshes (regression); (3) batch file deletion → no regression. The autotests/index/test_taskhandler_withindex.cpp:189 test covers the removeFile() call path but only asserts SUCCEED() (no indexChanged assertion), so it will not break.


根因分析

src/index/task/taskhandler.cpp 中的 removeFile() 通过 writer->deleteDocuments(term) 删除索引文档,但只调用了 reporter->increment(),遗漏了 reporter->markIndexChanged()。这导致 indexChanged=false,TaskManager::updateIndexStatusOnSuccess() 在删除文件后跳过 saveLastUpdateTime(),而 indexStatusChanged 信号仍无条件发射——界面刷新但索引更新时间不变。同文件 updateFile()、cleanupIndexs()、removeDirectoryIndex() 均正确调用了 markIndexChanged(),唯独 removeFile() 遗漏(迁移 commit 8d481bc 引入时即缺失)。关键证据:taskhandler.cpp:466-468(遗漏点)、taskmanager.cpp:1050-1058(跳过逻辑)、demo 验证确认修复前 indexChanged=false、修复后 true。

修复方案

在 removeFile() 中,于 writer->deleteDocuments(term) 之后、reporter->increment() 之前添加 reporter->markIndexChanged(),与 updateFile()、removeDirectoryIndex() 保持一致。单行改动,与阶段 2 分析报告第十节推荐的根因层方案完全一致。

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • 改动仅在 removeFile() 的 if (reporter) 块内添加一行 markIndexChanged() 调用。markIndexChanged() 仅设置 m_indexChanged=true(taskhandler.cpp:201),无副作用;不修改函数签名、公开成员或调用点。
  • 目标行源自迁移 commit 8d481bc(一次性迁移产物),非历史修复——本次改动不撤销任何已有修复。仅 2 处调用者(taskhandler.cpp:1322、:1327),均兼容:删除目录路径已通过 removeDirectoryIndex() 标记 indexChanged(幂等无冲突);删除文件路径为修复目标。

业务影响范围

影响文件索引删除模块:删除文件/目录时从索引移除文档并更新索引状态。调用者 RemoveFileListHandler(taskhandler.cpp:1322 目录路径、:1327 文件路径)对应用户在桌面删除文件后应刷新 dde-file-manager 索引"更新时间"的场景。修复后删除文件正确触发 saveLastUpdateTime(),时间戳刷新;删除目录保持正确(已标记)。

验证建议

验证:(1) 删除单个文件 → 索引"更新时间"刷新;(2) 删除目录 → 更新时间仍刷新(回归);(3) 批量删除文件 → 无回归。autotests/index/test_taskhandler_withindex.cpp:189 测试覆盖 removeFile() 调用路径,但仅断言 SUCCEED()(无 indexChanged 断言),不会因本次改动失败。

Summary by Sourcery

Bug Fixes:

  • Ensure file deletions mark the index as changed so the index update timestamp is saved and refreshed correctly.

1. Root cause: removeFile() deleted index documents but did not call
   reporter->markIndexChanged(), leaving indexChanged=false, causing
   taskmanager to skip saveLastUpdateTime after file deletion
2. Fix: add reporter->markIndexChanged() after deleteDocuments, before
   increment, matching updateFile and removeDirectoryIndex pattern
3. Impact: deleting files now correctly refreshes index update time;
   RemoveFileListHandler directory path is idempotent (already marked)

Log: Fix index update time not refreshing after file deletion

Influence:
1. Test file deletion triggers index status update time refresh
2. Test directory deletion still refreshes index update time
3. Verify no regression on batch file removal operations

fix: 修复删除文件后索引更新时间未刷新

1. 根因:removeFile() 删除索引文档后未调用 markIndexChanged(),
   导致 indexChanged 为 false,taskmanager 跳过 saveLastUpdateTime
2. 方案:在 deleteDocuments 之后、increment 之前添加
   markIndexChanged() 调用,与 updateFile/removeDirectoryIndex 一致
3. 影响:删除文件后索引更新时间正确刷新;删除目录路径幂等无冲突

Log: 修复删除文件后文件索引更新时间不刷新的问题

Influence:
1. 测试删除文件后索引状态更新时间是否刷新
2. 测试删除目录后索引更新时间是否刷新
3. 验证批量删除文件操作无回归

PMS: BUG-380553
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Johnson-zs

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 Oct 27, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds the missing index-change notification to removeFile(), ensuring file deletions trigger saveLastUpdateTime() while preserving existing directory and batch deletion behavior.

Sequence diagram for file deletion index status update

sequenceDiagram
    participant RemoveFileListHandler
    participant removeFile
    participant IndexWriter
    participant Reporter
    participant TaskManager
    participant IndexStatus

    RemoveFileListHandler->>removeFile: removeFile(context, path, writer, reporter)
    removeFile->>IndexWriter: deleteDocuments(term)
    removeFile->>Reporter: markIndexChanged()
    removeFile->>Reporter: increment()
    TaskManager->>Reporter: indexChanged()
    alt index changed
        TaskManager->>IndexStatus: saveLastUpdateTime()
    end
Loading

File-Level Changes

Change Details Files
Record index mutations when removing a file so successful deletion updates the stored index timestamp.
  • Call markIndexChanged() after deleting the file’s index documents and before incrementing the reporter.
  • Align removeFile() with the existing mutation-reporting behavior of related index update and removal paths.
src/index/task/taskhandler.cpp

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 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/index/task/taskhandler.cpp" line_range="468" />
<code_context>
         TermPtr term = newLucene<Term>(context.profile().pathField(), path.toStdWString());
         writer->deleteDocuments(term);
         if (reporter) {
+            reporter->markIndexChanged();
             reporter->increment();
         }
</code_context>
<issue_to_address>
**No-op deletion advances timestamp**

When a removal request names a path with no indexed document, `removeFile()` calls `markIndexChanged()` after `deleteDocuments()` matches nothing, so `RemoveFileListHandler` returns `indexChanged=true` and `TaskManager::updateIndexStatusOnSuccess()` saves a new update time for an unchanged index.

Mark the index changed only when `deleteDocuments()` removes at least one document.
</issue_to_address>

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

TermPtr term = newLucene<Term>(context.profile().pathField(), path.toStdWString());
writer->deleteDocuments(term);
if (reporter) {
reporter->markIndexChanged();

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 · No-op deletion advances timestamp

When a removal request names a path with no indexed document, removeFile() calls markIndexChanged() after deleteDocuments() matches nothing, so RemoveFileListHandler returns indexChanged=true and TaskManager::updateIndexStatusOnSuccess() saves a new update time for an unchanged index.

Mark the index changed only when deleteDocuments() removes at least one document.

Prompt for AI agents
In `src/index/task/taskhandler.cpp` at line 468:

**No-op deletion advances timestamp**

When a removal request names a path with no indexed document, `removeFile()` calls `markIndexChanged()` after `deleteDocuments()` matches nothing, so `RemoveFileListHandler` returns `indexChanged=true` and `TaskManager::updateIndexStatusOnSuccess()` saves a new update time for an unchanged index.

Mark the index changed only when `deleteDocuments()` removes at least one document.

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 100 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交在 removeFile 函数中补充了 reporter->markIndexChanged() 调用,确保文件删除后正确标记索引变更状态。变更仅新增一行代码,语法正确、逻辑合理、无安全风险。四维度均为满分,AI 分析、启发式扫描、OCR 审查三者结论一致,未发现问题。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: []


💡 改进建议代码示例


本报告由 AI 代码审查工具自动生成

@Johnson-zs

Copy link
Copy Markdown
Author

/forcemerge

@deepin-bot
deepin-bot Bot merged commit 0a3e2ef into linuxdeepin:develop/snipe Oct 27, 2026
17 checks passed
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