Skip to content

Commit 6ed64f6

Browse files
committed
Fix issue in JDKFileWatch that the wrong division of root/relative path was reported
1 parent 0169be7 commit 6ed64f6

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

src/main/java/engineering/swat/watch/impl/jdk/JDKFileWatch.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,9 @@ public JDKFileWatch(Path file, Executor exec,
6161
assert !parent.equals(file);
6262

6363
this.internal = new JDKDirectoryWatch(parent, exec, (w, e) -> {
64-
if (e.getKind() == WatchEvent.Kind.OVERFLOW) {
65-
var overflow = new WatchEvent(WatchEvent.Kind.OVERFLOW, file);
66-
eventHandler.accept(w, overflow);
67-
}
68-
if (fileName.equals(e.getRelativePath())) {
69-
eventHandler.accept(w, e);
64+
var kind = e.getKind();
65+
if (kind == WatchEvent.Kind.OVERFLOW || e.getRelativePath().equals(fileName)) {
66+
eventHandler.accept(w, new WatchEvent(kind, file));
7067
}
7168
}, eventFilter);
7269

src/test/java/engineering/swat/watch/SingleFileTests.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,11 @@ void memorylessRescanOnOverflow() throws IOException, InterruptedException {
143143
try (var watch = startWatchAndTriggerOverflow(Approximation.ALL, bookkeeper)) {
144144
Thread.sleep(TestHelper.SHORT_WAIT.toMillis());
145145

146-
var fileName = watch.getPath().getFileName();
147-
var parent = watch.getPath().getParent();
148-
149-
await("Overflow should trigger created event for `" + fileName + "`")
150-
.until(() -> bookkeeper.events().kind(CREATED).rootPath(parent).relativePath(fileName).any());
146+
var path = watch.getPath();
147+
await("Overflow should trigger created event for `" + path + "`")
148+
.until(() -> bookkeeper.events().kind(CREATED).rootPath(path).any());
151149
await("Overflow shouldn't trigger created events for other files")
152-
.until(() -> bookkeeper.events().kind(CREATED).rootPath(parent).relativePathNot(fileName).none());
150+
.until(() -> bookkeeper.events().kind(CREATED).rootPathNot(path).none());
153151
await("Overflow shouldn't trigger modified or deleted events")
154152
.until(() -> bookkeeper.events().kind(MODIFIED, DELETED).none());
155153
await("Overflow should be visible to user-defined event handler")

0 commit comments

Comments
 (0)