diff --git a/frameworks/native/backup_ext/BUILD.gn b/frameworks/native/backup_ext/BUILD.gn index eb044ee941024402744b702b845a89ec4965dbec..ee46ddb114a86b628efb0df907affa5e2ce6cb88 100644 --- a/frameworks/native/backup_ext/BUILD.gn +++ b/frameworks/native/backup_ext/BUILD.gn @@ -50,6 +50,7 @@ ohos_shared_library("backup_extension_ability_native") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/interfaces/innerkits/native:sandbox_helper_native", "${path_backup}/utils:backup_utils", "${path_jsoncpp}:jsoncpp", ] diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index f3cc2c8bdee3f7a5a8b8f738b10788cdb61be5d5..3fc0430377203a6532b7f648643a9881815f6567 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -50,6 +50,7 @@ #include "b_tarball/b_tarball_factory.h" #include "filemgmt_libhilog.h" #include "hitrace_meter.h" +#include "sandbox_helper.h" #include "service_proxy.h" #include "tar_file.h" #include "untar_file.h" @@ -799,10 +800,16 @@ static void RestoreBigFiles(bool appendTargetPath) continue; } - string fileName = path + item.hashName; - string filePath = appendTargetPath ? (path + item.fileName) : item.fileName; + string itemHashName = item.hashName; + string itemFileName = item.fileName; - if (!RestoreBigFilePrecheck(fileName, path, item.hashName, filePath)) { + BReportEntity::DecodeReportItem(item.hashName, itemHashName, true); + BReportEntity::DecodeReportItem(item.fileName, itemFileName, true); + + string fileName = path + itemHashName; + string filePath = appendTargetPath ? (path + itemFileName) : itemFileName; + + if (!RestoreBigFilePrecheck(fileName, path, itemHashName, filePath)) { continue; } @@ -1340,7 +1347,9 @@ static void WriteFile(const string &filename, const map GetReportInfos(); + /** + * @brief encode report item + */ + static void EncodeReportItem(const std::string &reportItem, std::string& encodeItem, bool enableEncode); + + /** + * @brief decode report item + */ + static void DecodeReportItem(const std::string &reportItem, std::string& decodeItem, bool enableEncode); + public: /** * @brief 构造方法 diff --git a/utils/src/b_json/b_report_entity.cpp b/utils/src/b_json/b_report_entity.cpp index 02fbb3c68cec1b3f66862ae3f9a008af725de97d..1551cff2570644c014ec4e1c37d1e6ed8f21312a 100644 --- a/utils/src/b_json/b_report_entity.cpp +++ b/utils/src/b_json/b_report_entity.cpp @@ -23,6 +23,7 @@ #include "b_error/b_error.h" #include "filemgmt_libhilog.h" +#include "sandbox_helper.h" #include "unique_fd.h" namespace OHOS::FileManagement::Backup { @@ -80,7 +81,7 @@ static ErrCode ParseReportInfo(struct ReportFileInfo &fileStat, return EPERM; } path = (path.length() > 0 && path[0] == '/') ? path.substr(1, path.length() - 1) : path; - fileStat.filePath = path.substr(0, path.length() - 1); + BReportEntity::DecodeReportItem(path.substr(0, path.length() - 1), fileStat.filePath, true); if (keys.find(INFO_MODE) != keys.end()) { fileStat.mode = residue[keys.find(INFO_MODE)->second]; } @@ -169,4 +170,23 @@ unordered_map BReportEntity::GetReportInfos() return infos; } + +void BReportEntity::EncodeReportItem(const string &reportItem, string& encodeItem, bool enableEncode) +{ + if (enableEncode) { + encodeItem = AppFileService::SandboxHelper::Encode(reportItem); + } else { + encodeItem = reportItem; + } +} + +void BReportEntity::DecodeReportItem(const string &reportItem, string& decodeItem, bool enableEncode) +{ + if (enableEncode) { + decodeItem = AppFileService::SandboxHelper::Decode(reportItem); + } else { + decodeItem = reportItem; + } +} + } // namespace OHOS::FileManagement::Backup \ No newline at end of file