Skip to content

Commit 0798c8d

Browse files
authored
GH-8659: Fix WatchService to react for renames
Fixes #8659 * GH-8659: Updating the documentation as requested * GH-8659: Fixes requested after coder review **Cherry-pick to `6.1.x`, `6.0.x` & `5.5.x`**
1 parent 019e96c commit 0798c8d

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

spring-integration-file/src/main/java/org/springframework/integration/file/FileReadingMessageSource.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
* @author Gary Russell
9494
* @author Artem Bilan
9595
* @author Steven Pearce
96+
* @author Patryk Ziobron
9697
*/
9798
public class FileReadingMessageSource extends AbstractMessageSource<File> implements ManageableLifecycle {
9899

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

535536
if (StandardWatchEventKinds.ENTRY_DELETE.equals(event.kind())) {
537+
Path filePath = file.toPath();
538+
if (this.pathKeys.containsKey(filePath)) {
539+
WatchKey watchKey = this.pathKeys.remove(filePath);
540+
watchKey.cancel();
541+
}
536542
if (getFilter() instanceof ResettableFileListFilter<File> resettableFileListFilter) {
537543
resettableFileListFilter.remove(file);
538544
}
@@ -554,7 +560,7 @@ private void processFilesFromNormalEvent(Set<File> files, File parentDir, WatchE
554560
}
555561
else {
556562
logger.debug(() -> "A file [" + file + "] for the event [" + event.kind() +
557-
"] doesn't exist. Ignored.");
563+
"] doesn't exist. Ignored. Maybe DELETE event is not watched ?");
558564
}
559565
}
560566
}

src/reference/asciidoc/file.adoc

+5
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,11 @@ For this purpose, the `watch-events` property (`FileReadingMessageSource.setWatc
371371
With such an option, we can use one downstream flow logic for new files and use some other logic for modified files.
372372
The following example shows how to configure different logic for create and modify events in the same directory:
373373

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

0 commit comments

Comments
 (0)