Skip to content

Commit

Permalink
fix #14574, cp on files >2GB
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Feb 7, 2019
1 parent 69d4ee8 commit b367332
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 8 additions & 2 deletions base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -746,8 +746,14 @@ function sendfile(src::AbstractString, dst::AbstractString)
dst_file = open(dst, JL_O_CREAT | JL_O_TRUNC | JL_O_WRONLY, filemode(src_file))
dst_open = true

bytes = filesize(stat(src_file))
sendfile(dst_file, src_file, Int64(0), Int(bytes))
bytes = Int(filesize(stat(src_file)))
offs = Int64(0)
while true
nsent = sendfile(dst_file, src_file, offs, bytes)
bytes -= nsent
offs += nsent
bytes <= 0 && break
end
finally
if src_open && isopen(src_file)
close(src_file)
Expand Down
8 changes: 4 additions & 4 deletions base/filesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ end
function sendfile(dst::File, src::File, src_offset::Int64, bytes::Int)
check_open(dst)
check_open(src)
err = ccall(:jl_fs_sendfile, Int32, (OS_HANDLE, OS_HANDLE, Int64, Csize_t),
src.handle, dst.handle, src_offset, bytes)
uv_error("sendfile", err)
nothing
result = ccall(:jl_fs_sendfile, Int32, (OS_HANDLE, OS_HANDLE, Int64, Csize_t),
src.handle, dst.handle, src_offset, bytes)
uv_error("sendfile", result)
return Int(result) # bytes written
end

function unsafe_write(f::File, buf::Ptr{UInt8}, len::UInt, offset::Int64=Int64(-1))
Expand Down

0 comments on commit b367332

Please sign in to comment.