Skip to content

Conversation

@ssam18
Copy link

@ssam18 ssam18 commented Nov 14, 2025

Fixes #3659

Problem

The serve_header.py script wasn't detecting when directories were moved into or out of the monitored root directory. This made the development workflow less smooth when reorganizing projects while the server was running.

Root Cause

The on_any_event handler only processed 'created' and 'deleted' events for directories, but file system watchers emit a separate 'moved' event type that includes both source and destination paths.

Solution

Added handling for 'moved' events on directories by treating them as a combination of:

  • Delete operation on the source path (remove any trees that were moved out)
  • Create operation on the destination path (scan for new trees that were moved in)

This mirrors how the filesystem actually handles move operations and ensures the working tree list stays in sync.

Testing

I tested this locally by:

  1. Starting serve_header.py
  2. Moving a project directory into the monitored root → now correctly detected and added
  3. Moving a project directory out of the monitored root → now correctly detected and removed
  4. Moving directories within the monitored root → both operations handled properly

The fix maintains backward compatibility and doesn't change behavior for other event types.

@ssam18 ssam18 requested a review from nlohmann as a code owner November 14, 2025 17:15
@github-actions github-actions bot added the S label Nov 14, 2025
@ssam18
Copy link
Author

ssam18 commented Nov 14, 2025

I actually stumbled on this while working with the header server during development. I had a habit of organizing my workspace by moving project folders around, and I kept noticing that serve_header.py would not pick up the changes until I restarted it.

After looking at the code, I realized it was only listening for create and delete events, not moves. Since the watchdog library treats moves as their own event type with both src_path and dest_path, I figured the cleanest fix was to handle them explicitly rather than relying on separate delete/create events that might not always fire.

Tested it out by moving directories in and out while the server was running, and it works great now!

Fixes nlohmann#3659

I was testing serve_header.py with my local development setup and noticed
that when I moved directories into or out of the monitored root, they
weren't being picked up properly. The script would only detect create and
delete events but not move operations.

This was happening because the on_any_event handler only checked for
'created' and 'deleted' events on directories. Move events have a
separate event type 'moved' that includes both the source and destination
paths.

The fix treats a move event like a combination of delete (for the source)
and create (for the destination) - we rescan to remove any trees that were
moved out, and add the destination directory to check for new trees that
were moved in.

This should make the development workflow smoother when reorganizing
project directories while the server is running.

Signed-off-by: Samaresh Kumar Singh <[email protected]>
@ssam18 ssam18 force-pushed the fix-serve-header-move-events-issue-3659 branch from 000e2e8 to 4b8db07 Compare November 14, 2025 17:31
@coveralls
Copy link

Coverage Status

coverage: 99.191%. remained the same
when pulling 4b8db07 on ssam18:fix-serve-header-move-events-issue-3659
into 49026f7 on nlohmann:develop.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

serve_header.py doesn't process 'move' events

2 participants