From 02db1c84308c99568a839a46a62199e80f1a9af4 Mon Sep 17 00:00:00 2001 From: 18721213663 Date: Wed, 19 Jul 2023 17:13:51 +0800 Subject: [PATCH 1/2] fixed dead14d from https://gitee.com/zhuhongtao66/filemanagement_file_api/pulls/330 xattr_adapt_IOS Signed-off-by: 18721213663 --- .../kits/js/src/mod_securitylabel/security_label.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/interfaces/kits/js/src/mod_securitylabel/security_label.h b/interfaces/kits/js/src/mod_securitylabel/security_label.h index e789b7261..fbac9b310 100644 --- a/interfaces/kits/js/src/mod_securitylabel/security_label.h +++ b/interfaces/kits/js/src/mod_securitylabel/security_label.h @@ -35,7 +35,11 @@ public: if (DATA_LEVEL.count(dataLevel) != 1) { return false; } +#ifdef IOS_PLATFORM + if (setxattr(path.c_str(), XATTR_KEY, dataLevel.c_str(), dataLevel.size(), 0, 0) < 0) { +#else if (setxattr(path.c_str(), XATTR_KEY, dataLevel.c_str(), dataLevel.size(), 0) < 0) { +#endif return false; } return true; @@ -43,7 +47,11 @@ public: static std::string GetSecurityLabel(const std::string &path) { +#ifdef IOS_PLATFORM + auto xattrValueSize = getxattr(path.c_str(), XATTR_KEY, nullptr, 0, 0, 0); +#else auto xattrValueSize = getxattr(path.c_str(), XATTR_KEY, nullptr, 0); +#endif if (xattrValueSize == -1 || errno == ENOTSUP) { return ""; } @@ -54,8 +62,11 @@ public: if (xattrValue == nullptr) { return ""; } - +#ifdef IOS_PLATFORM + xattrValueSize = getxattr(path.c_str(), XATTR_KEY, xattrValue.get(), xattrValueSize, 0, 0); +#else xattrValueSize = getxattr(path.c_str(), XATTR_KEY, xattrValue.get(), xattrValueSize); +#endif if (xattrValueSize == -1 || errno == ENOTSUP) { return ""; } -- Gitee From 9d4a5f54973551598fd2e6df957d4db074113aef Mon Sep 17 00:00:00 2001 From: 18721213663 Date: Wed, 26 Jul 2023 10:25:20 +0800 Subject: [PATCH 2/2] fs_fix_sendfile Signed-off-by: 18721213663 --- .../js/src/mod_fs/properties/copy_file.cpp | 19 ++++++++++++++++--- .../kits/js/src/mod_fs/properties/copy_file.h | 2 +- 2 files changed, 17 insertions(+), 4 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 6dc697584..15eb6ea4b 100755 --- a/interfaces/kits/js/src/mod_fs/properties/copy_file.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copy_file.cpp @@ -57,11 +57,24 @@ static NError SendFileCore(FileInfo& srcFdg, FileInfo& destFdg, struct stat& sta HILOGE("Failed to request heap memory."); return NError(ENOMEM); } - int ret = uv_fs_sendfile(nullptr, sendfile_req.get(), destFdg.fdg->GetFD(), srcFdg.fdg->GetFD(), 0, - statbf.st_size, nullptr); + int64_t offset = 0; + size_t size = static_cast(statbf.st_size); + int ret = 0; + while (size > MAX_SIZE) { + 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; + } + 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(errno); + return NError(ret); } return NError(ERRNO_NOERR); } diff --git a/interfaces/kits/js/src/mod_fs/properties/copy_file.h b/interfaces/kits/js/src/mod_fs/properties/copy_file.h index fef4af34b..2801c4a43 100755 --- a/interfaces/kits/js/src/mod_fs/properties/copy_file.h +++ b/interfaces/kits/js/src/mod_fs/properties/copy_file.h @@ -36,7 +36,7 @@ public: Para(FileInfo src, FileInfo dest) : src_(move(src)), dest_(move(dest)){}; }; - +constexpr size_t MAX_SIZE = 0x7ffff000; const string PROCEDURE_COPYFILE_NAME = "FileIOCopyFile"; } // namespace ModuleFileIO } // namespace FileManagement -- Gitee