Conversation
Yes,
We can use systhreads for things that uring doesn't handle. We'll probably need to do that anyway for stuff like |
|
|
Thanks both for the comments :))
Yep, this is also exposed in
Forgot this was an option, I'll have a go!
My understanding is that an There's also https://github.com/ocaml-multicore/eio#design-note-capabilities for some more context on this design.
Yep returning the kinds makes sense. Maybe following the layout of type dirent = {
kind : kind;
name : string;
}
and kind = [ `Unknown | `Dir | `File ... ]
Great point, I'll see what's available in the backend APIs to make this possible :)) |
|
Given: let cwd = Eio.Stdenv.cwd env in
Eio.Dir.read_dir cwd "path/to/foo"will the result be |
|
Currently it would be |
I just copied Rust's name for it (https://docs.rs/cap-std/0.22.1/cap_std/fs/struct.Dir.html). They have e.g. impl Dir {
fn read_dir<P: AsRef<Path>>(&self, path: P) -> Result<ReadDir>The Eio API also matches the POSIX one (e.g. So the idea is that a |
|
I pushed a commit which tries to use systhreads now they're fixed in OCaml trunk. It's meant to generate a discussion about how best to use them to provide non-blocking, asynchronous versions of unsupported functions in Uring. Right now the implementation uses a new effect, Also the |
talex5
left a comment
There was a problem hiding this comment.
Thanks, it seems to work!
Also the readdir function reuses openat2 to do the necessary filesystem containment checking, but then opens a directory handle anyway which probably isn't particularly efficient.
Also, there's a possible race if a symlink appears between the check and the open. The libc and OCaml APIs for reading directories aren't very nice, and if we want to return types too then I guess we should just call getdents64 directly and avoid the whole mess.
What if a directory contains 10**12 files (see) and I don't want a list that big in memory? There should be an API to read the contents of the directory asynchronously just like we are able to read a file asynchronously
Yes, probably makes sense for the backend API to provide open_dir, etc, and for read_dir to be a wrapper around that.
Should |
talex5
left a comment
There was a problem hiding this comment.
Should Eio.Dir.read_dir try to read all directory entries or just some amount of them and the user can call it multiple times ? Or should that be a completely separate function ?
Ideally, I think there should be two functions. Maybe the backend would provide something like:
method with_dir_entries : string -> (dir_entry Seq.t -> 'a) -> 'aBut I'm happy to merge it with just this read-everything function for now. Almost everyone will just use that.
CHANGES: API changes: - `Net.accept_sub` is deprecated in favour of `accept_fork` (@talex5 ocaml-multicore/eio#240). `Fiber.fork_on_accept`, which it used internally, has been removed. - Allow short writes in `Read_source_buffer` (@talex5 ocaml-multicore/eio#239). The reader is no longer required to consume all the data in one go. Also, add `Linux_eio.Low_level.writev_single` to expose this behaviour directly. - `Eio.Unix_perm` is now `Eio.Dir.Unix_perm`. New features: - Add `Eio.Mutex` (@TheLortex @talex5 ocaml-multicore/eio#223). - Add `Eio.Buf_write` (@talex5 ocaml-multicore/eio#235). This is a buffered writer for Eio sinks, based on Faraday. - Add `Eio_mock` library for testing (@talex5 ocaml-multicore/eio#228). At the moment it has mock flows and networks. - Add `Eio_mock.Backend` (@talex5 ocaml-multicore/eio#237 ocaml-multicore/eio#238). Allows running tests without needing a dependency on eio_main. Also, as it is single-threaded, it can detect deadlocks in test code instead of just hanging. - Add `Buf_read.{of_buffer, of_string, parse_string{,_exn}, return}` (@talex5 ocaml-multicore/eio#225). - Add `<*>` combinator to `Buf_read.Syntax` (@talex5 ocaml-multicore/eio#227). - Add `Eio.Dir.read_dir` (@patricoferris @talex5 ocaml-multicore/eio#207 ocaml-multicore/eio#218 ocaml-multicore/eio#219) Performance: - Add `Buf_read` benchmark and optimise it a bit (@talex5 ocaml-multicore/eio#230). - Inline `Buf_read.consume` to improve performance (@talex5 ocaml-multicore/eio#232). Bug fixes / minor changes: - Allow IO to happen even if a fiber keeps yielding (@TheLortex @talex5 ocaml-multicore/eio#213). - Fallback for `traceln` without an effect handler (@talex5 ocaml-multicore/eio#226). `traceln` now works outside of an event loop too. - Check for cancellation when creating a non-protected child context (@talex5 ocaml-multicore/eio#222). - eio_linux: handle EINTR when calling `getrandom` (@bikallem ocaml-multicore/eio#212). - Update to cmdliner.1.1.0 (@talex5 ocaml-multicore/eio#190).
CHANGES: API changes: - `Net.accept_sub` is deprecated in favour of `accept_fork` (@talex5 ocaml-multicore/eio#240). `Fiber.fork_on_accept`, which it used internally, has been removed. - Allow short writes in `Read_source_buffer` (@talex5 ocaml-multicore/eio#239). The reader is no longer required to consume all the data in one go. Also, add `Linux_eio.Low_level.writev_single` to expose this behaviour directly. - `Eio.Unix_perm` is now `Eio.Dir.Unix_perm`. New features: - Add `Eio.Mutex` (@TheLortex @talex5 ocaml-multicore/eio#223). - Add `Eio.Buf_write` (@talex5 ocaml-multicore/eio#235). This is a buffered writer for Eio sinks, based on Faraday. - Add `Eio_mock` library for testing (@talex5 ocaml-multicore/eio#228). At the moment it has mock flows and networks. - Add `Eio_mock.Backend` (@talex5 ocaml-multicore/eio#237 ocaml-multicore/eio#238). Allows running tests without needing a dependency on eio_main. Also, as it is single-threaded, it can detect deadlocks in test code instead of just hanging. - Add `Buf_read.{of_buffer, of_string, parse_string{,_exn}, return}` (@talex5 ocaml-multicore/eio#225). - Add `<*>` combinator to `Buf_read.Syntax` (@talex5 ocaml-multicore/eio#227). - Add `Eio.Dir.read_dir` (@patricoferris @talex5 ocaml-multicore/eio#207 ocaml-multicore/eio#218 ocaml-multicore/eio#219) Performance: - Add `Buf_read` benchmark and optimise it a bit (@talex5 ocaml-multicore/eio#230). - Inline `Buf_read.consume` to improve performance (@talex5 ocaml-multicore/eio#232). Bug fixes / minor changes: - Allow IO to happen even if a fiber keeps yielding (@TheLortex @talex5 ocaml-multicore/eio#213). - Fallback for `traceln` without an effect handler (@talex5 ocaml-multicore/eio#226). `traceln` now works outside of an event loop too. - Check for cancellation when creating a non-protected child context (@talex5 ocaml-multicore/eio#222). - eio_linux: handle EINTR when calling `getrandom` (@bikallem ocaml-multicore/eio#212). - Update to cmdliner.1.1.0 (@talex5 ocaml-multicore/eio#190).
This PR starts the implementation of a
readdirfeature for Eio. I opened it mainly to have a conversation about the API.kindof the entries which probably would be nice to add?read_dirbut I have seenreaddirto follow the convention used by the C function,contentsused byBosetc.At the moment I don't see a way to provide an asynchronous version with uring? I think with the 5.17 kernel there will be a
getdents64uring submission function which could then be used.Will fix #206