GH-8659: Fix WatchService to react for renames

Fixes https://github.com/spring-projects/spring-integration/issues/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 0798c8df95)

# Conflicts:
#	spring-integration-file/src/main/java/org/springframework/integration/file/FileReadingMessageSource.java
This commit is contained in:
pziobron
2023-06-29 20:23:33 +02:00
committed by abilan
parent 794aa0a56e
commit 9a54c23955
2 changed files with 12 additions and 1 deletions

View File

@@ -90,6 +90,7 @@ import org.springframework.util.Assert;
* @author Gary Russell
* @author Artem Bilan
* @author Steven Pearce
* @author Patryk Ziobron
*/
public class FileReadingMessageSource extends AbstractMessageSource<File> implements ManageableLifecycle {
@@ -505,6 +506,11 @@ public class FileReadingMessageSource extends AbstractMessageSource<File> implem
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) {
((ResettableFileListFilter<File>) getFilter()).remove(file);
}
@@ -526,7 +532,7 @@ public class FileReadingMessageSource extends AbstractMessageSource<File> implem
}
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 ?");
}
}
}