-
Notifications
You must be signed in to change notification settings - Fork 641
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
Directory sources #274
Directory sources #274
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
public final class Directory { | ||
|
||
/** | ||
* List all files in the given directory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
files and directories
StreamConverters.fromJavaStream(() => Files.walk(directory)) | ||
} | ||
|
||
private def allFilesFilter = new BiPredicate[Path, BasicFileAttributes] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not used
* Recursively list files in the given directory and its subdirectories. Listing is done | ||
* depth first. | ||
*/ | ||
def walk(directory: Path): Source[Path, NotUsed] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be good to expose the overloads too:
https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html#walk-java.nio.file.Path-int-java.nio.file.FileVisitOption...-
the visit options and depth seem very useful when someone would be using this API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started out with that, but then thought that it is so simple to create it yourself, so maybe more specific needs can be met by just looking at the sources of this and copying that single line of code...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think with alpakka we're targeting an "works out of the box" and "I would not look at the sources" use cases/people, so I'd really add those parameters IMHO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was rather from the not covering every conceivable use case under the sun, just the "normal" ones point of view, especially the filter which could be achieved by composition (with a bit of alloc overhead, but hey this is disk io we are talking about here).
Could you come up with a common use case for depths other than 0, which is covered by ls and all the depth (find ./
) which is covered by this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depth is pretty important to protect from entering infinite loops with symlinks to an upper directory if I remember correctly how these APIs work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I'll add it. Skipping filter though, as that can be achieved with composition.
@@ -13,7 +13,7 @@ import akka.stream.{ActorMaterializer, Materializer} | |||
|
|||
import scala.concurrent.duration._ | |||
|
|||
object FileTailSourceSpec extends { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hah funny
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
def walk(directory: Path): Source[Path, NotUsed] = { | ||
def walk(directory: Path, | ||
maxDepth: Option[Int] = None, | ||
fileVisitOptions: immutable.Seq[FileVisitOption] = Nil): Source[Path, NotUsed] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great thanks :)
Refs #272
Adds
Directory.ls
andDirectory.walk
to stream file paths from the filesystem.