diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index 27f631699fd11eeb27c7ff83a333c24d21f6a746..f5bd313ce457abd148a65c918b968f7e36dcdc89 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -801,9 +801,12 @@ 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_shared", + "bounds_checking_function:libsec_static", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", @@ -816,6 +819,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 +884,23 @@ 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_shared", + "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 +957,22 @@ 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_shared", + "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 +1029,14 @@ 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_shared", + "bounds_checking_function:libsec_static", + "bundle_framework:appexecfwk_core", "hilog:libhilog", "init:libbegetutil", "ipc:ipc_core", @@ -1017,6 +1046,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 +1103,22 @@ 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_shared", + "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 d2f42691023ab6e189cdfa1b58d5690e6e9c94ba..a46330d2dc1a2db4da451ddcd3c0453920e12909 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 de4b9af4dc213f534c4adb8c37fbcccef82974ea..175eab50dd2a83a0080ea8a5ba31a222869dcb24 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 299cb24f773fbb7bc9eb7636331f61fca260fae0..c930e6ecdade1c44fb53c8dbe951bedb602dc4bc 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 45403ca6d82752fcac6b36e2cf72b2f063305337..e59bf6522acdf84fbeef9a1f4d512d036b243a59 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,7 +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); + } + if (destFd < 0) { HILOGE("Error opening dest file descriptor. errno = %{public}d", errno); close(srcFd); 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 b824647e3bbdac890da2eb9d6bfa87d096ee50a0..0e6e48645e5d0e085e30317d3341b9672e2831f9 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 d902ff1f31e2dc4aa125bffbbff40378278b8ecc..0a9c1190449016d1b9708acc9259fa86fa531292 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 6ae96ff21a7ef2e09a8dd11e0f4e26b654e4d8c9..15fc364503c5c38f459b940ea6d2715e604a4962 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 487f35c69e38f90b309425a64e7b16ae4b4ae33e..11035ac47e5fad4d016c31d60efb749baf729f71 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 a0b823ea18493c5e54af1a8c4d4fedd85f2088c5..f322d51e58421994b330dc07916d0fd5bae4d448 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; @@ -155,7 +155,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 { @@ -172,6 +172,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 f882c1aa2e45e191eaed247f4161cf1367612aa0..66892ffae28103a14fe0de1193347ce540fa8489 100644 --- a/interfaces/kits/js/src/mod_fs/properties/movedir_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/movedir_core.cpp @@ -233,7 +233,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; } } @@ -250,7 +250,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 8ead99468d9e2761f1932c1410595fe6900b82aa..c8cb8cd3c114e58956deb6f623804dc584b9a9f0 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,46 @@ 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 1f986915199031de14d6eedf10ebb6115003e9c6..d308f8f135e9e1a37cb95b260a377b86b9db11e4 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 1edff30a2084d8e8f6387358103de195ac7aa3fa..4f5416e921601c36a07fbd065dc2be4e003fc7f8 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 217f429fd20e7a4e1c8b53fbbfbd3bdb4f067010..c194594282bf80ceae5494fc0183a9b484af6cd6 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 66b68f185be7c5dfa419e1028db09190e175003c..ce0eebbcc1ab57505091c978c15d31ed930a3f15 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 339b56db0664a30f426edd4bedc2e173952569ab..88e6317b74b58a1dbf486a1e82d1a1fa7aa72f83 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); } diff --git a/interfaces/test/unittest/js/BUILD.gn b/interfaces/test/unittest/js/BUILD.gn index 21089f49415c5dc8dd3236a7c49dec4d90d88a6a..2af5b12d175490c910267ab751fd6b5bce8ff63b 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",