Skip to content

Commit 1788b07

Browse files
JeffBezansonKristofferC
authored andcommitted
fix #14574, cp on files >2GB (#30989)
(cherry picked from commit 05785f9)
1 parent 58db74d commit 1788b07

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

base/filesystem.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,19 @@ function close(f::File)
102102
return nothing
103103
end
104104

105-
# sendfile is the most efficient way to copy a file (or any file descriptor)
105+
# sendfile is the most efficient way to copy from a file descriptor
106106
function sendfile(dst::File, src::File, src_offset::Int64, bytes::Int)
107107
check_open(dst)
108108
check_open(src)
109-
err = ccall(:jl_fs_sendfile, Int32, (OS_HANDLE, OS_HANDLE, Int64, Csize_t),
110-
src.handle, dst.handle, src_offset, bytes)
111-
uv_error("sendfile", err)
109+
while true
110+
result = ccall(:jl_fs_sendfile, Int32, (OS_HANDLE, OS_HANDLE, Int64, Csize_t),
111+
src.handle, dst.handle, src_offset, bytes)
112+
uv_error("sendfile", result)
113+
nsent = result
114+
bytes -= nsent
115+
src_offset += nsent
116+
bytes <= 0 && break
117+
end
112118
nothing
113119
end
114120

0 commit comments

Comments
 (0)