Skip to content

Fix stale parent directory sizes after subtree reindex#354

Open
wangruohui wants to merge 4 commits intozevv:masterfrom
wangruohui:update-parent
Open

Fix stale parent directory sizes after subtree reindex#354
wangruohui wants to merge 4 commits intozevv:masterfrom
wangruohui:update-parent

Conversation

@wangruohui
Copy link
Copy Markdown

Summary

This PR fixes a stale-cache issue in duc when reindexing a subtree.

Previously, if a user indexed a, then later modified files under a/b and ran duc index a/b, the subtree report for a/b was refreshed, but the cached directory entry stored in a was not. As a result, commands like duc ui a or duc ls a could still show the old size for b.

Root Cause

duc stores directory listings as serialized per-directory buffers, and parent directories cache the size of each child directory entry. Reindexing a subtree updated:

  • the subtree's own report
  • the subtree's own directory buffer

but it did not propagate the new size back into ancestor directory buffers.

That meant readers opening a still saw the old cached size for b.

Changes

This PR adds parent-buffer propagation after writing a refreshed subtree report:

  • update the immediate parent directory entry with the subtree's new exact size and devino
  • compute the size delta between the old and new subtree values
  • propagate that delta upward through ancestor directory buffers

This keeps cached parent views consistent after duc index <subtree> without forcing a full reindex of the ancestor tree.

Example

Before this change:

  1. duc index a
  2. modify files under a/b
  3. duc index a/b
  4. duc ui a

b could still show the old size inside a.

After this change, b is updated correctly in the parent view.

Copilot AI review requested due to automatic review settings March 18, 2026 16:13
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes stale cached directory sizes when reindexing a subtree by propagating updated subtree sizes into ancestor serialized directory buffers, keeping parent views consistent without a full reindex.

Changes:

  • Add helpers to split a path into parent/child and to update a child directory entry inside a parent directory buffer.
  • After writing a refreshed subtree report, update the immediate parent entry (exact size + devino) and propagate size deltas up ancestor buffers.
  • Hook the propagation into duc_index() after db_write_report().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

wangruohui and others added 2 commits March 19, 2026 00:53
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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