google / google/jimfs

WatchService registered directory gets deleted, but nothing happens.

Open
#72 0 comments 2 reactions 0 assignees View on GitHub
P3 type=defect
Dominant language
Java
Stars
2.6k
Forks
296
Avg merge
9m
Merged PRs (30d)
7

Description

```
FileSystem fs = Jimfs.newFileSystem(Configuration.unix());
Path data = fs.getPath("/data");
Files.createDirectory(data);

watcher = data.getFileSystem().newWatchService();
Thread watcherThread = new Thread(() -> {
WatchKey key;
try {
key = watcher.take(); // will be stuck here
while (key != null) {
for (WatchEvent event : key.pollEvents()) {
System.out.printf("event of type: %s received for file: %s\n", event.kind(), event.context());
}
boolean isValid = key.reset();
}
} catch (Exception e) {
e.printStackTrace();
}
}, "CustomWatcher");
watcherThread.start();
data.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);

Files.deleteIfExists(data);
```
When the registered directory gets deleted nothing happens at all but when using the default file system `WatchService.take()` actually stops waiting and the WatchKey for the registered directory gets invalidated.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.