| ... | ... | @@ -2562,7 +2562,7 @@ pub const Dir = struct { |
| 2562 | 2562 | var atomic_file = try dest_dir.atomicFile(dest_path, .{ .mode = mode }); |
| 2563 | 2563 | defer atomic_file.deinit(); |
| 2564 | 2564 | |
| 2565 | | try copy_file(in_file.handle, atomic_file.file.handle); |
| 2565 | try copy_file(in_file.handle, atomic_file.file.handle, size); |
| 2566 | 2566 | try atomic_file.finish(); |
| 2567 | 2567 | } |
| 2568 | 2568 | |
| ... | ... | @@ -3041,7 +3041,7 @@ const CopyFileRawError = error{SystemResources} || os.CopyFileRangeError || os.S |
| 3041 | 3041 | // Transfer all the data between two file descriptors in the most efficient way. |
| 3042 | 3042 | // The copy starts at offset 0, the initial offsets are preserved. |
| 3043 | 3043 | // No metadata is transferred over. |
| 3044 | | fn copy_file(fd_in: os.fd_t, fd_out: os.fd_t) CopyFileRawError!void { |
| 3044 | fn copy_file(fd_in: os.fd_t, fd_out: os.fd_t, maybe_size: ?u64) CopyFileRawError!void { |
| 3045 | 3045 | if (comptime builtin.target.isDarwin()) { |
| 3046 | 3046 | const rc = os.system.fcopyfile(fd_in, fd_out, null, os.system.COPYFILE_DATA); |
| 3047 | 3047 | switch (os.errno(rc)) { |
| ... | ... | @@ -3064,7 +3064,10 @@ fn copy_file(fd_in: os.fd_t, fd_out: os.fd_t) CopyFileRawError!void { |
| 3064 | 3064 | // a 32 bit value so that the syscall won't return EINVAL except for |
| 3065 | 3065 | // impossibly large files (> 2^64-1 - 2^32-1). |
| 3066 | 3066 | const amt = try os.copy_file_range(fd_in, offset, fd_out, offset, math.maxInt(u32), 0); |
| 3067 | | // Terminate when no data was copied |
| 3067 | // Terminate as soon as we have copied size bytes or no bytes |
| 3068 | if (maybe_size) |s| { |
| 3069 | if (s == amt) break :cfr_loop; |
| 3070 | } |
| 3068 | 3071 | if (amt == 0) break :cfr_loop; |
| 3069 | 3072 | offset += amt; |
| 3070 | 3073 | } |
| ... | ... | @@ -3077,7 +3080,10 @@ fn copy_file(fd_in: os.fd_t, fd_out: os.fd_t) CopyFileRawError!void { |
| 3077 | 3080 | var offset: u64 = 0; |
| 3078 | 3081 | sendfile_loop: while (true) { |
| 3079 | 3082 | const amt = try os.sendfile(fd_out, fd_in, offset, 0, &empty_iovec, &empty_iovec, 0); |
| 3080 | | // Terminate when no data was copied |
| 3083 | // Terminate as soon as we have copied size bytes or no bytes |
| 3084 | if (maybe_size) |s| { |
| 3085 | if (s == amt) break :sendfile_loop; |
| 3086 | } |
| 3081 | 3087 | if (amt == 0) break :sendfile_loop; |
| 3082 | 3088 | offset += amt; |
| 3083 | 3089 | } |