Skip to content

Commit

Permalink
Skip non-existing directory when watching for changes
Browse files Browse the repository at this point in the history
Fix quarkusio#32092.
The issue was not specific to Gradle.
It was problematic with Gradle, as it was configuring the watcher on not existing directories.
  • Loading branch information
cescoffier committed Nov 2, 2023
1 parent 72d993c commit efd5a54
Showing 1 changed file with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,25 @@ private void doObserve(Collection<Watcher> watchers, long intervalMs) {
for (Watcher watcher : watchers) {
try {
Path rootPath = watcher.rootPath;
List<Path> matchingPaths = Files.walk(rootPath)
.filter(path -> hasExtension(path, watcher.fileExtension))
.collect(Collectors.toList());
List<Path> changedFiles = new ArrayList<>();
for (Path path : matchingPaths) {
long lastModifiedTime = Files.getLastModifiedTime(path).toMillis();
if (lastModifiedTime > lastModified.computeIfAbsent(path, whatever -> 0L)) {
changedFiles.add(path);
lastModified.put(path, lastModifiedTime);
}
if (!rootPath.toFile().isDirectory()) {
// Skip directory - it does not exist.
continue;
}

if (!firstRun && !changedFiles.isEmpty()) {
watcher.action.accept(changedFiles);
try (var walker = Files.walk(rootPath)) {
List<Path> matchingPaths = walker.filter(path -> hasExtension(path, watcher.fileExtension))
.collect(Collectors.toList());
List<Path> changedFiles = new ArrayList<>();
for (Path path : matchingPaths) {
long lastModifiedTime = Files.getLastModifiedTime(path).toMillis();
if (lastModifiedTime > lastModified.computeIfAbsent(path, whatever -> 0L)) {
changedFiles.add(path);
lastModified.put(path, lastModifiedTime);
}
}
if (!firstRun && !changedFiles.isEmpty()) {
watcher.action.accept(changedFiles);
}
}
} catch (IOException e) {
log.debug("Failed checking for code gen source modifications", e);
Expand Down

0 comments on commit efd5a54

Please sign in to comment.