diff --git a/frameworks/native/backup_ext/src/ext_backup_js.cpp b/frameworks/native/backup_ext/src/ext_backup_js.cpp index 103bd8b0b6c06b6487ddbd4e2c24f1318c142fff..fa9ea8bb310dfb38178b514781caada552ff7777 100644 --- a/frameworks/native/backup_ext/src/ext_backup_js.cpp +++ b/frameworks/native/backup_ext/src/ext_backup_js.cpp @@ -852,8 +852,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 77252b298ac621d30251438736c04a329537a8ef..2e6c7f9f358ca1b315ed92ae6b5afb9424792cf1 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -332,24 +332,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) @@ -359,31 +361,43 @@ 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 = %{public}s, err =%{public}d", GetAnonyPath(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 = %{public}s, err = %{public}d", GetAnonyPath(tarName).c_str(), errno); - errCode = errno; - AuditLog auditLog = {false, "Open fd failed", "ADD", "", 1, "FAILED", - "GetIncreFileHandleForNormalVersion", "CommonFile", GetAnonyPath(tarName)}; - HiAudit::GetInstance(false).Write(auditLog); - } - // 对应的简报文件 - 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); + errCode = 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; + AuditLog auditLog = {false, "Open fd failed", "ADD", "", 1, "FAILED", + "GetIncreFileHandleForNormalVersion", "CommonFile", GetAnonyPath(tarName)}; + HiAudit::GetInstance(false).Write(auditLog); + 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); + errCode = 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) { diff --git a/frameworks/native/backup_ext/src/sub_ext_extension.cpp b/frameworks/native/backup_ext/src/sub_ext_extension.cpp index 3586eab8606acec09d386ba4ceb7483b11095bac..71463bde160fab05a6b77f697f6026580b140010 100644 --- a/frameworks/native/backup_ext/src/sub_ext_extension.cpp +++ b/frameworks/native/backup_ext/src/sub_ext_extension.cpp @@ -976,6 +976,7 @@ static TarMap GetIncrmentBigInfos(const vector &files) for (const auto &item : files) { struct stat sta = {}; if (stat(item.filePath.c_str(), &sta) != 0) { + HILOGE("Failed to stat file %{public}s, err = %{public}d", item.filePath.c_str(), errno); throw BError(BError::Codes::EXT_INVAL_ARG, "Get file stat failed"); } string md5Name = getStringHash(bigFiles, item.filePath);