Skip to content
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

WatchService registered directory gets deleted, but nothing happens. #72

Open
ghost opened this issue Jul 31, 2018 · 0 comments
Open

WatchService registered directory gets deleted, but nothing happens. #72

ghost opened this issue Jul 31, 2018 · 0 comments
Labels
P3 type=defect Bug, not working as expected

Comments

@ghost
Copy link

ghost commented Jul 31, 2018

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.

@cpovirk cpovirk added type=defect Bug, not working as expected P3 labels Jul 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 type=defect Bug, not working as expected
Projects
None yet
Development

No branches or pull requests

1 participant