From 584f5bb1a9d3da7bb2e8531c69c9f412ee233482 Mon Sep 17 00:00:00 2001 From: "Zhangyao(Maggie)" Date: Fri, 20 Dec 2024 14:42:58 +0800 Subject: [PATCH] onFileReady report Signed-off-by: Zhangyao(Maggie) --- .../native/backup_ext/src/ext_backup_js.cpp | 5 +- .../native/backup_ext/src/ext_extension.cpp | 68 +++++++++++-------- 2 files changed, 44 insertions(+), 29 deletions(-) diff --git a/frameworks/native/backup_ext/src/ext_backup_js.cpp b/frameworks/native/backup_ext/src/ext_backup_js.cpp index d6293eaa8..4de154106 100644 --- a/frameworks/native/backup_ext/src/ext_backup_js.cpp +++ b/frameworks/native/backup_ext/src/ext_backup_js.cpp @@ -817,8 +817,11 @@ int ExtBackupJs::CallJsMethod(const std::string &funcName, work->data = reinterpret_cast(param.get()); HILOGI("Will execute current js method"); int ret = uv_queue_work( - loop, work.get(), [](uv_work_t *work) {}, + loop, work.get(), [](uv_work_t *work) { + HILOGI("Enter, %{public}zu", (size_t)work); + }, [](uv_work_t *work, int status) { + HILOGI("AsyncWork Enter, %{public}zu", (size_t)work); CallJsParam *param = reinterpret_cast(work->data); do { if (param == nullptr) { diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index a10fbcf63..c3dbed240 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -315,24 +315,26 @@ static ErrCode GetIncreFileHandleForSpecialVersion(const string &fileName) return ERR_OK; } -static string GetIncrementalFileHandlePath(const string &fileName, const string &bundleName) +static ErrCode GetIncrementalFileHandlePath(const string &fileName, const string &bundleName, std::string &tarName) { string path = string(BConstants::PATH_BUNDLE_BACKUP_HOME).append(BConstants::SA_BUNDLE_BACKUP_RESTORE); if (BFile::EndsWith(bundleName, BConstants::BUNDLE_FILE_MANAGER) && bundleName.size() == BConstants::FM_LEN) { if (mkdir(string(BConstants::PATH_FILEMANAGE_BACKUP_HOME).data(), S_IRWXU) && errno != EEXIST) { - string str = string("Failed to create .backup folder. ").append(std::generic_category().message(errno)); - throw BError(BError::Codes::EXT_INVAL_ARG, str); + string errMsg = string("Failed to create .backup folder. ").append(std::generic_category().message(errno)); + HILOGE("%{public}s, errno = %{public}d", errMsg.c_str(), errno); + return errno; } path = string(BConstants::PATH_FILEMANAGE_BACKUP_HOME).append(BConstants::SA_BUNDLE_BACKUP_RESTORE); } else if (bundleName == BConstants::BUNDLE_MEDIAL_DATA) { path = string(BConstants::PATH_MEDIALDATA_BACKUP_HOME).append(BConstants::SA_BUNDLE_BACKUP_RESTORE); } if (mkdir(path.data(), S_IRWXU) && errno != EEXIST) { - string str = string("Failed to create restore folder. ").append(std::generic_category().message(errno)); - throw BError(BError::Codes::EXT_INVAL_ARG, str); + string errMsg = string("Failed to create restore folder. ").append(std::generic_category().message(errno)); + HILOGE("%{public}s, errno = %{public}d", errMsg.c_str(), errno); + return errno; } - string tarName = path + fileName; - return tarName; + tarName = path + fileName; + return ERR_OK; } ErrCode BackupExtExtension::GetIncreFileHandleForNormalVersion(const std::string &fileName) @@ -342,28 +344,38 @@ ErrCode BackupExtExtension::GetIncreFileHandleForNormalVersion(const std::string if (proxy == nullptr) { throw BError(BError::Codes::EXT_BROKEN_IPC, string("Failed to AGetInstance")); } - string tarName = GetIncrementalFileHandlePath(fileName, bundleName_); + std::string tarName; int32_t errCode = ERR_OK; - if (access(tarName.c_str(), F_OK) == 0) { - HILOGE("The file already exists, tarname = %{private}s, err =%{public}d", tarName.c_str(), errno); - errCode = errno; - } - UniqueFd fd(open(tarName.data(), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)); - if (fd < 0) { - HILOGE("Failed to open tar file = %{private}s, err = %{public}d", tarName.c_str(), errno); - errCode = errno; - } - // 对应的简报文件 - string reportName = GetReportFileName(tarName); - if (access(reportName.c_str(), F_OK) == 0) { - HILOGE("The report file already exists, Name = %{private}s, err =%{public}d", reportName.c_str(), errno); - errCode = errno; - } - UniqueFd reportFd(open(reportName.data(), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)); - if (reportFd < 0) { - HILOGE("Failed to open report file = %{private}s, err = %{public}d", reportName.c_str(), errno); - errCode = errno; - } + UniqueFd fd(-1); + UniqueFd reportFd(-1); + do { + errCode = GetIncrementalFileHandlePath(fileName, bundleName_, tarName); + if (errCode != ERR_OK) { + HILOGE("GetIncrementalFileHandlePath failed, err = %{public}d", errCode); + break; + } + if (access(tarName.c_str(), F_OK) == 0) { + HILOGE("The file already exists, tarname = %{public}s, err =%{public}d", + GetAnonyPath(tarName).c_str(), errno); + } + fd = UniqueFd(open(tarName.data(), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)); + if (fd < 0) { + HILOGE("Failed to open tar file = %{public}s, err = %{public}d", GetAnonyPath(tarName).c_str(), errno); + errCode = errno; + break; + } + // 对应的简报文件 + string reportName = GetReportFileName(tarName); + if (access(reportName.c_str(), F_OK) == 0) { + HILOGE("The report file already exists, Name = %{private}s, err =%{public}d", reportName.c_str(), errno); + } + reportFd = UniqueFd(open(reportName.data(), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)); + if (reportFd < 0) { + HILOGE("Failed to open report file = %{private}s, err = %{public}d", reportName.c_str(), errno); + errCode = errno; + break; + } + } while (0); HILOGI("extension: Will notify AppIncrementalFileReady"); auto ret = proxy->AppIncrementalFileReady(fileName, move(fd), move(reportFd), errCode); if (ret != ERR_OK) { -- Gitee