From b367332e6cd8ff4e6b88f1d74907a5467d1cfd22 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Wed, 6 Feb 2019 23:50:54 -0500 Subject: [PATCH] fix #14574, `cp` on files >2GB --- base/file.jl | 10 ++++++++-- base/filesystem.jl | 8 ++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/base/file.jl b/base/file.jl index e3e70c0421aa4..b29a7fdbb0300 100644 --- a/base/file.jl +++ b/base/file.jl @@ -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) diff --git a/base/filesystem.jl b/base/filesystem.jl index fbba3884573c9..43dcd014d379e 100644 --- a/base/filesystem.jl +++ b/base/filesystem.jl @@ -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))