From 007c2fe7a6343617882cb016784920eecd4754f7 Mon Sep 17 00:00:00 2001 From: xingshenjie Date: Mon, 24 Mar 2025 18:19:06 -0700 Subject: [PATCH] Fix open api add open truc Signed-off-by: xingshenjie --- interfaces/kits/js/src/mod_fs/common_func.cpp | 41 ++++++++++++++++++- interfaces/kits/js/src/mod_fs/common_func.h | 3 +- .../kits/js/src/mod_fs/properties/copy.cpp | 19 ++++++++- 3 files changed, 59 insertions(+), 4 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/common_func.cpp b/interfaces/kits/js/src/mod_fs/common_func.cpp index 6193013a3..1aeb5595d 100644 --- a/interfaces/kits/js/src/mod_fs/common_func.cpp +++ b/interfaces/kits/js/src/mod_fs/common_func.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -35,7 +35,10 @@ #include "filemgmt_libn.h" #include "file_utils.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 @@ -44,6 +47,9 @@ namespace FileManagement { namespace ModuleFileIO { using namespace std; using namespace OHOS::FileManagement::LibN; +#if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) && !defined(CROSS_PLATFORM) +const uint32_t API_VERSION_MOD = 1000; +#endif namespace { const std::vector PUBLIC_DIR_PATHS = { @@ -412,6 +418,39 @@ bool CommonFunc::IsSystemApp() uint64_t fullTokenId = OHOS::IPCSkeleton::GetSelfTokenID(); return Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(fullTokenId); } + +uint32_t CommonFunc::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 tuple, unique_ptr> CommonFunc::GetCopyPathArg(napi_env env, diff --git a/interfaces/kits/js/src/mod_fs/common_func.h b/interfaces/kits/js/src/mod_fs/common_func.h index 567cf26b4..37571e691 100644 --- a/interfaces/kits/js/src/mod_fs/common_func.h +++ b/interfaces/kits/js/src/mod_fs/common_func.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -105,6 +105,7 @@ struct CommonFunc { #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 ModuleFileIO diff --git a/interfaces/kits/js/src/mod_fs/properties/copy.cpp b/interfaces/kits/js/src/mod_fs/properties/copy.cpp index ffd87bebc..621e27361 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -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 Copy::mutex_; std::map> Copy::jsCbMap_; +uint32_t g_apiCompatibleVersion = 0; static int OpenSrcFile(const string &srcPth, std::shared_ptr infos, int32_t &srcFd) { @@ -267,7 +269,20 @@ int Copy::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); -- Gitee