unix: refactor uv__fs_copyfile() logic
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: https://github.com/nodejs/node/issues/30085 PR-URL: https://github.com/libuv/libuv/pull/2533 Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
This commit is contained in:
parent
a62f8ced7a
commit
780c08a63e
@ -999,6 +999,7 @@ static ssize_t uv__fs_copyfile(uv_fs_t* req) {
|
||||
int err;
|
||||
size_t bytes_to_send;
|
||||
int64_t in_offset;
|
||||
ssize_t bytes_written;
|
||||
|
||||
dstfd = -1;
|
||||
err = 0;
|
||||
@ -1076,18 +1077,17 @@ 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);
|
||||
bytes_written = fs_req.result;
|
||||
uv_fs_req_cleanup(&fs_req);
|
||||
if (err < 0)
|
||||
|
||||
if (bytes_written < 0) {
|
||||
err = bytes_written;
|
||||
break;
|
||||
bytes_to_send -= fs_req.result;
|
||||
in_offset += fs_req.result;
|
||||
}
|
||||
|
||||
bytes_to_send -= bytes_written;
|
||||
in_offset += bytes_written;
|
||||
}
|
||||
|
||||
out:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user