Skip to content

Commit 936216c

Browse files
committed
Add fix
1 parent 00e1577 commit 936216c

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

server/src/main/java/org/elasticsearch/common/file/AbstractFileWatchingService.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
import java.nio.file.attribute.BasicFileAttributes;
2929
import java.nio.file.attribute.FileTime;
3030
import java.util.HashMap;
31-
import java.util.HashSet;
3231
import java.util.List;
3332
import java.util.Map;
3433
import java.util.Set;
3534
import java.util.concurrent.ExecutionException;
35+
import java.util.stream.Collectors;
3636
import java.util.stream.Stream;
3737

3838
/**
@@ -238,16 +238,16 @@ protected final void watcherThread() {
238238
key.reset();
239239

240240
if (key == settingsDirWatchKey) {
241-
// there may be multiple events for the same file - we only want to re-read once
242-
Set<Path> processedFiles = new HashSet<>();
243-
for (WatchEvent<?> e : events) {
244-
Path fullFile = settingsDir.resolve(e.context().toString());
245-
if (Files.isSymbolicLink(fullFile)) {
241+
Set<Path> changedPaths = events.stream()
242+
.map(event -> settingsDir.resolve(event.context().toString()))
243+
.collect(Collectors.toSet());
244+
for (var changedPath : changedPaths) {
245+
// If a symlink changed in the settings directory, it could be linked to other symlinks so reprocess all files
246+
if (Files.isSymbolicLink(changedPath)) {
246247
reprocessAllChangedFilesInSettingsDir();
247-
} else if (processedFiles.add(fullFile)) {
248-
if (fileChanged(fullFile)) {
249-
process(fullFile);
250-
}
248+
break;
249+
} else if (fileChanged(changedPath)) {
250+
process(changedPath);
251251
}
252252
}
253253
} else if (key == configDirWatchKey) {

0 commit comments

Comments
 (0)