From 3178c046ee361f431782ecc4c0f1092111acd4a5 Mon Sep 17 00:00:00 2001 From: yangbiao59 Date: Thu, 3 Jul 2025 17:22:25 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=9B=9E=E5=90=881.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangbiao59 --- interfaces/kits/js/BUILD.gn | 35 ++++++ interfaces/kits/js/src/mod_fs/fs_utils.cpp | 105 ++++++++++++++++++ interfaces/kits/js/src/mod_fs/fs_utils.h | 10 +- .../js/src/mod_fs/properties/access_core.cpp | 4 +- .../js/src/mod_fs/properties/copy_core.cpp | 27 +++++ .../src/mod_fs/properties/copy_dir_core.cpp | 1 + .../js/src/mod_fs/properties/fsync_core.cpp | 2 +- .../js/src/mod_fs/properties/mkdir_core.cpp | 4 +- .../js/src/mod_fs/properties/mkdtemp_core.cpp | 2 +- .../js/src/mod_fs/properties/move_core.cpp | 5 +- .../js/src/mod_fs/properties/movedir_core.cpp | 4 +- .../js/src/mod_fs/properties/open_core.cpp | 38 ++++++- .../src/mod_fs/properties/read_lines_core.cpp | 2 +- .../js/src/mod_fs/properties/rename_core.cpp | 2 +- .../js/src/mod_fs/properties/symlink_core.cpp | 2 +- .../src/mod_fs/properties/truncate_core.cpp | 3 +- .../js/src/mod_fs/properties/unlink_core.cpp | 2 +- 17 files changed, 227 insertions(+), 21 deletions(-) diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index 0d0381732..c2830075d 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -801,7 +801,9 @@ ohos_shared_library("ani_file_fs") { ] use_exceptions = true external_deps = [ + "ability_base:zuri", "ability_runtime:ability_manager", + "access_token:libtokenid_sdk", "app_file_service:fileuri_native", "bounds_checking_function:libsec_static", "bundle_framework:appexecfwk_base", @@ -816,6 +818,7 @@ ohos_shared_library("ani_file_fs") { "hisysevent:libhisysevent", "ipc:ipc_core", "libuv:uv", + "napi:ace_napi", "runtime_core:ani", "runtime_core:ani_helpers", "runtime_core:libarkruntime", @@ -880,13 +883,22 @@ ohos_shared_library("ani_file_hash") { "${utils_path}/filemgmt_libhilog:filemgmt_libhilog", ] external_deps = [ + "ability_base:zuri", + "access_token:libtokenid_sdk", + "app_file_service:fileuri_native", "bounds_checking_function:libsec_static", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", "hilog:libhilog", + "ipc:ipc_core", "libuv:uv", + "napi:ace_napi", "openssl:libcrypto_shared", "runtime_core:ani", "runtime_core:ani_helpers", "runtime_core:libarkruntime", + "samgr:samgr_proxy", ] use_exceptions = true @@ -943,12 +955,21 @@ ohos_shared_library("ani_file_securitylabel") { "${utils_path}/filemgmt_libhilog:filemgmt_libhilog", ] external_deps = [ + "ability_base:zuri", + "access_token:libtokenid_sdk", + "app_file_service:fileuri_native", "bounds_checking_function:libsec_static", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", "hilog:libhilog", + "ipc:ipc_core", "libuv:uv", + "napi:ace_napi", "runtime_core:ani", "runtime_core:ani_helpers", "runtime_core:libarkruntime", + "samgr:samgr_proxy", ] use_exceptions = true @@ -1005,9 +1026,13 @@ ohos_shared_library("ani_file_environment") { "${utils_path}/filemgmt_libhilog:filemgmt_libhilog", ] external_deps = [ + "ability_base:zuri", + "ability_runtime:ability_manager", "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", + "app_file_service:fileuri_native", "bounds_checking_function:libsec_static", + "bundle_framework:appexecfwk_core", "hilog:libhilog", "init:libbegetutil", "ipc:ipc_core", @@ -1017,6 +1042,7 @@ ohos_shared_library("ani_file_environment") { "runtime_core:ani", "runtime_core:ani_helpers", "runtime_core:libarkruntime", + "samgr:samgr_proxy", ] use_exceptions = true @@ -1073,12 +1099,21 @@ ohos_shared_library("ani_file_statvfs") { "${utils_path}/filemgmt_libhilog:filemgmt_libhilog", ] external_deps = [ + "ability_base:zuri", + "access_token:libtokenid_sdk", + "app_file_service:fileuri_native", "bounds_checking_function:libsec_static", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", "hilog:libhilog", + "ipc:ipc_core", "libuv:uv", + "napi:ace_napi", "runtime_core:ani", "runtime_core:ani_helpers", "runtime_core:libarkruntime", + "samgr:samgr_proxy", ] use_exceptions = true cflags = [ diff --git a/interfaces/kits/js/src/mod_fs/fs_utils.cpp b/interfaces/kits/js/src/mod_fs/fs_utils.cpp index d2f426910..a46330d2d 100644 --- a/interfaces/kits/js/src/mod_fs/fs_utils.cpp +++ b/interfaces/kits/js/src/mod_fs/fs_utils.cpp @@ -15,9 +15,19 @@ #include "fs_utils.h" #include "filemgmt_libhilog.h" +#if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) && !defined(CROSS_PLATFORM) +#include "bundle_mgr_proxy.h" +#include "ipc_skeleton.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" +#include "tokenid_kit.h" +#endif namespace OHOS::FileManagement::ModuleFileIO { using namespace std; +#if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) && !defined(CROSS_PLATFORM) +const uint32_t API_VERSION_MOD = 1000; +#endif namespace { const vector PUBLIC_DIR_PATHS = { "/Documents" }; @@ -110,4 +120,99 @@ string FsUtils::Decode(const string &uri) return outPutStream.str(); } +#if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) && !defined(CROSS_PLATFORM) +bool IsNumeric(const string &str) +{ + if (str.empty()) { + return false; + } + for (char const &c : str) { + if (!isdigit(c)) { + return false; + } + } + return true; +} + +void SetQueryMap(Uri* uri, std::unordered_map &queryMap) +{ + // file://media/image/12?networkid=xxxx&api_version=xxxx?times=xxx&user=101 + string query = uri->GetQuery(); + string pairString; + stringstream queryStream(query); + + while (getline(queryStream, pairString, '&')) { + size_t splitIndex = pairString.find('='); + if (splitIndex == string::npos || splitIndex == (pairString.length() - 1)) { + HILOGE("failed to parse query, query field is %{private}s!", pairString.c_str()); + continue; + } + queryMap[pairString.substr(0, splitIndex)] = pairString.substr(splitIndex + 1); + } + return; +} + +bool FsUtils::GetAndCheckUserId(Uri* uri, string &userId) +{ + if (uri->ToString().find("user=") == string::npos) { + return false; + } + + std::unordered_map queryMap; + SetQueryMap(uri, queryMap); + auto it = queryMap.find("user"); + if (it != queryMap.end()) { + userId = it->second; + if (!IsNumeric(userId)) { + HILOGE("IsNumeric check fail"); + return false; + } + return true; + } else { + HILOGE("GetAndCheckUserId no match userId"); + } + return false; +} + +bool FsUtils::IsSystemApp() +{ + uint64_t fullTokenId = OHOS::IPCSkeleton::GetSelfTokenID(); + return Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(fullTokenId); +} + +uint32_t FsUtils::GetApiCompatibleVersion() +{ + uint32_t apiCompatibleVersion = 0; + OHOS::sptr systemAbilityManager = + OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (systemAbilityManager == nullptr) { + HILOGE("systemAbilityManager is null"); + return apiCompatibleVersion; + } + + OHOS::sptr remoteObject = + systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); + if (remoteObject == nullptr) { + HILOGE("remoteObject is null"); + return apiCompatibleVersion; + } + + sptr iBundleMgr = OHOS::iface_cast(remoteObject); + if (iBundleMgr == nullptr) { + HILOGE("IBundleMgr is null"); + return apiCompatibleVersion; + } + + AppExecFwk::BundleInfo bundleInfo; + auto res = iBundleMgr->GetBundleInfoForSelf(0, bundleInfo); + if (res == ERR_OK) { + apiCompatibleVersion = bundleInfo.targetVersion % API_VERSION_MOD; + } else { + HILOGE("Call for GetApiCompatibleVersion failed, err:%{public}d", res); + } + return apiCompatibleVersion; +} +#endif + } // namespace OHOS::FileManagement::ModuleFileIO diff --git a/interfaces/kits/js/src/mod_fs/fs_utils.h b/interfaces/kits/js/src/mod_fs/fs_utils.h index de4b9af4d..175eab50d 100644 --- a/interfaces/kits/js/src/mod_fs/fs_utils.h +++ b/interfaces/kits/js/src/mod_fs/fs_utils.h @@ -30,9 +30,10 @@ #include #include "fd_guard.h" +#include "file_uri.h" #include "uv.h" -#if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) +#if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) && !defined(CROSS_PLATFORM) #include "iremote_broker.h" #endif @@ -75,7 +76,7 @@ struct FileInfo { unique_ptr fdg = { nullptr }; }; -#if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) +#if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) && !defined(CROSS_PLATFORM) class FileIoToken : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"ohos.fileio.open"); @@ -93,6 +94,11 @@ public: static string GetModeFromFlags(const uint32_t &flags); static bool CheckPublicDirPath(const string &sandboxPath); static string Decode(const string &uri); +#if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) && !defined(CROSS_PLATFORM) + static bool GetAndCheckUserId(Uri* uri, std::string &userId); + static bool IsSystemApp(); + static uint32_t GetApiCompatibleVersion(); +#endif }; } // namespace OHOS::FileManagement::ModuleFileIO diff --git a/interfaces/kits/js/src/mod_fs/properties/access_core.cpp b/interfaces/kits/js/src/mod_fs/properties/access_core.cpp index 299cb24f7..c930e6ecd 100644 --- a/interfaces/kits/js/src/mod_fs/properties/access_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/access_core.cpp @@ -189,7 +189,7 @@ FsResult AccessCore::DoAccess(const std::string& path, const std::optional } int ret = Access(path, finalMode, flag); if (ret < 0 && (std::string_view(uv_err_name(ret)) != "ENOENT")) { - HILOGE("Failed to access file by path"); + HILOGE("Failed to access file by path, ret:%{public}d", ret); return FsResult::Error(ret); } bool isAccess = (ret == 0); @@ -205,7 +205,7 @@ FsResult AccessCore::DoAccess(const std::string& path, const AccessModeTyp } int ret = Access(path, finalMode, finalFlag); if (ret < 0 && (std::string_view(uv_err_name(ret)) != "ENOENT")) { - HILOGE("Failed to access file by path"); + HILOGE("Failed to access file by path, ret:%{public}d", ret); return FsResult::Error(ret); } bool isAccess = (ret == 0); diff --git a/interfaces/kits/js/src/mod_fs/properties/copy_core.cpp b/interfaces/kits/js/src/mod_fs/properties/copy_core.cpp index 45403ca6d..3daf6f942 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copy_core.cpp @@ -54,6 +54,7 @@ const string PROCEDURE_COPY_NAME = "FileFSCopy"; const std::string MEDIALIBRARY_DATA_URI = "datashare:///media"; const std::string MEDIA = "media"; const int SLEEP_TIME = 100000; +const int OPEN_TRUC_VERSION = 20; constexpr int DISMATCH = 0; constexpr int MATCH = 1; constexpr int BUF_SIZE = 1024; @@ -61,6 +62,7 @@ constexpr size_t MAX_SIZE = 1024 * 1024 * 4; constexpr std::chrono::milliseconds NOTIFY_PROGRESS_DELAY(300); std::recursive_mutex CopyCore::mutex_; std::map> CopyCore::callbackMap_; +uint32_t g_apiCompatibleVersion = 0; static int OpenSrcFile(const string &srcPth, std::shared_ptr infos, int32_t &srcFd) { @@ -72,6 +74,17 @@ static int OpenSrcFile(const string &srcPth, std::shared_ptr infos, HILOGE("Failed to get remote object"); return ENOMEM; } +#if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) + string userId; + if (FsUtils::GetAndCheckUserId(&uri, userId) && FsUtils::IsSystemApp()) { + dataShareHelper = DataShare::DataShareHelper::Creator(remote->AsObject(), + MEDIALIBRARY_DATA_URI + "?user=" + userId); + } else { + dataShareHelper = DataShare::DataShareHelper::Creator(remote->AsObject(), MEDIALIBRARY_DATA_URI); + } +#else + dataShareHelper = DataShare::DataShareHelper::Creator(remote->AsObject(), MEDIALIBRARY_DATA_URI); +#endif dataShareHelper = DataShare::DataShareHelper::Creator(remote->AsObject(), MEDIALIBRARY_DATA_URI); if (!dataShareHelper) { HILOGE("Failed to connect to datashare"); @@ -214,6 +227,20 @@ int CopyCore::CopyFile(const string &src, const string &dest, std::shared_ptr= OPEN_TRUC_VERSION) { + destFd = open(dest.c_str(), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); + } else { + destFd = open(dest.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); + } + auto destFd = open(dest.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); if (destFd < 0) { HILOGE("Error opening dest file descriptor. errno = %{public}d", errno); diff --git a/interfaces/kits/js/src/mod_fs/properties/copy_dir_core.cpp b/interfaces/kits/js/src/mod_fs/properties/copy_dir_core.cpp index b824647e3..0e6e48645 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy_dir_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copy_dir_core.cpp @@ -247,6 +247,7 @@ struct CopyDirResult CopyDirCore::DoCopyDir(const string &src, const string &des if (ret == EEXIST && modeValue == DIRMODE_FILE_COPY_THROW_ERR) { return { FsResult::Error(EEXIST), make_optional>(move(errfiles)) }; } else if (ret) { + HILOGE("Failed to copy dir, ret %{public}d", ret); return { FsResult::Error(ret), nullopt }; } return { FsResult::Success(), nullopt }; diff --git a/interfaces/kits/js/src/mod_fs/properties/fsync_core.cpp b/interfaces/kits/js/src/mod_fs/properties/fsync_core.cpp index d902ff1f3..0a9c11904 100644 --- a/interfaces/kits/js/src/mod_fs/properties/fsync_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/fsync_core.cpp @@ -34,7 +34,7 @@ FsResult FsyncCore::DoFsync(const int32_t &fd) } int ret = uv_fs_fsync(nullptr, fsyncReq.get(), fd, nullptr); if (ret < 0) { - HILOGE("Failed to transfer data associated with file descriptor: %{public}d", fd); + HILOGE("Failed to transfer data associated with file descriptor: %{public}d, ret:%{public}d", fd, ret); return FsResult::Error(ret); } return FsResult::Success(); diff --git a/interfaces/kits/js/src/mod_fs/properties/mkdir_core.cpp b/interfaces/kits/js/src/mod_fs/properties/mkdir_core.cpp index 6ae96ff21..15fc36450 100644 --- a/interfaces/kits/js/src/mod_fs/properties/mkdir_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/mkdir_core.cpp @@ -67,7 +67,7 @@ static int32_t MkdirExec(const string &path, bool recursion, bool hasOption) return EEXIST; } if (ret != -ENOENT) { - HILOGE("Failed to check for illegal path or request for heap memory"); + HILOGE("Failed to check for illegal path or request for heap memory, ret: %{public}d", ret); return ret; } if (::Mkdirs(path.c_str(), static_cast(recursion)) < 0) { @@ -76,7 +76,7 @@ static int32_t MkdirExec(const string &path, bool recursion, bool hasOption) } ret = UvAccess(path, 0); if (ret) { - HILOGE("Failed to verify the result of Mkdirs function"); + HILOGE("Failed to verify the result of Mkdirs function, ret: %{public}d", ret); return ret; } return ERRNO_NOERR; diff --git a/interfaces/kits/js/src/mod_fs/properties/mkdtemp_core.cpp b/interfaces/kits/js/src/mod_fs/properties/mkdtemp_core.cpp index 487f35c69..11035ac47 100644 --- a/interfaces/kits/js/src/mod_fs/properties/mkdtemp_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/mkdtemp_core.cpp @@ -32,7 +32,7 @@ FsResult MkdtempCore::DoMkdtemp(const string &path) } int ret = uv_fs_mkdtemp(nullptr, mkdtempReq.get(), const_cast(path.c_str()), nullptr); if (ret < 0) { - HILOGE("Failed to create a temporary directory with path"); + HILOGE("Failed to create a temporary directory with path ret %{public}d", ret); return FsResult::Error(ret); } diff --git a/interfaces/kits/js/src/mod_fs/properties/move_core.cpp b/interfaces/kits/js/src/mod_fs/properties/move_core.cpp index 56961567c..8ab7a5a55 100644 --- a/interfaces/kits/js/src/mod_fs/properties/move_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/move_core.cpp @@ -138,7 +138,7 @@ static int RenameFile(const string &src, const string &dest) return CopyAndDeleteFile(src, dest); } if (ret < 0) { - HILOGE("Failed to move file using rename syscall."); + HILOGE("Failed to move file using rename syscall, ret:%{public}d", ret); return ret; } return ERRNO_NOERR; @@ -161,7 +161,7 @@ static int MoveFile(const string &src, const string &dest, int mode) return EEXIST; } if (ret < 0 && (string_view(uv_err_name(ret)) != "ENOENT")) { - HILOGE("Failed to access destPath with MODE_THROW_ERR."); + HILOGE("Failed to access destPath with MODE_THROW_ERR, ret:%{public}d", ret); return ret; } } else { @@ -178,6 +178,7 @@ FsResult MoveCore::DoMove(const string &src, const string &dest, const opt } int ret = MoveFile(move(srcPath), move(destPath), modeType); if (ret) { + HILOGE("Failed movefile ret %{public}d", ret); return FsResult::Error(ret); } return FsResult::Success(); diff --git a/interfaces/kits/js/src/mod_fs/properties/movedir_core.cpp b/interfaces/kits/js/src/mod_fs/properties/movedir_core.cpp index fb357ff05..107e2dee7 100644 --- a/interfaces/kits/js/src/mod_fs/properties/movedir_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/movedir_core.cpp @@ -237,7 +237,7 @@ static int MoveDirFunc(const string &src, const string &dest, const int mode, de if (mode == DIRMODE_DIRECTORY_REPLACE) { int removeRes = RmDirectory(destStr); if (removeRes) { - HILOGE("Failed to remove dest directory in DIRMODE_DIRECTORY_REPLACE"); + HILOGE("Failed to remove dest directory in DIRMODE_DIRECTORY_REPLACE, ret %{public}d", removeRes); return removeRes; } } @@ -254,7 +254,7 @@ static int MoveDirFunc(const string &src, const string &dest, const int mode, de } int removeRes = RmDirectory(src); if (removeRes) { - HILOGE("Failed to remove src directory"); + HILOGE("Failed to remove src directory, ret %{public}d", removeRes); return removeRes; } } diff --git a/interfaces/kits/js/src/mod_fs/properties/open_core.cpp b/interfaces/kits/js/src/mod_fs/properties/open_core.cpp index 8ead99468..95439abd5 100644 --- a/interfaces/kits/js/src/mod_fs/properties/open_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/open_core.cpp @@ -116,17 +116,47 @@ static int OpenFileByDatashare(const string &path, uint32_t flags) return fd; } +static int OpenFileByDatashareHasUserId(const string &path, unsigned int flags, const string &userId) +{ + std::shared_ptr dataShareHelper = nullptr; + sptr remote = new (std::nothrow) IRemoteStub(); + if (!remote) { + HILOGE("Failed to get remote object"); + return -ENOMEM; + } + + dataShareHelper = DataShare::DataShareHelper::Creator(remote->AsObject(), + MEDIALIBRARY_DATA_URI + "?user=" + userId); + if (!dataShareHelper) { + HILOGE("Failed to connect to datashare"); + return -E_PERMISSION; + } + Uri uri(path); + int fd = dataShareHelper->OpenFile(uri, FsUtils::GetModeFromFlags(flags)); + return fd; +} + static tuple OpenByFileDataUri(Uri &uri, const string &uriStr, uint32_t mode) { string bundleName = uri.GetAuthority(); AppFileService::ModuleFileUri::FileUri fileUri(uriStr); string realPath = fileUri.GetRealPath(); if (bundleName == MEDIA) { - int res = OpenFileByDatashare(uri.ToString(), mode); - if (res < 0) { - HILOGE("Failed to open file by Datashare error %{public}d", res); + string userId; + if (FsUtils::GetAndCheckUserId(&uri, userId) && FsUtils::IsSystemApp()) { + int res = OpenFileByDatashareHasUserId(uri.ToString(), mode, userId); + if (res < 0) { + HILOGE("Failed to open file by DatashareHasUserId error %{public}d", res); + } + return { res, uri.ToString() }; + } else { + int res = OpenFileByDatashare(uri.ToString(), mode); + if (res < 0) { + HILOGE("Failed to open file by Datashare error %{public}d", res); + } + return { res, uri.ToString() }; + } - return { res, uri.ToString() }; } else if (bundleName == DOCS && access(realPath.c_str(), F_OK) != 0) { int res = OpenFileByDatashare(uri.ToString(), mode); if (res < 0) { diff --git a/interfaces/kits/js/src/mod_fs/properties/read_lines_core.cpp b/interfaces/kits/js/src/mod_fs/properties/read_lines_core.cpp index 1f9869151..d308f8f13 100644 --- a/interfaces/kits/js/src/mod_fs/properties/read_lines_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/read_lines_core.cpp @@ -95,7 +95,7 @@ FsResult ReadLinesCore::DoReadLines(const string &path, opti int64_t offset = 0; int ret = GetFileSize(path, offset); if (ret != 0) { - HILOGE("Failed to get size of the file"); + HILOGE("Failed to get size of the file ret %{public}d", ret); return FsResult::Error(ret); } return InstantiateReaderIterator(iterator, offset); diff --git a/interfaces/kits/js/src/mod_fs/properties/rename_core.cpp b/interfaces/kits/js/src/mod_fs/properties/rename_core.cpp index 1edff30a2..4f5416e92 100644 --- a/interfaces/kits/js/src/mod_fs/properties/rename_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/rename_core.cpp @@ -36,7 +36,7 @@ FsResult RenameCore::DoRename(const string &src, const string &dest) } int ret = uv_fs_rename(nullptr, renameReq.get(), src.c_str(), dest.c_str(), nullptr); if (ret < 0) { - HILOGE("Failed to rename file with path"); + HILOGE("Failed to rename file with path ret %{public}d", ret); return FsResult::Error(ret); } return FsResult::Success(); diff --git a/interfaces/kits/js/src/mod_fs/properties/symlink_core.cpp b/interfaces/kits/js/src/mod_fs/properties/symlink_core.cpp index 217f429fd..c19459428 100644 --- a/interfaces/kits/js/src/mod_fs/properties/symlink_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/symlink_core.cpp @@ -37,7 +37,7 @@ FsResult SymlinkCore::DoSymlink(const string &target, const string &srcPat } int ret = uv_fs_symlink(nullptr, symlinkReq.get(), target.c_str(), srcPath.c_str(), 0, nullptr); if (ret < 0) { - HILOGE("Failed to create a link for old path"); + HILOGE("Failed to create a link for old path ret %{public}d", ret); return FsResult::Error(ret); } return FsResult::Success(); diff --git a/interfaces/kits/js/src/mod_fs/properties/truncate_core.cpp b/interfaces/kits/js/src/mod_fs/properties/truncate_core.cpp index 66b68f185..ce0eebbcc 100644 --- a/interfaces/kits/js/src/mod_fs/properties/truncate_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/truncate_core.cpp @@ -48,6 +48,7 @@ static int Truncate(FileInfo &fileInfo, int64_t truncateLen) int ret = uv_fs_open( nullptr, openReq.get(), fileInfo.path.get(), O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP, nullptr); if (ret < 0) { + HILOGE("Failed to open by libuv ret %{public}d", ret); return ret; } std::unique_ptr ftruncateReq = { new uv_fs_t, @@ -58,7 +59,7 @@ static int Truncate(FileInfo &fileInfo, int64_t truncateLen) } ret = uv_fs_ftruncate(nullptr, ftruncateReq.get(), ret, truncateLen, nullptr); if (ret < 0) { - HILOGE("Failed to truncate file by path"); + HILOGE("Failed to truncate file by path ret %{public}d", ret); return ret; } } else { diff --git a/interfaces/kits/js/src/mod_fs/properties/unlink_core.cpp b/interfaces/kits/js/src/mod_fs/properties/unlink_core.cpp index 339b56db0..88e6317b7 100644 --- a/interfaces/kits/js/src/mod_fs/properties/unlink_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/unlink_core.cpp @@ -36,7 +36,7 @@ FsResult UnlinkCore::DoUnlink(const std::string &src) } int ret = uv_fs_unlink(nullptr, unlinkReq.get(), src.c_str(), nullptr); if (ret < 0) { - HILOGD("Failed to unlink with path"); + HILOGD("Failed to unlink with path ret %{public}d", ret); return FsResult::Error(ret); } -- Gitee From 44e058ae67fce691cc0eb7d68ee73f8f20d0ffcd Mon Sep 17 00:00:00 2001 From: yangbiao59 Date: Fri, 4 Jul 2025 01:29:54 +0000 Subject: [PATCH 2/3] modify Signed-off-by: yangbiao59 --- interfaces/kits/js/src/mod_fs/properties/copy_core.cpp | 3 +-- interfaces/kits/js/src/mod_fs/properties/open_core.cpp | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/copy_core.cpp b/interfaces/kits/js/src/mod_fs/properties/copy_core.cpp index 3daf6f942..e59bf6522 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copy_core.cpp @@ -83,7 +83,7 @@ static int OpenSrcFile(const string &srcPth, std::shared_ptr infos, dataShareHelper = DataShare::DataShareHelper::Creator(remote->AsObject(), MEDIALIBRARY_DATA_URI); } #else - dataShareHelper = DataShare::DataShareHelper::Creator(remote->AsObject(), MEDIALIBRARY_DATA_URI); + dataShareHelper = DataShare::DataShareHelper::Creator(remote->AsObject(), MEDIALIBRARY_DATA_URI); #endif dataShareHelper = DataShare::DataShareHelper::Creator(remote->AsObject(), MEDIALIBRARY_DATA_URI); if (!dataShareHelper) { @@ -241,7 +241,6 @@ int CopyCore::CopyFile(const string &src, const string &dest, std::shared_ptr OpenByFileDataUri(Uri &uri, const string &uriStr, uint HILOGE("Failed to open file by Datashare error %{public}d", res); } return { res, uri.ToString() }; - } } else if (bundleName == DOCS && access(realPath.c_str(), F_OK) != 0) { int res = OpenFileByDatashare(uri.ToString(), mode); -- Gitee From c3e158a394ba92325bd458c17cc25d14236cb2fc Mon Sep 17 00:00:00 2001 From: yangbiao59 Date: Fri, 4 Jul 2025 02:50:32 +0000 Subject: [PATCH 3/3] update interfaces/test/unittest/js/BUILD.gn. Signed-off-by: yangbiao59 --- interfaces/test/unittest/js/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/interfaces/test/unittest/js/BUILD.gn b/interfaces/test/unittest/js/BUILD.gn index d4863929c..90e029bc4 100644 --- a/interfaces/test/unittest/js/BUILD.gn +++ b/interfaces/test/unittest/js/BUILD.gn @@ -41,6 +41,7 @@ ohos_unittest("ani_file_environment_test") { external_deps = [ "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", + "app_file_service:fileuri_native", "googletest:gmock_main", "googletest:gtest_main", "hilog:libhilog", -- Gitee