Skip to content

Conversation

@boenrobot
Copy link
Contributor

@boenrobot boenrobot commented Oct 21, 2025

Replace ReadDirectoryChangesW with ReadDirectoryChangesExW, out of which the FileAttributes can tell if a file or folder is being created/modified/deleted.

This raises the minimum required Windows version to Windows 10, as this is where ReadDirectoryChangesExW was introduced.

Fixes #261

};
}
match cur_entry.Action {
FILE_ACTION_RENAMED_OLD_NAME => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also rolled the FILE_ACTION_RENAMED_OLD_NAME into the match... Because I can't see any reason it shouldn't be in it already. Was there a good reason that I'm unaware of? If so, I can revert this part.

Copy link
Member

@JohnTitor JohnTitor Jan 11, 2026

Choose a reason for hiding this comment

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

I also don't see any reason and I'm ok with the current :)

@boenrobot boenrobot marked this pull request as draft October 21, 2025 12:40
…ich the FileAttributes can tell if a file or folder is being created/modified/deleted.

This raises the minimum required Windows version to Windows 10, as this is where ReadDirectoryChangesExW was introduced.
@boenrobot
Copy link
Contributor Author

boenrobot commented Oct 21, 2025

As per @JohnTitor in #261, I made it backwards compatible for older versions of Windows too, with a one time runtime check (the results of which are passed around). Did so by effectively duplicating handle_event (into handle_extended_event). I'm sure there's portions of the code that can be made more DRY, but then again, it might be less error prone to have to keep up to date two copies, and maybe eventually drop the older one.

…le (Windows versions earlier than 10).

Checked dynamically once at server creation and passed along to the ReadData.
Comment on lines +350 to +358
if ret == 0 {
// error reading. retransmute request memory to allow drop.
// Because of the error, ownership of the `overlapped` alloc was not passed
// over to `ReadDirectoryChangesExW`.
// So we can claim ownership back.
let _overlapped = Box::from_raw(overlapped);
let request = Box::from_raw(request);
ReleaseSemaphore(request.data.complete_sem, 1, ptr::null_mut());
}
Copy link
Member

Choose a reason for hiding this comment

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

I think it could fail silently, right? If so, the watched paths are silently ignored and it may cause some confusion. Some form of logging would be nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there some backend independent logging I could hook into? I don't think it's wise to add one only for windows.

Copy link
Member

Choose a reason for hiding this comment

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

You can use the log crate, we've already used it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nevermind... I saw log::error!()... I'll use that.

_ => {
// Some unidentified error occurred, log and unwatch the directory, then return.
log::error!(
"unknown error in ReadDirectoryChangesExW for directory {}: {}",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this line handles errors already... No need to log the error twice.

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.

CreateKind | RemoveKind | ModifyKind seem to always be Any most of the time?

2 participants