Skip to content

Commit

Permalink
fix: sendfile: fall back to portable copy (ocaml#8049)
Browse files Browse the repository at this point in the history
Fixes ocaml#8041

Signed-off-by: Etienne Millon <me@emillon.org>
  • Loading branch information
emillon committed Jun 27, 2023
1 parent e74ba0f commit a49c7ee
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

- Fix deadlock on Windows (#8044, @nojb)

- When using `sendfile` to copy files on Linux, fall back to the portable
version if it fails at runtime for some reason (NFS, etc).
(#8049, fixes #8041, @emillon)

3.8.2 (2023-06-16)
------------------

Expand Down
7 changes: 6 additions & 1 deletion otherlibs/stdune/src/io.ml
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,14 @@ module Copyfile = struct
Exn.protectx (setup_copy ?chmod ~src ~dst ()) ~finally:close_both
~f:(fun (ic, oc) -> copy_channels ic oc)

let sendfile_with_fallback ?chmod ~src ~dst () =
try sendfile ?chmod ~src ~dst ()
with Unix.Unix_error (EINVAL, "sendfile", _) ->
copy_file_portable ?chmod ~src ~dst ()

let copy_file_best =
match available with
| `Sendfile -> sendfile
| `Sendfile -> sendfile_with_fallback
| `Copyfile -> copyfile
| `Nothing -> copy_file_portable

Expand Down
6 changes: 0 additions & 6 deletions test/blackbox-tests/test-cases/github8041.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,3 @@
If sendfile fails, we should fallback to the portable implementation.
$ strace -e inject=sendfile:error=EINVAL -o /dev/null dune build @install
Error: sendfile(): Invalid argument
-> required by _build/default/data.txt
-> required by _build/install/default/share/p/data.txt
-> required by _build/default/p.install
-> required by alias install
[1]

0 comments on commit a49c7ee

Please sign in to comment.