Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,22 @@ void watch(Set<Path> paths, Runnable action) {
this.thread = new WatcherThread();
this.thread.start();
}
this.thread.register(new Registration(paths, action));
this.thread.register(new Registration(resolveSymlinks(paths), action));
}
catch (IOException ex) {
throw new UncheckedIOException("Failed to register paths for watching: " + paths, ex);
}
}
}

private Set<Path> resolveSymlinks(Set<Path> paths) throws IOException {
Set<Path> result = new HashSet<>();
for (Path path : paths) {
result.add(Files.isSymbolicLink(path) ? Files.readSymbolicLink(path) : path);
}
return result;
}

@Override
public void close() throws IOException {
synchronized (this.lock) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ void shouldWatchFile(@TempDir Path tempDir) throws Exception {
callback.expectChanges();
}

@Test
void shouldFollowSymlink(@TempDir Path tempDir) throws Exception {
Path realFile = tempDir.resolve("realFile.txt");
Path symLink = tempDir.resolve("symlink.txt");
Files.createFile(realFile);
Files.createSymbolicLink(symLink, realFile);
WaitingCallback callback = new WaitingCallback();
this.fileWatcher.watch(Set.of(symLink), callback);
Files.writeString(realFile, "Some content");
callback.expectChanges();
}

@Test
void shouldIgnoreNotWatchedFiles(@TempDir Path tempDir) throws Exception {
Path watchedFile = tempDir.resolve("watched.txt");
Expand Down