From 14fd63a5c8e2d7b0eab2970699c2b4a407200cec Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Fri, 24 Feb 2023 10:38:52 +0000 Subject: [PATCH 1/2] Add test for pread and pwrite --- tests/fs.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/fs.md b/tests/fs.md index 63a1c7e72..c62d4f4fc 100644 --- a/tests/fs.md +++ b/tests/fs.md @@ -8,6 +8,7 @@ ```ocaml +module Int63 = Optint.Int63 module Path = Eio.Path let () = Eio.Exn.Backend.show := false @@ -512,3 +513,22 @@ Unconfined: +write -> ok - : unit = () ``` + +# pread/pwrite + +Check reading and writing vectors at arbitrary offsets: + +```ocaml +# run @@ fun env -> + let cwd = Eio.Stdenv.cwd env in + let path = cwd / "test.txt" in + Path.with_open_out path ~create:(`Exclusive 0o600) @@ fun file -> + Eio.Flow.copy_string "+-!" file; + Eio.File.pwrite_all file ~file_offset:(Int63.of_int 2) Cstruct.[of_string "abc"; of_string "123"]; + let buf1 = Cstruct.create 3 in + let buf2 = Cstruct.create 4 in + Eio.File.pread_exact file ~file_offset:(Int63.of_int 1) [buf1; buf2]; + traceln" %S/%S" (Cstruct.to_string buf1) (Cstruct.to_string buf2);; ++ "-ab"/"c123" +- : unit = () +``` From 76ffd669efcefbb18a4c2ede85f9192cfdb1290c Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Mon, 27 Feb 2023 13:23:25 +0000 Subject: [PATCH 2/2] Add test for readdir with no access Report the error as `Permission_denied`. --- lib_eio_linux/eio_linux.ml | 2 +- lib_eio_luv/eio_luv.ml | 1 + tests/fs.md | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib_eio_linux/eio_linux.ml b/lib_eio_linux/eio_linux.ml index 1706fc788..3a5387faf 100644 --- a/lib_eio_linux/eio_linux.ml +++ b/lib_eio_linux/eio_linux.ml @@ -47,7 +47,7 @@ let wrap_error_fs code name arg = match code with | Unix.EEXIST -> Eio.Fs.err (Already_exists e) | Unix.ENOENT -> Eio.Fs.err (Not_found e) - | Unix.EXDEV -> Eio.Fs.err (Permission_denied e) + | Unix.EXDEV | EPERM | EACCES -> Eio.Fs.err (Permission_denied e) | _ -> wrap_error code name arg module FD = struct diff --git a/lib_eio_luv/eio_luv.ml b/lib_eio_luv/eio_luv.ml index f0e645b40..ed6f5a575 100644 --- a/lib_eio_luv/eio_luv.ml +++ b/lib_eio_luv/eio_luv.ml @@ -45,6 +45,7 @@ let wrap_error_fs e = match e with | `EEXIST -> Eio.Fs.err (Already_exists (Luv_error e)) | `ENOENT -> Eio.Fs.err (Not_found (Luv_error e)) + | `EPERM | `EACCES -> Eio.Fs.err (Permission_denied (Luv_error e)) | e -> wrap_error e let or_raise = function diff --git a/tests/fs.md b/tests/fs.md index c62d4f4fc..0a9fce31c 100644 --- a/tests/fs.md +++ b/tests/fs.md @@ -377,6 +377,20 @@ Reading directory entries under `cwd` and outside of `cwd`. - : unit = () ``` +An error from the underlying directory, not the sandbox: + +```ocaml +# Unix.mkdir "test-no-access" 0; +- : unit = () +# run @@ fun env -> + let cwd = Eio.Stdenv.cwd env in + try_read_dir (cwd / "test-no-access");; ++Eio.Io Fs Permission_denied _, reading directory +- : unit = () +# Unix.chmod "test-no-access" 0o700; +- : unit = () +``` + Can use `fs` to access absolute paths: ```ocaml