Skip to content

Commit bb57f08

Browse files
pziobronartembilan
authored andcommitted
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`** (cherry picked from commit 0798c8d) # Conflicts: # spring-integration-file/src/main/java/org/springframework/integration/file/FileReadingMessageSource.java
1 parent 6228eaa commit bb57f08

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
* @author Gary Russell
9191
* @author Artem Bilan
9292
* @author Steven Pearce
93+
* @author Patryk Ziobron
9394
*/
9495
public class FileReadingMessageSource extends AbstractMessageSource<File> implements ManageableLifecycle {
9596

@@ -505,6 +506,11 @@ private void processFilesFromNormalEvent(Set<File> files, File parentDir, WatchE
505506
logger.debug(() -> "Watch event [" + event.kind() + "] for file [" + file + "]");
506507

507508
if (StandardWatchEventKinds.ENTRY_DELETE.equals(event.kind())) {
509+
Path filePath = file.toPath();
510+
if (this.pathKeys.containsKey(filePath)) {
511+
WatchKey watchKey = this.pathKeys.remove(filePath);
512+
watchKey.cancel();
513+
}
508514
if (getFilter() instanceof ResettableFileListFilter) {
509515
((ResettableFileListFilter<File>) getFilter()).remove(file);
510516
}
@@ -526,7 +532,7 @@ private void processFilesFromNormalEvent(Set<File> files, File parentDir, WatchE
526532
}
527533
else {
528534
logger.debug(() -> "A file [" + file + "] for the event [" + event.kind() +
529-
"] doesn't exist. Ignored.");
535+
"] doesn't exist. Ignored. Maybe DELETE event is not watched ?");
530536
}
531537
}
532538
}

src/reference/asciidoc/file.adoc

Lines changed: 5 additions & 0 deletions
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)