Skip to content

fix: update cache when watching box files#5790

Open
stevenjoezhang wants to merge 1 commit into
masterfrom
fix/watch-cache-status
Open

fix: update cache when watching box files#5790
stevenjoezhang wants to merge 1 commit into
masterfrom
fix/watch-cache-status

Conversation

@stevenjoezhang

Copy link
Copy Markdown
Member

What does it do?

Issue resolved: #5747

Screenshots

Pull request tasks

  • Add test cases for the changes.
  • Passed the CI test.

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

How to test

git clone -b fix/watch-cache-status https://github.com/hexojs/hexo.git
cd hexo
npm install
npm test

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 addresses #5747 by ensuring the Box watcher updates (and cleans up) the cache when files are created/changed/deleted during watch mode, preventing subsequent watch restarts from incorrectly treating previously-seen files as newly created.

Changes:

  • Use cache-based status detection (Cache.compareFile) for watch() add/change events so cache entries are created/updated during watch.
  • Remove cache entries on unlink events before processing deletes.
  • Add a regression test asserting that a watched “create” inserts cache and results in skip on a subsequent process() run.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
lib/box/index.ts Updates watch event handling to derive file status from cache and removes cache entries on unlink.
test/scripts/box/box.ts Adds/extends watch-mode tests to validate cache insertion on create and cache removal on delete.

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

Comment thread lib/box/index.ts
Comment on lines +27 to +30
interface FileStatus {
type: string;
path: string;
}
Comment thread lib/box/index.ts
Comment on lines 243 to 246
watcher.on('unlink', path => {
this._processFile(File.TYPE_DELETE, getPath(path));
const filePath = getPath(path);
this._removeFileCache(filePath).then(() => this._processFile(File.TYPE_DELETE, filePath));
});
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.

Restarting watch triggers a warning about trying to create an already existing file for posts that were created during the previous watch

2 participants