Skip to content

feat: track file close-write events - #253

Open
wangrong1069 wants to merge 4 commits into
linuxdeepin:release/snipefrom
wangrong1069:pr0824
Open

feat: track file close-write events#253
wangrong1069 wants to merge 4 commits into
linuxdeepin:release/snipefrom
wangrong1069:pr0824

Conversation

@wangrong1069

@wangrong1069 wangrong1069 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Summary by Sourcery

Track file close-write events so modified files are reindexed when writing completes.

New Features:

  • Track file close-write events and update the corresponding index entries after files are closed.

Bug Fixes:

  • Prevent stale close-write events from being processed after a file is deleted or renamed.

Enhancements:

  • Extend event dispatch and path handling to support close-write file events across mounted filesystems.

Chores:

  • Add the close-write event type and kernel event generation support.

Add tracking for file close-write events.

Log: 新增文件写关闭事件追踪
PMS: BUG-370789
Influence: 内核模块现在能够追踪文件写关闭事件,增强文件变更监控能力。
Add ACT_CLOSE_WRITE_FILE event handling to update file index when
a file is written and closed, skipping non-existent files.

添加 ACT_CLOSE_WRITE_FILE 事件处理,文件写入关闭后更新索引,
通过 make_file_record 判断文件是否存在,不存在则跳过。

Log: 添加文件写入关闭事件的索引更新处理
PMS: BUG-370789
Influence: 文件被写入并关闭后,索引将自动更新文件元数据,保证搜索结果时效性。
Wrap the cmp_event_path macro expression in parentheses to prevent
operator precedence issues when used in larger expressions.

为 cmp_event_path 宏表达式添加括号,防止在复杂表达式中使用时出现运算符优先级问题。

Log: 修复 cmp_event_path 宏缺少括号的问题
PMS: BUG-370789
Influence: 修复后宏在复杂表达式中能正确求值,避免事件路径比较逻辑错误。
As title.

Log: Bump version to 7.0.61

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

Sorry @wangrong1069, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: wangrong1069

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

@github-actions

Copy link
Copy Markdown

TAG Bot

TAG: 7.0.61
EXISTED: no
DISTRIBUTION: unstable

@sourcery-ai

sourcery-ai Bot commented Aug 24, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds support for tracking and indexing file close-write events end-to-end, from kernel monitoring and event merging through daemon handling and index updates, while refactoring server event dispatching logic for mounts and path prefixing.

Sequence diagram for file close-write indexing

sequenceDiagram
    participant Kernel as Kernel fsnotify
    participant Probe as __fput kretprobe
    participant Server as Event dispatcher
    participant Daemon as Default event handler
    participant Queue as Index job queue
    participant Index as File index manager

    Kernel->>Probe: __fput(file)
    Probe->>Probe: on___fput_ent()
    Probe->>Server: ACT_CLOSE_WRITE_FILE(path)
    Server->>Server: convert_fs_event()
    Server->>Daemon: file_close_write(path)
    Daemon->>Daemon: filter_event()
    Daemon->>Queue: update_index_delay(path)
    Queue->>Index: update_index(path)
    Index->>Index: make_file_record(path)
    alt file exists
        Index->>Index: updateDocument(path)
    else file does not exist
        Index-->>Queue: Skip update
    end
Loading

Flow diagram for close-write event merging

flowchart TD
    CloseWrite["close_write(X)"] --> NextEvent{Next event}
    NextEvent -->|delete X| RemoveClose["Remove close_write(X)"]
    NextEvent -->|rename from X| RemoveClose
    NextEvent -->|other event| Retain["Retain close_write(X)"]
    RemoveClose --> MergeFail["Merge fails for current event"]
Loading

File-Level Changes

Change Details Files
Introduce a single-path index update flow that safely refreshes a document when a file is modified and closed.
  • Add overloads of update_index_delay and update_index that accept only a file path.
  • Wire index_job_type::update handling to call the appropriate file_index_manager::update_index overload based on presence of a destination path.
  • Implement path-based index update that builds a file record, skips missing files, updates the Lucene document by FULL_PATH_FIELD, and logs success/failures.
src/daemon/include/core/base_event_handler.h
src/daemon/include/core/file_index_manager.h
src/daemon/src/core/base_event_handler.cpp
src/daemon/src/core/file_index_manager.cpp
Propagate ACT_CLOSE_WRITE_FILE events from kernel to daemon and map them to index updates while extending event name coverage.
  • Handle ACT_CLOSE_WRITE_FILE in default_event_handler::prepare_event and filter_event to convert paths and enqueue index update jobs.
  • Expand act_names to include rename-from/to, mount/unmount, and file_close_write for logging/diagnostics.
src/daemon/src/core/default_event_handler.cpp
Extend kernel event capture and merge logic to emit and correctly coalesce close-write file events.
  • Track FS_CLOSE_WRITE in fsnotify and map it to ACT_CLOSE_WRITE_FILE for regular files.
  • Define ACT_CLOSE_WRITE_FILE constant and extend action_merge_fns dispatch table.
  • Add merge rules so close-write followed by delete or rename-from remove the close-write event and either merge or fail appropriately.
  • Fix cmp_event_path macro to be fully parenthesized to avoid precedence issues.
src/kernelmod/vfs_change_consts.h
src/kernelmod/vfs_fsnotify.c
src/kernelmod/event_merge.c
Capture close-write events via kretprobe on __fput to detect writable files being closed.
  • Include fsnotify_backend.h and implement __fput entry kretprobe that filters non-writable or directory files and emits ACT_CLOSE_WRITE_FILE events.
  • Register the new __fput kretprobe in the vfs_krps array alongside existing probes.
src/kernelmod/vfs_kretprobes.c
Refactor server-side event dispatcher to treat mount/unmount as special and centralize device/mount-point resolution and path prefixing, including close-write events.
  • Simplify convert_fs_event by moving device/mount root computation after the main switch, and handling mount/unmount early with immediate mount_info updates.
  • Ensure ACT_CLOSE_WRITE_FILE follows the same src/dst handling as create/delete events, with device_id and mount-point prefixing applied.
  • Remove temporary root string management and instead use mount_point directly, including conditional prefixing only when mount_point is not '/'.
  • Tighten logging messages and casts for unsupported and unknown actions.
src/server/event-dispatcher.c

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

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