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

Support listing files in a directory Path #222

Closed
jeffdgr8 opened this issue Sep 17, 2023 · 6 comments
Closed

Support listing files in a directory Path #222

jeffdgr8 opened this issue Sep 17, 2023 · 6 comments

Comments

@jeffdgr8
Copy link
Contributor

Listing files within a directory is one of the few file APIs my library tests require that kotlinx-io doesn't currently support.

Similar API references:

@fzhinkin
Copy link
Collaborator

I see a few design options here:

  • return a list or a sequence (but Sequence is not closable);
  • support filtration by filename or by additional metadata that could be collected during the directory listing (file type, file size);
  • instead of returning some particular iterable type, pass a lambda accepting paths to a routine so that users can build whatever they want themselves (might lead to some problems with concurrent fs modification and infinite recursion via symlinks).

@fzhinkin fzhinkin added the fs label Oct 12, 2023
@jeffdgr8
Copy link
Contributor Author

My current use case in tests is fairly simple. I'm using the API to either check the number of files in a directory using the size of the file list, or to recursively delete all the contents of a directory.

The file/path list API works well for both of these requirements. An iterable sequence could also work, although it requires iterating and terminating the sequence to get the size. I would think if the underlying platform file API being used is already returning a list or array, there's probably not much value in mapping that existing collection to a sequence.

The other API options could also be useful. It might make sense to offer these filter/iterable APIs in addition to a simple file/path list API. A recursive iteration API would be especially useful for the recursive delete operation.

@StefanOltmann
Copy link

I think just returning a list of strings with the file names in the directory like java.io.File.list() does is the easiest way to get this started.

@lppedd
Copy link
Contributor

lppedd commented Nov 7, 2023

I think just returning a list of strings with the file names in the directory like java.io.File.list() does is the easiest way to get this started.

I'd say lets not force rushed solutions. Once something is in it's difficult to take out and will just clutter the API.
kotlinx-io can take Okio as a reference implementation but might try a design closer to Java NIO.
Personally the NIO API is the cleanest I've seen.

fzhinkin added a commit that referenced this issue Mar 18, 2024
fzhinkin added a commit that referenced this issue Mar 18, 2024
@fzhinkin fzhinkin self-assigned this Mar 18, 2024
fzhinkin added a commit that referenced this issue Apr 24, 2024
fzhinkin added a commit that referenced this issue May 6, 2024
@fzhinkin
Copy link
Collaborator

fzhinkin commented May 8, 2024

TL;DR: there were (and are) no signs that a proper stable FS API will be released soon (I mean in the next couple of months), so I decided to provide some API (FileSystem.list(Path): Collection) to make the library more usable.

@StefanOltmann
Copy link

I agree with this decision!

And it's unlikely that this API will change. Maybe the implementation, but FileSystem.list(Path) just makes sense.

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

No branches or pull requests

4 participants