Skip to content

Commit

Permalink
Merge pull request #451 from talex5/more-tests
Browse files Browse the repository at this point in the history
Add tests for pread, pwrite and readdir
  • Loading branch information
talex5 authored Feb 27, 2023
2 parents 5541790 + 76ffd66 commit fd33336
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib_eio_linux/eio_linux.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib_eio_luv/eio_luv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions tests/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

```ocaml
module Int63 = Optint.Int63
module Path = Eio.Path
let () = Eio.Exn.Backend.show := false
Expand Down Expand Up @@ -376,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 <cwd:test-no-access>
- : unit = ()
# Unix.chmod "test-no-access" 0o700;
- : unit = ()
```

Can use `fs` to access absolute paths:

```ocaml
Expand Down Expand Up @@ -512,3 +527,22 @@ Unconfined:
+write <cwd:stat_reg> -> 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 = ()
```

0 comments on commit fd33336

Please sign in to comment.