From 082d7cedcf23d4214efe3605c33a8e001ae97ab8 Mon Sep 17 00:00:00 2001 From: nieben Date: Wed, 31 Jan 2024 11:08:04 +0800 Subject: [PATCH] feature-incre-review-change Signed-off-by: nieben --- .../native/backup_ext/src/ext_extension.cpp | 65 +++++++++++-------- .../native/backup_ext/src/untar_file.cpp | 2 +- .../src/module_ipc/service_incremental.cpp | 4 +- 3 files changed, 42 insertions(+), 29 deletions(-) diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 3c29b896c..d07943922 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -545,12 +545,19 @@ int BackupExtExtension::DoRestore(const string &fileName) static map GetTarIncludes(const string &tarName) { - // 获取简报文件内容 - string reportName = GetReportFileName(tarName); + map includes {}; + string reportName = GetReportFileName(tarName); // 获取简报内容 - BReportEntity rp(UniqueFd(open(reportName.data(), O_RDONLY))); - return rp.GetReportInfos(); + UniqueFd fd (open(reportName.data(), O_RDONLY)); + if (fd < 0) { + HILOGE("Failed to open report file %{private}s, err = %{public}d", reportName.c_str(), errno); + return includes; + } + + BReportEntity rp(move(fd)); + includes = rp.GetReportInfos(); + return includes; } int BackupExtExtension::DoIncrementalRestore(const string &fileName) @@ -570,7 +577,7 @@ int BackupExtExtension::DoIncrementalRestore(const string &fileName) } else { UntarFile::GetInstance().IncrementalUnPacket(tarName, "/", GetTarIncludes(tarName)); } - HILOGI("Application recovered successfully, package path is %{public}s", tarName.c_str()); + HILOGI("Application recovered successfully, package path is %{private}s", tarName.c_str()); return ERR_OK; } @@ -797,30 +804,36 @@ static void DeleteBackupTars() static void DeleteBackupIncrementalTars() { // The directory include tars and manage.json which would be deleted - BJsonCachedEntity cachedEntity(UniqueFd(open(INDEX_FILE_RESTORE.data(), O_RDONLY))); - auto cache = cachedEntity.Structuralize(); - auto info = cache.GetExtManage(); - auto path = string(BConstants::PATH_BUNDLE_BACKUP_HOME).append(BConstants::SA_BUNDLE_BACKUP_RESTORE); - for (auto &item : info) { - if (ExtractFileExt(item) != "tar" || IsUserTar(item, INDEX_FILE_RESTORE)) { - continue; - } - string tarPath = path + item; - if (!RemoveFile(tarPath)) { - HILOGE("Failed to delete the backup tar %{private}s, err = %{public}d", tarPath.c_str(), errno); - } - // 删除简报文件 - string reportPath = GetReportFileName(tarPath); - if (!RemoveFile(reportPath)) { - HILOGE("Failed to delete the backup report %{private}s, err = %{public}d", reportPath.c_str(), errno); + UniqueFd fd (open(INDEX_FILE_RESTORE.data(), O_RDONLY)); + if (fd < 0) { + HILOGE("Failed to open file %{private}s, err = %{public}d", INDEX_FILE_RESTORE.data(), errno); + } else { + BJsonCachedEntity cachedEntity(move(fd)); + auto cache = cachedEntity.Structuralize(); + auto info = cache.GetExtManage(); + auto path = string(BConstants::PATH_BUNDLE_BACKUP_HOME).append(BConstants::SA_BUNDLE_BACKUP_RESTORE); + for (auto &item : info) { + if (ExtractFileExt(item) != "tar" || IsUserTar(item, INDEX_FILE_RESTORE)) { + continue; + } + string tarPath = path + item; + if (!RemoveFile(tarPath)) { + HILOGE("Failed to delete the backup tar %{private}s, err = %{public}d", tarPath.c_str(), errno); + } + // 删除简报文件 + string reportPath = GetReportFileName(tarPath); + if (!RemoveFile(reportPath)) { + HILOGE("Failed to delete the backup report %{private}s, err = %{public}d", reportPath.c_str(), errno); + } } } if (!RemoveFile(INDEX_FILE_RESTORE)) { - HILOGE("Failed to delete the backup index %{public}s", INDEX_FILE_RESTORE.c_str()); + HILOGE("Failed to delete the backup index %{private}s, err = %{public}d", INDEX_FILE_RESTORE.c_str(), errno); } string reportManagePath = GetReportFileName(INDEX_FILE_RESTORE); // GetIncrementalFileHandle创建的空fd if (!RemoveFile(reportManagePath)) { - HILOGE("Failed to delete the backup report index %{public}s", reportManagePath.c_str()); + HILOGE("Failed to delete the backup report index %{private}s, err = %{public}d", + reportManagePath.c_str(), errno); } } @@ -1225,7 +1238,7 @@ static void WriteFile(const string &filename, const mapAppIncrementalFileReady(item.first, std::move(fd), UniqueFd(open(file.data(), O_RDONLY))); if (SUCCEEDED(ret)) { - HILOGI("IncrementalBigFileReady:The application is packaged successfully, package name is %{public}s", + HILOGI("IncrementalBigFileReady:The application is packaged successfully, package name is %{private}s", item.first.c_str()); RemoveFile(file); } else { diff --git a/frameworks/native/backup_ext/src/untar_file.cpp b/frameworks/native/backup_ext/src/untar_file.cpp index ebff9a541..13abfc8d5 100644 --- a/frameworks/native/backup_ext/src/untar_file.cpp +++ b/frameworks/native/backup_ext/src/untar_file.cpp @@ -100,7 +100,7 @@ int UntarFile::IncrementalUnPacket(const string &tarFile, const string &rootPath includes_ = includes; tarFilePtr_ = fopen(tarFile.c_str(), "rb"); if (tarFilePtr_ == nullptr) { - HILOGE("Failed to open tar file %{public}s, err = %{public}d", tarFile.c_str(), errno); + HILOGE("Failed to open tar file %{private}s, err = %{public}d", tarFile.c_str(), errno); return errno; } diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index 7c737f4de..f6d2af212 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -340,7 +340,7 @@ bool Service::IncrementalBackup(const string &bundleName) append("/"). append(BConstants::BACKUP_STAT_SYMBOL). append(to_string(session_->GetLastIncrementalTime(bundleName))); - HILOGI("path = %{public}s", path.c_str()); + HILOGI("path = %{private}s", path.c_str()); UniqueFd fdLocal(open(path.data(), O_RDWR, S_IRGRP | S_IWGRP | S_IRGRP | S_IWGRP)); // BFile::SendFile(incrementalFd, fdLocal); // 云上存在的数据 @@ -358,7 +358,7 @@ bool Service::IncrementalBackup(const string &bundleName) for (auto &fileName : fileNameVec) { ret = proxy->GetIncrementalFileHandle(fileName); if (ret) { - HILOGE("Failed to extension file handle %{public}s", fileName.c_str()); + HILOGE("Failed to extension file handle %{private}s", fileName.c_str()); } } return true; -- Gitee