Skip to content

Commit

Permalink
Merge pull request #9 from stevegury/master
Browse files Browse the repository at this point in the history
FileSystemWatcher, when enabling "scan for current files" also report directories.
  • Loading branch information
robertroeser committed Aug 26, 2015
2 parents 0f325b0 + 5ec546d commit ba043ff
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions src/main/java/rx/fileutils/FileSystemWatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,22 +142,13 @@ private List<WatchEvent<Path>> getEventsForCurrentFiles(Path directory) {
Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) {
events.add(new WatchEvent<Path>() {
@Override
public Kind<Path> kind() {
return ENTRY_CREATE;
}

@Override
public int count() {
return 1;
}

@Override
public Path context() {
return path;
}
});
events.add(pathToWatchEvent(path));
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult preVisitDirectory(Path path, BasicFileAttributes attrs) {
events.add(pathToWatchEvent(path));
return FileVisitResult.CONTINUE;
}
});
Expand All @@ -167,6 +158,25 @@ public Path context() {

return events;
}

private WatchEvent<Path> pathToWatchEvent(Path path) {
return new WatchEvent<Path>() {
@Override
public Kind<Path> kind() {
return ENTRY_CREATE;
}

@Override
public int count() {
return 1;
}

@Override
public Path context() {
return path;
}
};
}
}

public static class Builder {
Expand Down

0 comments on commit ba043ff

Please sign in to comment.