From 67018d0abf99d4d33de0f11eafab044679fdaedb Mon Sep 17 00:00:00 2001 From: fengjq Date: Sat, 19 Aug 2023 09:47:16 +0800 Subject: [PATCH] Bugfix for the condition of the sendfile loop call. Signed-off-by: fengjq --- .../kits/js/src/mod_fs/properties/copy_file.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/copy_file.cpp b/interfaces/kits/js/src/mod_fs/properties/copy_file.cpp index 97ba9ff71..89003eccc 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy_file.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copy_file.cpp @@ -71,21 +71,22 @@ static NError SendFileCore(FileInfo& srcFdg, FileInfo& destFdg, struct stat& sta int64_t offset = 0; size_t size = static_cast(statbf.st_size); int ret = 0; - while (size > MAX_SIZE) { + while (size > 0) { ret = uv_fs_sendfile(nullptr, sendfile_req.get(), destFdg.fdg->GetFD(), srcFdg.fdg->GetFD(), offset, MAX_SIZE, nullptr); if (ret < 0) { HILOGE("Failed to sendfile by ret : %{public}d", ret); return NError(ret); } - offset += MAX_SIZE; - size -= MAX_SIZE; + offset += static_cast(ret); + size -= static_cast(ret); + if (ret == 0) { + break; + } } - ret = uv_fs_sendfile(nullptr, sendfile_req.get(), destFdg.fdg->GetFD(), srcFdg.fdg->GetFD(), - offset, size, nullptr); - if (ret < 0) { - HILOGE("Failed to sendfile by ret : %{public}d", ret); - return NError(ret); + if (size != 0) { + HILOGE("The execution of the sendfile task was terminated, remaining file size %{public}zu", size); + return NError(EIO); } return NError(ERRNO_NOERR); } -- Gitee