Skip to content

Commit

Permalink
unix: refactor uv__fs_copyfile() logic
Browse files Browse the repository at this point in the history
The Unix/macOS uv__fs_copyfile() implementation falls back to
using uv_fs_sendfile(). This commit refactors the error handling
to use the sendfile() req's result field, which is an ssize_t
instead of using the return value, which is an int. The int
value was coming back as a negative number for some large files.

Refs: nodejs/node#30085
  • Loading branch information
cjihrig committed Oct 29, 2019
1 parent a62f8ce commit a2a0ce1
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/unix/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1076,16 +1076,12 @@ static ssize_t uv__fs_copyfile(uv_fs_t* req) {
bytes_to_send = src_statsbuf.st_size;
in_offset = 0;
while (bytes_to_send != 0) {
err = uv_fs_sendfile(NULL,
&fs_req,
dstfd,
srcfd,
in_offset,
bytes_to_send,
NULL);
uv_fs_sendfile(NULL, &fs_req, dstfd, srcfd, in_offset, bytes_to_send, NULL);
uv_fs_req_cleanup(&fs_req);
if (err < 0)
if (fs_req.result < 0) {
err = fs_req.result;
break;
}
bytes_to_send -= fs_req.result;
in_offset += fs_req.result;
}
Expand Down

0 comments on commit a2a0ce1

Please sign in to comment.