From 4b190fc6d1f067e3f641d886afc67db953f13ebf Mon Sep 17 00:00:00 2001 From: wangpggg Date: Fri, 8 Mar 2024 18:07:00 +0800 Subject: [PATCH] modify warnings Signed-off-by: wangpeng --- frameworks/native/backup_ext/src/tar_file.cpp | 11 +++-------- frameworks/native/backup_ext/src/untar_file.cpp | 5 ++--- .../kits/js/backup/session_backup_n_exporter.cpp | 4 ++-- .../backup/session_incremental_backup_n_exporter.cpp | 4 ++-- .../kits/js/backup/session_restore_n_exporter.cpp | 6 +++--- interfaces/kits/js/file_uri/file_uri_n_exporter.cpp | 1 - .../backup_sa/src/module_external/bms_adapter.cpp | 4 ++-- .../backup_sa/src/module_ipc/service_incremental.cpp | 2 +- .../backup_tool/src/tools_op_incremental_backup.cpp | 5 ++--- .../backup_tool/src/tools_op_incremental_restore.cpp | 12 ++---------- tools/backup_tool/src/tools_op_restore.cpp | 7 ------- utils/src/b_json/b_report_entity.cpp | 2 +- 12 files changed, 20 insertions(+), 43 deletions(-) diff --git a/frameworks/native/backup_ext/src/tar_file.cpp b/frameworks/native/backup_ext/src/tar_file.cpp index 33886e549..3a52d9dcb 100644 --- a/frameworks/native/backup_ext/src/tar_file.cpp +++ b/frameworks/native/backup_ext/src/tar_file.cpp @@ -218,9 +218,8 @@ bool TarFile::WriteFileContent(const string &fileName, off_t size) HILOGE("Failed to open file %{public}s, err = %{public}d", fileName.data(), errno); return false; } - off_t remain = size; - bool isFilled = false; + off_t remain = size; while (remain > 0) { off_t read = ioBuffer_.size(); if (remain < read) { @@ -242,11 +241,7 @@ bool TarFile::WriteFileContent(const string &fileName, off_t size) close(fd); if (remain == 0) { - if (!isFilled) { - return CompleteBlock(size); - } else { - return true; - } + return CompleteBlock(size); } return false; } @@ -262,7 +257,7 @@ off_t TarFile::SplitWriteAll(const vector &ioBuffer, off_t read) auto writeBytes = fwrite(&ioBuffer[count], sizeof(uint8_t), len - count, currentTarFile_); if (writeBytes < 1) { // 再执行一遍 - auto writeBytes = fwrite(&ioBuffer[count], sizeof(uint8_t), len - count, currentTarFile_); + writeBytes = fwrite(&ioBuffer[count], sizeof(uint8_t), len - count, currentTarFile_); if (writeBytes < 1) { HILOGE("Failed to fwrite tar file, err = %{public}d", errno); return count; diff --git a/frameworks/native/backup_ext/src/untar_file.cpp b/frameworks/native/backup_ext/src/untar_file.cpp index bf367c10b..f2814d36b 100644 --- a/frameworks/native/backup_ext/src/untar_file.cpp +++ b/frameworks/native/backup_ext/src/untar_file.cpp @@ -230,8 +230,7 @@ int UntarFile::ParseIncrementalTarFile(const string &rootPath) return ret; } - bool finished = false; - while (!finished) { + do { readCnt_ = fread(buff, 1, BLOCK_SIZE, tarFilePtr_); if (readCnt_ < BLOCK_SIZE) { HILOGE("Parsing tar file completed, read data count is less then block size."); @@ -265,7 +264,7 @@ int UntarFile::ParseIncrementalTarFile(const string &rootPath) if (ret != 0) { HILOGE("Failed to handle file property"); } - } + } while (readCnt_ >= BLOCK_SIZE); return ret; } diff --git a/interfaces/kits/js/backup/session_backup_n_exporter.cpp b/interfaces/kits/js/backup/session_backup_n_exporter.cpp index 5ee1512b8..d3252402c 100644 --- a/interfaces/kits/js/backup/session_backup_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_backup_n_exporter.cpp @@ -90,7 +90,7 @@ static void onBundleBegin(weak_ptr pCallbacks, ErrCode err, co if (!err && errCode == 0) { return bundleName; } - + NVal res; if (err) { res = NVal {env, err.GetNapiErr(env)}; @@ -129,7 +129,7 @@ static void onBundleEnd(weak_ptr pCallbacks, ErrCode err, cons if (!err && errCode == 0) { return bundleName; } - + NVal res; if (err) { res = NVal {env, err.GetNapiErr(env)}; diff --git a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp index 16f7fdcb6..6925a336a 100644 --- a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp @@ -96,7 +96,7 @@ static void onBundleBegin(weak_ptr pCallbacks, ErrCode err, co if (!err && errCode == 0) { return bundleName; } - + NVal res; if (err) { res = NVal {env, err.GetNapiErr(env)}; @@ -135,7 +135,7 @@ static void onBundleEnd(weak_ptr pCallbacks, ErrCode err, cons if (!err && errCode == 0) { return bundleName; } - + NVal res; if (err) { res = NVal {env, err.GetNapiErr(env)}; diff --git a/interfaces/kits/js/backup/session_restore_n_exporter.cpp b/interfaces/kits/js/backup/session_restore_n_exporter.cpp index e9790eec2..34afc9697 100644 --- a/interfaces/kits/js/backup/session_restore_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_restore_n_exporter.cpp @@ -133,7 +133,7 @@ static void onBundleBegin(weak_ptr pCallbacks, ErrCode err, co if (!err && errCode == 0) { return bundleName; } - + NVal res; if (err) { res = NVal {env, err.GetNapiErr(env)}; @@ -172,7 +172,7 @@ static void onBundleEnd(weak_ptr pCallbacks, ErrCode err, cons if (!err && errCode == 0) { return bundleName; } - + NVal res; if (err) { res = NVal {env, err.GetNapiErr(env)}; @@ -210,7 +210,7 @@ static void onAllBundlesEnd(weak_ptr pCallbacks, ErrCode err) if (!err && errCode == 0) { return NVal::CreateUndefined(env); } - + NVal res; if (err) { res = NVal {env, err.GetNapiErr(env)}; diff --git a/interfaces/kits/js/file_uri/file_uri_n_exporter.cpp b/interfaces/kits/js/file_uri/file_uri_n_exporter.cpp index 4917b6524..f1a212a3e 100644 --- a/interfaces/kits/js/file_uri/file_uri_n_exporter.cpp +++ b/interfaces/kits/js/file_uri/file_uri_n_exporter.cpp @@ -146,7 +146,6 @@ napi_value FileUriNExporter::GetFileUriPath(napi_env env, napi_callback_info inf NError(EINVAL).ThrowErr(env); return nullptr; } - string sandboxPath = SandboxHelper::Decode(fileuriEntity->fileUri_.uri_.GetPath()); string bundleName = fileuriEntity->fileUri_.uri_.GetAuthority(); if (bundleName == MEDIA_AUTHORITY) { return NVal::CreateUTF8String(env, fileuriEntity->fileUri_.GetPath()).val_; diff --git a/services/backup_sa/src/module_external/bms_adapter.cpp b/services/backup_sa/src/module_external/bms_adapter.cpp index d0753183d..b1f8287e9 100644 --- a/services/backup_sa/src/module_external/bms_adapter.cpp +++ b/services/backup_sa/src/module_external/bms_adapter.cpp @@ -220,11 +220,11 @@ static bool CreateIPCInteractionFiles(int32_t userId, const string &bundleName, return false; } incExcFile << BConstants::BACKUP_INCLUDE << endl; - for (auto &include : includes) { + for (const auto &include : includes) { incExcFile << include << endl; } incExcFile << BConstants::BACKUP_EXCLUDE << endl; - for (auto &exclude : excludes) { + for (const auto &exclude : excludes) { incExcFile << exclude << endl; } incExcFile.close(); diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index ec65795dc..85c39f738 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -341,7 +341,7 @@ bool Service::IncrementalBackup(const string &bundleName) append(BConstants::BACKUP_STAT_SYMBOL). append(to_string(session_->GetLastIncrementalTime(bundleName))); HILOGI("path = %{public}s", path.c_str()); - UniqueFd fdLocal(open(path.data(), O_RDWR, S_IRGRP | S_IWGRP | S_IRGRP | S_IWGRP)); + UniqueFd fdLocal(open(path.data(), O_RDWR, S_IRGRP | S_IWGRP)); // BFile::SendFile(incrementalFd, fdLocal); // 云上存在的数据 UniqueFd lastManifestFd(session_->GetIncrementalManifestFd(bundleName)); diff --git a/tools/backup_tool/src/tools_op_incremental_backup.cpp b/tools/backup_tool/src/tools_op_incremental_backup.cpp index a8c2fa1ed..8971eced5 100644 --- a/tools/backup_tool/src/tools_op_incremental_backup.cpp +++ b/tools/backup_tool/src/tools_op_incremental_backup.cpp @@ -265,7 +265,7 @@ static int GetLocalCapabilitiesIncremental(shared_ptr ctx, return -EPERM; } int num = 0; - for (auto &bundleName : bundleNames) { + for (const auto &bundleName : bundleNames) { BIncrementalData data; data.bundleName = bundleName; data.lastIncrementalTime = atoi(times[num].c_str()); @@ -281,7 +281,7 @@ static int GetLocalCapabilitiesIncremental(shared_ptr ctx, return 0; } -static int32_t Init(const string &pathCapFile, vector bundleNames, vector times) +static int32_t Init(const string &pathCapFile, const vector& bundleNames, const vector& times) { StartTrace(HITRACE_TAG_FILEMANAGEMENT, "Init"); // SELinux backup_tool工具/data/文件夹下创建文件夹 SA服务因root用户的自定义标签无写入权限 此处调整为软链接形式 @@ -308,7 +308,6 @@ static int32_t Init(const string &pathCapFile, vector bundleNames, vecto if (int ret = GetLocalCapabilitiesIncremental(ctx, pathCapFile, bundleNames, times); ret != 0) { return ret; } - vector bundlesToBackup; for (auto &data : ctx->lastIncrementalData) { string tmpPath = string(BConstants::BACKUP_TOOL_INCREMENTAL_RECEIVE_DIR) + data.bundleName; if (access(tmpPath.data(), F_OK) != 0 && mkdir(tmpPath.data(), S_IRWXU) != 0) { diff --git a/tools/backup_tool/src/tools_op_incremental_restore.cpp b/tools/backup_tool/src/tools_op_incremental_restore.cpp index ffab7d1e5..ab635a44d 100644 --- a/tools/backup_tool/src/tools_op_incremental_restore.cpp +++ b/tools/backup_tool/src/tools_op_incremental_restore.cpp @@ -95,16 +95,8 @@ public: private: struct BundleStatus { set sendFile; - set sentFile; }; - void TryClearBundleOfMap(const BundleName &bundleName) - { - if (bundleStatusMap_[bundleName].sendFile == bundleStatusMap_[bundleName].sentFile) { - bundleStatusMap_.erase(bundleName); - } - } - map bundleStatusMap_; mutable condition_variable cv_; mutex lock_; @@ -242,7 +234,7 @@ static bool GetRealPath(string &path) } static int32_t InitRestoreSession(shared_ptr ctx, - vector &bundleNames, + const vector &bundleNames, vector ×) { if (bundleNames.size() != times.size()) { @@ -265,7 +257,7 @@ static int32_t InitRestoreSession(shared_ptr ctx, } int num = 0; - for (auto &bundleName : bundleNames) { + for (const auto &bundleName : bundleNames) { BIncrementalData data; data.bundleName = bundleName; data.lastIncrementalTime = atoi(times[num].c_str()); diff --git a/tools/backup_tool/src/tools_op_restore.cpp b/tools/backup_tool/src/tools_op_restore.cpp index 31b52d323..5e7916c07 100644 --- a/tools/backup_tool/src/tools_op_restore.cpp +++ b/tools/backup_tool/src/tools_op_restore.cpp @@ -96,13 +96,6 @@ private: set sentFile; }; - void TryClearBundleOfMap(const BundleName &bundleName) - { - if (bundleStatusMap_[bundleName].sendFile == bundleStatusMap_[bundleName].sentFile) { - bundleStatusMap_.erase(bundleName); - } - } - map bundleStatusMap_; mutable condition_variable cv_; mutex lock_; diff --git a/utils/src/b_json/b_report_entity.cpp b/utils/src/b_json/b_report_entity.cpp index 118119cf6..6290f046c 100644 --- a/utils/src/b_json/b_report_entity.cpp +++ b/utils/src/b_json/b_report_entity.cpp @@ -119,7 +119,7 @@ static void DealLine(unordered_map &keys, { string currentLine = line; if (currentLine[currentLine.length() - 1] == LINE_WRAP) { - currentLine = currentLine.substr(0, currentLine.length() - 1); + currentLine.pop_back(); } vector splits = SplitStringByChar(currentLine, ATTR_SEP); -- Gitee