Skip to content

Commit 4beb950

Browse files
committed
Fix issue that MODIFIED events were issued for directories when auto-handling overflows
1 parent 9744874 commit 4beb950

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/main/java/engineering/swat/watch/impl/overflows/MemorylessRescanner.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ public List<WatchEvent> getEvents() {
8989
return events;
9090
}
9191

92-
protected void addEvents(Path path, BasicFileAttributes attrs) {
92+
private void addEvents(Path path, BasicFileAttributes attrs) {
9393
events.add(newEvent(WatchEvent.Kind.CREATED, path));
94-
if (attrs.isDirectory() || attrs.size() > 0) {
94+
if (attrs.isRegularFile() && attrs.size() > 0) {
9595
events.add(newEvent(WatchEvent.Kind.MODIFIED, path));
9696
}
9797
}
9898

99-
protected WatchEvent newEvent(WatchEvent.Kind kind, Path fullPath) {
99+
private WatchEvent newEvent(WatchEvent.Kind kind, Path fullPath) {
100100
var event = new WatchEvent(kind, fullPath);
101101
return watch.relativize(event);
102102
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ void memorylessRescanOnOverflow() throws IOException, InterruptedException {
157157
await("Overflow should trigger created events")
158158
.until(nCreated::get, Predicate.isEqual(6)); // 3 directories + 3 files
159159
await("Overflow should trigger modified events")
160-
.until(nModified::get, Predicate.isEqual(5)); // 3 directories + 2 files (c.txt is still empty)
160+
.until(nModified::get, Predicate.isEqual(2)); // 2 files (c.txt is still empty)
161161
await("Overflow should be visible to user-defined event handler")
162162
.until(nOverflow::get, Predicate.isEqual(1));
163163
}

0 commit comments

Comments
 (0)