Skip to content

Commit b367332

Browse files
committed
fix #14574, cp on files >2GB
1 parent 69d4ee8 commit b367332

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

base/file.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -746,8 +746,14 @@ function sendfile(src::AbstractString, dst::AbstractString)
746746
dst_file = open(dst, JL_O_CREAT | JL_O_TRUNC | JL_O_WRONLY, filemode(src_file))
747747
dst_open = true
748748

749-
bytes = filesize(stat(src_file))
750-
sendfile(dst_file, src_file, Int64(0), Int(bytes))
749+
bytes = Int(filesize(stat(src_file)))
750+
offs = Int64(0)
751+
while true
752+
nsent = sendfile(dst_file, src_file, offs, bytes)
753+
bytes -= nsent
754+
offs += nsent
755+
bytes <= 0 && break
756+
end
751757
finally
752758
if src_open && isopen(src_file)
753759
close(src_file)

base/filesystem.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ end
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)
112-
nothing
109+
result = ccall(:jl_fs_sendfile, Int32, (OS_HANDLE, OS_HANDLE, Int64, Csize_t),
110+
src.handle, dst.handle, src_offset, bytes)
111+
uv_error("sendfile", result)
112+
return Int(result) # bytes written
113113
end
114114

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

0 commit comments

Comments
 (0)