diff --git a/src/unix/fs.c b/src/unix/fs.c index a6366255..00af4675 100644 --- a/src/unix/fs.c +++ b/src/unix/fs.c @@ -795,6 +795,7 @@ static ssize_t uv__fs_copyfile(uv_fs_t* req) { int64_t in_offset; dstfd = -1; + err = 0; /* Open the source file. */ srcfd = uv_fs_open(NULL, &fs_req, req->path, O_RDONLY, 0, NULL); diff --git a/test/test-fs-copyfile.c b/test/test-fs-copyfile.c index 2d1f9079..e91044e0 100644 --- a/test/test-fs-copyfile.c +++ b/test/test-fs-copyfile.c @@ -119,6 +119,13 @@ TEST_IMPL(fs_copyfile) { ASSERT(r == 0); handle_result(&req); + /* Copies a file of size zero. */ + unlink(dst); + touch_file(src, 0); + r = uv_fs_copyfile(NULL, &req, src, dst, 0, NULL); + ASSERT(r == 0); + handle_result(&req); + /* Copies file synchronously. Overwrites existing file. */ r = uv_fs_copyfile(NULL, &req, fixture, dst, 0, NULL); ASSERT(r == 0); @@ -141,9 +148,9 @@ TEST_IMPL(fs_copyfile) { unlink(dst); r = uv_fs_copyfile(loop, &req, fixture, dst, 0, handle_result); ASSERT(r == 0); - ASSERT(result_check_count == 3); - uv_run(loop, UV_RUN_DEFAULT); ASSERT(result_check_count == 4); + uv_run(loop, UV_RUN_DEFAULT); + ASSERT(result_check_count == 5); unlink(dst); /* Cleanup */ return 0;