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 1 commit
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 @@ -533,6 +533,10 @@ 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())) {
if (this.pathKeys.containsKey(file.toPath())) {
WatchKey watchKey = this.pathKeys.remove(file.toPath());
watchKey.cancel();
}
if (getFilter() instanceof ResettableFileListFilter<File> resettableFileListFilter) {
resettableFileListFilter.remove(file);
}
Expand All @@ -554,7 +558,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
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ public boolean remove(File fileToRemove) {
File top2 = File.createTempFile("tmp", null, this.rootDir);
File foo2 = File.createTempFile("foo", ".txt", this.foo);
File bar2 = File.createTempFile("bar", ".txt", this.bar);
File baz = new File(this.foo, "baz");
baz.mkdir();
File baz1 = File.createTempFile("baz", ".txt", baz);
File bazA = new File(this.foo, "bazA");
bazA.mkdir();
File baz1 = File.createTempFile("baz", ".txt", bazA);
files = scanner.listFiles(this.rootDir);
int n = 0;
Set<File> accum = new HashSet<>(files);
Expand Down Expand Up @@ -170,7 +170,7 @@ public boolean remove(File fileToRemove) {

assertThat(accum).containsAll(filesForOverflow);

File baz2 = File.createTempFile("baz2", ".txt", baz);
File baz2 = File.createTempFile("baz2", ".txt", bazA);

n = 0;
while (n++ < 300 && accum.size() < 605) {
Expand Down Expand Up @@ -207,7 +207,19 @@ public boolean remove(File fileToRemove) {

assertThat(removeFileLatch.await(10, TimeUnit.SECONDS)).isTrue();

File baz3 = File.createTempFile("baz3", ".txt", baz);
File bazB = new File(this.foo, "bazB");
bazA.renameTo(bazB);
File baz3 = File.createTempFile("baz3", ".txt", bazB);

while (n++ < 300 && files.size() < 1) {
Thread.sleep(100);
files = scanner.listFiles(this.rootDir);
accum.addAll(files);
}

assertThat(files).hasSize(1).contains(baz3);

File baz4 = File.createTempFile("baz4", ".txt", bazB);

n = 0;
Message<File> fileMessage = null;
Expand All @@ -216,7 +228,7 @@ public boolean remove(File fileToRemove) {
}

assertThat(fileMessage).isNotNull();
assertThat(fileMessage.getPayload()).isEqualTo(baz3);
assertThat(fileMessage.getPayload()).isEqualTo(baz4);
assertThat(fileMessage.getHeaders().get(FileHeaders.RELATIVE_PATH, String.class))
.startsWith(TestUtils.applySystemFileSeparator("foo/baz/"));

Expand Down