diff --git a/interfaces/kits/js/src/mod_fs/properties/copy.cpp b/interfaces/kits/js/src/mod_fs/properties/copy.cpp old mode 100644 new mode 100755 index ffd87bebc2837bedbe60dee1932da8dd4acb3846..f95664871cd85478b14053a82f701d7a734506ea --- a/interfaces/kits/js/src/mod_fs/properties/copy.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copy.cpp @@ -15,6 +15,7 @@ #include "copy.h" +#include #include #include #include @@ -54,6 +55,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 unint32_t API_VERSION_MOD = 1000; constexpr int DISMATCH = 0; constexpr int MATCH = 1; constexpr int BUF_SIZE = 1024; @@ -61,6 +63,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_; +unint32_t g_apiCompatibleVersion = 0; static int OpenSrcFile(const string &srcPth, std::shared_ptr infos, int32_t &srcFd) { @@ -259,6 +262,29 @@ int Copy::CheckOrCreatePath(const std::string &destPath) return ERRNO_NOERR; } +uint32_t Copy::GetApiCompatibleVersion() +{ + uint32_t apiCompatibleVersion = 0; + OHOS::sptr systemAbilityManager = + OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + OHOS::sptr remoteObject = + systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); + sptr iBundleMgr = OHOS::iface_cast(remoteObject); + if (iBundleMgr == nullptr) { + HILOGD("IBundleMgr is null"); + return apiCompatibleVersion; + } + AppExecFwk::BundleInfo bundleInfo; + if (iBundleMgr->GetBundleInfoForSelf(0, bundleInfo) == ERR_OK) { + apiCompatibleVersion = bundleInfo.targetVersion % API_VERSION_MOD; + HILOGD("targetVersion: [%{public}u], apiCompatibleVersion: [%{public}u]", bundleInfo.targetVersion, + apiCompatibleVersion); + } else { + HILOGD("Call for GetApiCompatibleVersion failed"); + } + return apiCompatibleVersion; +} + int Copy::CopyFile(const string &src, const string &dest, std::shared_ptr infos) { HILOGD("src = %{public}s, dest = %{public}s", GetAnonyString(src).c_str(), GetAnonyString(dest).c_str()); @@ -267,7 +293,18 @@ int Copy::CopyFile(const string &src, const string &dest, std::shared_ptr= 20) { + 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);