Skip to content

GH-8659: Fix the WatchServiceDirectoryScanner to detect new file afte… #8662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
* @author Gary Russell
* @author Artem Bilan
* @author Steven Pearce
* @author Patryk Ziobron
*/
public class FileReadingMessageSource extends AbstractMessageSource<File> implements ManageableLifecycle {

Expand Down Expand Up @@ -533,6 +534,11 @@ private void processFilesFromNormalEvent(Set<File> files, File parentDir, WatchE
logger.debug(() -> "Watch event [" + event.kind() + "] for file [" + file + "]");

if (StandardWatchEventKinds.ENTRY_DELETE.equals(event.kind())) {
Path filePath = file.toPath();
if (this.pathKeys.containsKey(filePath)) {
WatchKey watchKey = this.pathKeys.remove(filePath);
watchKey.cancel();
}
if (getFilter() instanceof ResettableFileListFilter<File> resettableFileListFilter) {
resettableFileListFilter.remove(file);
}
Expand All @@ -554,7 +560,7 @@ private void processFilesFromNormalEvent(Set<File> files, File parentDir, WatchE
}
else {
logger.debug(() -> "A file [" + file + "] for the event [" + event.kind() +
"] doesn't exist. Ignored.");
"] doesn't exist. Ignored. Maybe DELETE event is not watched ?");
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/reference/asciidoc/file.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,11 @@ For this purpose, the `watch-events` property (`FileReadingMessageSource.setWatc
With such an option, we can use one downstream flow logic for new files and use some other logic for modified files.
The following example shows how to configure different logic for create and modify events in the same directory:

It is worth mentioning that the `ENTRY_DELETE` event is involved in the rename operation of sub-directory of the watched directory.
More specifically, `ENTRY_DELETE` event, which is related to the previous directory name, precedes `ENTRY_CREATE` event which notifies about the new (renamed) directory.
On some operating systems (like Windows), the `ENTRY_DELETE` event has to be registered to deal with that situation.
Otherwise, renaming watched sub-directory in the File Explorer could result in the new files not being detected in that sub-directory.

====
[source,xml]
----
Expand Down