Allow reading absolute paths with Stdenv.fs

`open_in` was missing the fix that was already applied to `open_out` and
`open_dir`.
This commit is contained in:
Thomas Leonard 2022-01-17 15:41:23 +00:00
parent 607d2ef583
commit aea5d71a34
2 changed files with 17 additions and 1 deletions

View File

@ -903,7 +903,7 @@ module Objects = struct
~access:`R
~flags:Uring.Open_flags.cloexec
~perm:0
~resolve:Uring.Resolve.beneath
~resolve:resolve_flags
in
(flow fd :> <Eio.Flow.source; Eio.Flow.close>)

View File

@ -232,3 +232,19 @@ Using `cwd` we can't access the parent, but using `fs` we can:
+chdir ".."
- : unit = ()
```
Can use `fs` to access absolute paths:
```ocaml
# run @@ fun env ->
let cwd = Eio.Stdenv.cwd env in
let fs = Eio.Stdenv.fs env in
let b = Buffer.create 10 in
Eio.Dir.with_open_in fs Filename.null (fun flow -> Eio.Flow.copy flow (Eio.Flow.buffer_sink b));
traceln "Read %S and got %S" Filename.null (Buffer.contents b);
traceln "Trying with cwd instead fails:";
Eio.Dir.with_open_in cwd Filename.null (fun flow -> Eio.Flow.copy flow (Eio.Flow.buffer_sink b));;;
+Read "/dev/null" and got ""
+Trying with cwd instead fails:
Exception: Eio.Dir.Permission_denied ("/dev/null", _)
```