@@ -141,36 +141,40 @@ public T context() {
141
141
*/
142
142
private static class Configuration {
143
143
private final Kind <?>[] kinds ;
144
- private final boolean singleDirectory ;
144
+ private final boolean watchFileTree ;
145
145
146
146
public Configuration () {
147
147
this (new Kind <?>[0 ], new Modifier [0 ]);
148
148
}
149
149
150
150
public Configuration (Kind <?>[] kinds , Modifier [] modifiers ) {
151
151
// Extract only the relevant information from `modifiers`
152
- var fileTree = false ;
152
+ var watchFileTree = false ;
153
153
for (var m : modifiers ) {
154
- fileTree |= m == ExtendedWatchEventModifier .FILE_TREE ;
154
+ watchFileTree |= m == ExtendedWatchEventModifier .FILE_TREE ;
155
155
}
156
156
157
157
this .kinds = Arrays .copyOf (kinds , kinds .length );
158
- this .singleDirectory = ! fileTree ;
158
+ this .watchFileTree = watchFileTree ;
159
159
}
160
160
161
161
/**
162
162
* Tests if an event should be ignored by a watch key with this
163
163
* configuration. This is the case when one of the following is true:
164
164
* (a) the watch key isn't configured to watch events of the given
165
- * {@code kind}; (b) the watch key is configured to watch only the root
166
- * level of a file tree , but the given {@code context} (a {@code Path})
167
- * points to a non-root level .
165
+ * {@code kind}; (b) the watch key is configured to watch only a single
166
+ * directory , but the given {@code context} (a {@code Path}) points to a
167
+ * file in a subdirectory .
168
168
*/
169
169
public boolean ignore (Kind <?> kind , @ Nullable Object context ) {
170
170
for (var k : kinds ) {
171
171
if (k == kind ) {
172
- return singleDirectory &&
173
- context instanceof Path && ((Path ) context ).getNameCount () > 1 ;
172
+ if (watchFileTree ) {
173
+ return false ;
174
+ } else { // Watch a single directory
175
+ return context instanceof Path &&
176
+ ((Path ) context ).getNameCount () > 1 ; // File in subdirectory
177
+ }
174
178
}
175
179
}
176
180
return true ;
0 commit comments