Skip to content
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

Merged

Conversation

johanandren
Copy link
Member

Refs #272

Adds Directory.ls and Directory.walk to stream file paths from the filesystem.

Copy link
Contributor

@ktoso ktoso left a 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
Copy link
Contributor

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] {
Copy link
Contributor

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] = {
Copy link
Contributor

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

Copy link
Member Author

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...

Copy link
Contributor

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

Copy link
Member Author

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?

Copy link
Contributor

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?

Copy link
Member Author

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hah funny

Copy link
Member

@patriknw patriknw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@johanandren johanandren merged commit ef8db12 into akka:master May 8, 2017
def walk(directory: Path): Source[Path, NotUsed] = {
def walk(directory: Path,
maxDepth: Option[Int] = None,
fileVisitOptions: immutable.Seq[FileVisitOption] = Nil): Source[Path, NotUsed] = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants