共 41 个文件变更+691-100
@@ -126,7 +126,7 @@ public:
126 ErrCode HandleOnRelease(int32_t scenario) override;126 ErrCode HandleOnRelease(int32_t scenario) override;
127 ErrCode HandleGetCompatibilityInfo(const string &extInfo, int32_t scenario, bool isExist,127 ErrCode HandleGetCompatibilityInfo(const string &extInfo, int32_t scenario, bool isExist,
128 string &compatibilityInfo) override;128 string &compatibilityInfo) override;
129- ErrCode GetIncrementalFileHandles(const std::vector<std::string> &fileNames,129+ ErrCode GetIncrementalFileHandles(const BStringRawData &fileNamesRD,
130 std::vector<FileOpenResult> &openResults) override;130 std::vector<FileOpenResult> &openResults) override;
131public:131public:
132 explicit BackupExtExtension(const std::shared_ptr<Backup::ExtBackup> &extension,132 explicit BackupExtExtension(const std::shared_ptr<Backup::ExtBackup> &extension,
@@ -25,7 +25,7 @@
25#include "service_client.h"25#include "service_client.h"
26 26 
27namespace OHOS::FileManagement::Backup {27namespace OHOS::FileManagement::Backup {
28-constexpr size_t MAX_IPC_SEND_DATA_SIZE = static_cast<size_t>(1024 * 1024);28+constexpr size_t MAX_IPC_SEND_DATA_SIZE = static_cast<size_t>(100 * 1024);
29constexpr double IPC_SEND_DATA_SCALE_FACTOR = 0.75;29constexpr double IPC_SEND_DATA_SCALE_FACTOR = 0.75;
30constexpr size_t SAFE_IPC_SEND_DATA_SIZE = static_cast<size_t>(MAX_IPC_SEND_DATA_SIZE * IPC_SEND_DATA_SCALE_FACTOR);30constexpr size_t SAFE_IPC_SEND_DATA_SIZE = static_cast<size_t>(MAX_IPC_SEND_DATA_SIZE * IPC_SEND_DATA_SCALE_FACTOR);
31constexpr size_t VECTOR_MAX_SIZE = 102400;31constexpr size_t VECTOR_MAX_SIZE = 102400;
@@ -425,8 +425,8 @@ FileOpenResult BackupExtExtension::GetIncreFileHandleForUntarNormalVersion(const
425 fd = UniqueFd(open(realDir.c_str(), O_RDWR | O_CREAT | O_TRUNC | O_UNCACHE, S_IRUSR | S_IWUSR));425 fd = UniqueFd(open(realDir.c_str(), O_RDWR | O_CREAT | O_TRUNC | O_UNCACHE, S_IRUSR | S_IWUSR));
426 if (fd < 0) {426 if (fd < 0) {
427 errCode = errno;427 errCode = errno;
428- HILOGE("Failed to open file, path:%{public}s, errno:%{public}d", GetAnonyPath(realDir).c_str(),428+ HILOGE("Failed to open file, errno:%{public}d, path len:%{public}zu, path:%{public}s", errCode,
429- errCode);429+ realDir.size(), GetAnonyPath(realDir).c_str());
430 break;430 break;
431 }431 }
432 } while (0);432 } while (0);
@@ -444,10 +444,13 @@ ErrCode BackupExtExtension::GetIncrementalFileHandle(const std::string &fileName
444 return ERR_OK;444 return ERR_OK;
445}445}
446 446 
447-ErrCode BackupExtExtension::GetIncrementalFileHandles(const std::vector<std::string> &fileNames,447+ErrCode BackupExtExtension::GetIncrementalFileHandles(const BStringRawData &fileNamesRD,
448 std::vector<FileOpenResult> &openResults)448 std::vector<FileOpenResult> &openResults)
449{449{
450 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);450 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
451+ std::string serializedData;
452+ fileNamesRD.Unmarshalling(serializedData);
453+ auto fileNames = StringUtils::StringVectorDeserialize(serializedData);
451 HILOGI("Enter GetIncrementalFileHandles, input file count: %{public}zu, output container size: %{public}zu",454 HILOGI("Enter GetIncrementalFileHandles, input file count: %{public}zu, output container size: %{public}zu",
452 fileNames.size(), openResults.size());455 fileNames.size(), openResults.size());
453 try {456 try {
@@ -772,12 +775,16 @@ ErrCode BackupExtExtension::ReportAppFileReadys(std::vector<std::shared_ptr<IFil
772 775 
773 int reportRsWithoutFd = ERR_OK;776 int reportRsWithoutFd = ERR_OK;
774 if (!abnormalfileNames.empty()) {777 if (!abnormalfileNames.empty()) {
775- reportRsWithoutFd = proxy->AppFileReadysWithoutFd(abnormalfileNames, errCodes);778+ BStringRawData abnormalfileNamesRD;
779+ abnormalfileNamesRD.Marshalling(StringUtils::StringVectorSerialize(abnormalfileNames));
780+ reportRsWithoutFd = proxy->AppFileReadysWithoutFd(abnormalfileNamesRD, errCodes);
776 }781 }
777 782 
778 vector<int> temp(normalfds.size(), ERR_OK);783 vector<int> temp(normalfds.size(), ERR_OK);
779 HILOGI("send get file Names length %{public}zu", fileNames.size());784 HILOGI("send get file Names length %{public}zu", fileNames.size());
780- int reportRs = proxy->AppFileReadys(fileNames, normalfds, temp);785+ BStringRawData fileNamesRD;
786+ fileNamesRD.Marshalling(StringUtils::StringVectorSerialize(fileNames));
787+ int reportRs = proxy->AppFileReadys(fileNamesRD, normalfds, temp);
781 for (auto fdval : normalfds) {788 for (auto fdval : normalfds) {
782 CloseFileWithFDSan(fdval);789 CloseFileWithFDSan(fdval);
783 }790 }
@@ -1513,16 +1520,18 @@ void BackupExtExtension::RestoreOneBigFile(const std::string &path, const ExtMan
1513{1520{
1514 string itemHashName = item.hashName;1521 string itemHashName = item.hashName;
1515 string itemFileName = item.fileName;1522 string itemFileName = item.fileName;
1516- // check if item.hasName and fileName need decode by report item attribute1523+ if (!item.isLongPath) {
1517- string reportPath = GetReportFileName(path + item.hashName);1524+ // check if item.hasName and fileName need decode by report item attribute
1518- UniqueFd fd(open(reportPath.data(), O_RDONLY | O_UNCACHE));1525+ string reportPath = GetReportFileName(path + item.hashName);
1519- if (fd < 0) {1526+ UniqueFd fd(open(reportPath.data(), O_RDONLY | O_UNCACHE));
1520- HILOGE("Failed to open report file = %{public}s, err = %{public}d", reportPath.c_str(), errno);1527+ if (fd < 0) {
1521- errFileInfos_[item.hashName].emplace_back(errno);1528+ HILOGE("Failed to open report file = %{public}s, err = %{public}d", reportPath.c_str(), errno);
1522- throw BError(BError::Codes::EXT_INVAL_ARG, string("open report file failed"));1529+ errFileInfos_[item.hashName].emplace_back(errno);
1530+ throw BError(BError::Codes::EXT_INVAL_ARG, string("open report file failed"));
1531+ }
1532+ BReportEntity rp(move(fd));
1533+ rp.CheckAndUpdateIfReportLineEncoded(itemFileName);
1523 }1534 }
1524- BReportEntity rp(move(fd));
1525- rp.CheckAndUpdateIfReportLineEncoded(itemFileName);
1526 1535 
1527 string fileName = path + itemHashName;1536 string fileName = path + itemHashName;
1528 string filePath = appendTargetPath ? (path + itemFileName) : itemFileName;1537 string filePath = appendTargetPath ? (path + itemFileName) : itemFileName;
@@ -1576,7 +1585,7 @@ void BackupExtExtension::RestoreBigFiles(bool appendTargetPath)
1576 ancoStats.push_back(item.sta);1585 ancoStats.push_back(item.sta);
1577 continue;1586 continue;
1578 }1587 }
1579- if (GetSupportWithoutTar() && !StringUtils::IsAncoFile(item.hashName)) {1588+ if (!item.isLongPath && (GetSupportWithoutTar() && !StringUtils::IsAncoFile(item.hashName))) {
1580 continue;1589 continue;
1581 }1590 }
1582 RestoreOneBigFile(path, item, appendTargetPath);1591 RestoreOneBigFile(path, item, appendTargetPath);
@@ -1692,7 +1692,7 @@ void BackupExtExtension::DoBackupTaskCore(
1692 continue;1692 continue;
1693 }1693 }
1694 bool isWithoutTarFile = supportWithoutTar && !fileInfo->isAncoFile_;1694 bool isWithoutTarFile = supportWithoutTar && !fileInfo->isAncoFile_;
1695- if (isWithoutTarFile) {1695+ if (isWithoutTarFile && !fileInfo->isLongPath_) {
1696 std::string restorePath = fileInfo->GetRestorePath();1696 std::string restorePath = fileInfo->GetRestorePath();
1697 fileInfo->filename_ = restorePath.empty() ? fileInfo->filePath_ : restorePath;1697 fileInfo->filename_ = restorePath.empty() ? fileInfo->filePath_ : restorePath;
1698 }1698 }
@@ -2090,7 +2090,7 @@ void BackupExtExtension::ClearPublicTempFiles()
2090std::string BackupExtExtension::FileInfoToString(std::shared_ptr<IFileInfo> fileInfo)2090std::string BackupExtExtension::FileInfoToString(std::shared_ptr<IFileInfo> fileInfo)
2091{2091{
2092 Json::Value value;2092 Json::Value value;
2093- if (fileInfo->isAncoFile_) {2093+ if (fileInfo->isAncoFile_ || fileInfo->isLongPath_) {
2094 value["path"] = fileInfo->filename_;2094 value["path"] = fileInfo->filename_;
2095 } else {2095 } else {
2096 std::string restorePath = fileInfo->GetRestorePath();2096 std::string restorePath = fileInfo->GetRestorePath();
@@ -2178,7 +2178,8 @@ void BackupExtExtension::DoAppendFiles(const std::vector<std::shared_ptr<IFileIn
2178 item->isBigFile_ &&2178 item->isBigFile_ &&
2179 BJsonEntityExtManage::CheckUserTar(item->filePath_, item->sta_, item->isAncoFile_, isSupportWithoutTar);2179 BJsonEntityExtManage::CheckUserTar(item->filePath_, item->sta_, item->isAncoFile_, isSupportWithoutTar);
2180 value["isBigFile"] = item->isBigFile_;2180 value["isBigFile"] = item->isBigFile_;
2181- if (isSupportWithoutTar) {2181+ value["isLongPath"] = item->isLongPath_;
2182+ if (isSupportWithoutTar && !item->isLongPath_) {
2182 value["information"]["stat"]["st_size"] = static_cast<int64_t>(item->sta_.st_size);2183 value["information"]["stat"]["st_size"] = static_cast<int64_t>(item->sta_.st_size);
2183 value["information"]["stat"]["st_mode"] = static_cast<int32_t>(item->sta_.st_mode);2184 value["information"]["stat"]["st_mode"] = static_cast<int32_t>(item->sta_.st_mode);
2184 } else {2185 } else {
@@ -94,16 +94,16 @@ public:
94 ErrCode IncrementalRestoreOnMigrateResult(int32_t errCode, const std::string &bundleName) override;94 ErrCode IncrementalRestoreOnMigrateResult(int32_t errCode, const std::string &bundleName) override;
95 95 
96 ErrCode IncrementalRestoreOnFileReadys(const std::string &bundleName,96 ErrCode IncrementalRestoreOnFileReadys(const std::string &bundleName,
97- const std::vector<std::string> &fileNames,97+ const BStringRawData &fileNamesRD,
98 const std::vector<FileOpenResult> &openResults) override;98 const std::vector<FileOpenResult> &openResults) override;
99 99
100 ErrCode SetBatchSize(uint32_t size) override;100 ErrCode SetBatchSize(uint32_t size) override;
101 101
102 ErrCode BackupOnFileReadysWithoutFd(const std::string &bundleName,102 ErrCode BackupOnFileReadysWithoutFd(const std::string &bundleName,
103- const std::vector<std::string> &fileNames,103+ const BStringRawData &fileNamesRD,
104 const std::vector<int> &errCodes) override;104 const std::vector<int> &errCodes) override;
105 ErrCode BackupOnFileReadys(const std::string &bundleName,105 ErrCode BackupOnFileReadys(const std::string &bundleName,
106- const std::vector<std::string> &fileNames,106+ const BStringRawData &fileNamesRD,
107 const std::vector<int> &fds,107 const std::vector<int> &fds,
108 const std::vector<int> &errCodes) override;108 const std::vector<int> &errCodes) override;
109 109 
@@ -148,7 +148,9 @@ ErrCode BIncrementalRestoreSession::GetFileHandles(const string &bundleName, con
148 }148 }
149 HILOGI("Begin getFileHandles, bundle:%{public}s, fileNameSize:%{public}zu", bundleName.c_str(),149 HILOGI("Begin getFileHandles, bundle:%{public}s, fileNameSize:%{public}zu", bundleName.c_str(),
150 fileNames.size());150 fileNames.size());
151- return proxy->GetIncrementalFileHandles(bundleName, fileNames);151+ BStringRawData fileNamesRD;
152+ fileNamesRD.Marshalling(StringUtils::StringVectorSerialize(fileNames));
153+ return proxy->GetIncrementalFileHandles(bundleName, fileNamesRD);
152}154}
153 155 
154ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, vector<BundleName> bundlesToRestore)156ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, vector<BundleName> bundlesToRestore)
@@ -230,13 +230,16 @@ ErrCode ServiceReverse::IncrementalRestoreOnFileReadyWithoutFd(const std::string
230}230}
231 231 
232ErrCode ServiceReverse::IncrementalRestoreOnFileReadys(const std::string &bundleName,232ErrCode ServiceReverse::IncrementalRestoreOnFileReadys(const std::string &bundleName,
233- const std::vector<std::string> &fileNames,233+ const BStringRawData &fileNamesRD,
234 const std::vector<FileOpenResult> &openResults)234 const std::vector<FileOpenResult> &openResults)
235{235{
236 if (scenario_ != Scenario::RESTORE || !callbacksIncrementalRestore_.onFileReadyBatch) {236 if (scenario_ != Scenario::RESTORE || !callbacksIncrementalRestore_.onFileReadyBatch) {
237 HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_);237 HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_);
238 return BError(BError::Codes::OK);238 return BError(BError::Codes::OK);
239 }239 }
240+ std::string serializedData;
241+ fileNamesRD.Unmarshalling(serializedData);
242+ auto fileNames = StringUtils::StringVectorDeserialize(serializedData);
240 AddIncrementalFileToBatch(bundleName, fileNames, openResults);243 AddIncrementalFileToBatch(bundleName, fileNames, openResults);
241 return BError(BError::Codes::OK);244 return BError(BError::Codes::OK);
242}245}
@@ -218,7 +218,7 @@ ErrCode ServiceReverse::RestoreOnFileReadyWithoutFd(const std::string &bundleNam
218}218}
219 219 
220ErrCode ServiceReverse::BackupOnFileReadys(const std::string &bundleName,220ErrCode ServiceReverse::BackupOnFileReadys(const std::string &bundleName,
221- const std::vector<std::string> &fileNames,221+ const BStringRawData &fileNamesRD,
222 const std::vector<int> &fds,222 const std::vector<int> &fds,
223 const std::vector<int> &errCodes)223 const std::vector<int> &errCodes)
224{224{
@@ -226,19 +226,25 @@ ErrCode ServiceReverse::BackupOnFileReadys(const std::string &bundleName,
226 HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_);226 HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_);
227 return BError(BError::Codes::OK);227 return BError(BError::Codes::OK);
228 }228 }
229+ std::string serializedData;
230+ fileNamesRD.Unmarshalling(serializedData);
231+ auto fileNames = StringUtils::StringVectorDeserialize(serializedData);
229 std::vector<int> manifestFds(fileNames.size(), INVALID_FD);232 std::vector<int> manifestFds(fileNames.size(), INVALID_FD);
230 AddFileToBatch(bundleName, fileNames, fds, manifestFds, errCodes);233 AddFileToBatch(bundleName, fileNames, fds, manifestFds, errCodes);
231 return BError(BError::Codes::OK);234 return BError(BError::Codes::OK);
232}235}
233 236
234ErrCode ServiceReverse::BackupOnFileReadysWithoutFd(const std::string &bundleName,237ErrCode ServiceReverse::BackupOnFileReadysWithoutFd(const std::string &bundleName,
235- const std::vector<std::string> &fileNames,238+ const BStringRawData &fileNamesRD,
236 const std::vector<int> &errCodes)239 const std::vector<int> &errCodes)
237{240{
238 if (scenario_ != Scenario::BACKUP || !callbacksBackup_.onFileReadyBatch) {241 if (scenario_ != Scenario::BACKUP || !callbacksBackup_.onFileReadyBatch) {
239 HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_);242 HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_);
240 return BError(BError::Codes::OK);243 return BError(BError::Codes::OK);
241 }244 }
245+ std::string serializedData;
246+ fileNamesRD.Unmarshalling(serializedData);
247+ auto fileNames = StringUtils::StringVectorDeserialize(serializedData);
242 std::vector<int> fds(fileNames.size(), INVALID_FD);248 std::vector<int> fds(fileNames.size(), INVALID_FD);
243 std::vector<int> manifestFds(fileNames.size(), INVALID_FD);249 std::vector<int> manifestFds(fileNames.size(), INVALID_FD);
244 AddFileToBatch(bundleName, fileNames, fds, manifestFds, errCodes);250 AddFileToBatch(bundleName, fileNames, fds, manifestFds, errCodes);
@@ -0,0 +1,83 @@
1+/*
2+ * Copyright (c) 2026 Huawei Device Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+#ifndef OHOS_FILEMGMT_BACKUP_BSTRING_RAW_DATA_H
17+#define OHOS_FILEMGMT_BACKUP_BSTRING_RAW_DATA_H
18+ 
19+#include <errno.h>
20+#include <sstream>
21+ 
22+namespace OHOS::FileManagement::Backup {
23+ 
24+constexpr size_t MAX_IPC_STRING_SIZE = 16 * 1024 * 1024; // 16M
25+struct BStringRawData {
26+ uint32_t size = 0;
27+ const void *data = nullptr;
28+ std::string serializedData;
29+ 
30+ int32_t Marshalling(const std::string &in)
31+ {
32+ if (in.length() > MAX_IPC_STRING_SIZE) {
33+ return EINVAL;
34+ }
35+ std::stringstream ss;
36+ uint32_t length = in.length();
37+ if (!ss.write(reinterpret_cast<const char *>(&length), sizeof(length)).good()) {
38+ return EINVAL;
39+ }
40+ if (!ss.write(in.c_str(), length).good()) {
41+ return EINVAL;
42+ }
43+ serializedData = ss.str();
44+ data = reinterpret_cast<const void *>(serializedData.data());
45+ size = serializedData.length();
46+ return 0;
47+ }
48+ 
49+ int32_t Unmarshalling(std::string &out) const
50+ {
51+ std::stringstream ss;
52+ ss.write(reinterpret_cast<const char *>(data), size);
53+ uint32_t length = 0;
54+ ss.read(reinterpret_cast<char *>(&length), sizeof(length));
55+ if (ss.gcount() != sizeof(uint32_t)) {
56+ return EINVAL;
57+ }
58+ if (length <= 0 || length > size || length > MAX_IPC_STRING_SIZE) {
59+ return EINVAL;
60+ }
61+ out.resize(length);
62+ ss.read(&out[0], length);
63+ if (ss.gcount() != length) {
64+ return EINVAL;
65+ }
66+ return 0;
67+ }
68+ 
69+ int32_t RawDataCpy(const void *readdata)
70+ {
71+ if (readdata == nullptr || size == 0) {
72+ return EINVAL;
73+ }
74+ std::stringstream ss;
75+ ss.write(reinterpret_cast<const char *>(readdata), size);
76+ serializedData = ss.str();
77+ data = reinterpret_cast<const void *>(serializedData.data());
78+ return 0;
79+ }
80+};
81+} // namespace OHOS::FileManagement::Backup
82+ 
83+#endif
@@ -15,6 +15,7 @@
15 15 
16package OHOS.FileManagement.Backup;16package OHOS.FileManagement.Backup;
17sequenceable BackupFileInfo..OHOS.FileManagement.Backup.FileOpenResult;17sequenceable BackupFileInfo..OHOS.FileManagement.Backup.FileOpenResult;
18+rawdata OHOS.FileManagement.Backup.BStringRawData;
18interface OHOS.FileManagement.Backup.IExtension{19interface OHOS.FileManagement.Backup.IExtension{
19 [ipccode 1] void GetFileHandleWithUniqueFd([in] String fileName, [out] int getFileHandleErrCode, [out] FileDescriptor fd);20 [ipccode 1] void GetFileHandleWithUniqueFd([in] String fileName, [out] int getFileHandleErrCode, [out] FileDescriptor fd);
20 [ipccode 2] void HandleClear();21 [ipccode 2] void HandleClear();
@@ -36,5 +37,5 @@ interface OHOS.FileManagement.Backup.IExtension{
36 [ipccode 17] void HandleGetCompatibilityInfo([in] String extInfo, [in] int scenario, [in] boolean isExist,37 [ipccode 17] void HandleGetCompatibilityInfo([in] String extInfo, [in] int scenario, [in] boolean isExist,
37 [out] String compatibilityInfo);38 [out] String compatibilityInfo);
38 [ipccode 18] void GetIncrementalRpFileHandle([in] String fileName, [out] int fdErrCode);39 [ipccode 18] void GetIncrementalRpFileHandle([in] String fileName, [out] int fdErrCode);
39- [ipccode 19, ipcincapacity 131071] void GetIncrementalFileHandles([in] String[] fileNames, [out] FileOpenResult[] openResults);40+ [ipccode 19, ipcincapacity 131071] void GetIncrementalFileHandles([in] BStringRawData fileNames, [out] FileOpenResult[] openResults);
40}41}
@@ -24,6 +24,7 @@ sequenceable OHOS.FileManagement.Backup.StatInfo;
24sequenceable OHOS.FileManagement.Backup.AncoScanResult;24sequenceable OHOS.FileManagement.Backup.AncoScanResult;
25sequenceable OHOS.FileManagement.Backup.AncoRestoreResult;25sequenceable OHOS.FileManagement.Backup.AncoRestoreResult;
26sequenceable BackupPathInfo..OHOS.FileManagement.Backup.BPathInfo;26sequenceable BackupPathInfo..OHOS.FileManagement.Backup.BPathInfo;
27+rawdata OHOS.FileManagement.Backup.BStringRawData;
27interface OHOS.FileManagement.Backup.IService{28interface OHOS.FileManagement.Backup.IService{
28 [ipccode 39] void InitRestoreSession([in] IServiceReverse reverseIpcRemoteObject);29 [ipccode 39] void InitRestoreSession([in] IServiceReverse reverseIpcRemoteObject);
29 [ipccode 1] void InitRestoreSessionWithErrMsg([in] IServiceReverse reverseIpcRemoteObject,30 [ipccode 1] void InitRestoreSessionWithErrMsg([in] IServiceReverse reverseIpcRemoteObject,
@@ -102,7 +103,7 @@ interface OHOS.FileManagement.Backup.IService{
102 [in] String[] tarFileNames);103 [in] String[] tarFileNames);
103 [ipccode 59] void MigrateFile([in] BPathInfo path, [in] String bundleName, [in] String fileName);104 [ipccode 59] void MigrateFile([in] BPathInfo path, [in] String bundleName, [in] String fileName);
104 [ipccode 60] void GetApkFileHandle([in] String path, [in] String fileName, [out] FileDescriptor fd);105 [ipccode 60] void GetApkFileHandle([in] String path, [in] String fileName, [out] FileDescriptor fd);
105- [ipccode 61, ipcincapacity 131071] void GetIncrementalFileHandles([in] String bundleName, [in] String[] fileNames);106+ [ipccode 61, ipcincapacity 131071] void GetIncrementalFileHandles([in] String bundleName, [in] BStringRawData fileNames);
106- [ipccode 62, ipcincapacity 131071] void AppFileReadysWithoutFd([in] String[] fileNames, [in] int[] errCodes);107+ [ipccode 62, ipcincapacity 131071] void AppFileReadysWithoutFd([in] BStringRawData fileNames, [in] int[] errCodes);
107- [ipccode 63, ipcincapacity 131071] void AppFileReadys([in] String[] fileNames, [in] FileDescriptor[] fds, [in] int[] errCodes);108+ [ipccode 63, ipcincapacity 131071] void AppFileReadys([in] BStringRawData fileNames, [in] FileDescriptor[] fds, [in] int[] errCodes);
108 }109 }
@@ -16,6 +16,7 @@
16package OHOS.FileManagement.Backup;16package OHOS.FileManagement.Backup;
17import ServiceReverseType;17import ServiceReverseType;
18sequenceable BackupFileInfo..OHOS.FileManagement.Backup.FileOpenResult;18sequenceable BackupFileInfo..OHOS.FileManagement.Backup.FileOpenResult;
19+rawdata OHOS.FileManagement.Backup.BStringRawData;
19interface OHOS.FileManagement.Backup.IServiceReverse{20interface OHOS.FileManagement.Backup.IServiceReverse{
20 [ipccode 999] void BackupOnBundleStarted([in] int backupOnBundleStartedErrCode, [in] String bundleName);21 [ipccode 999] void BackupOnBundleStarted([in] int backupOnBundleStartedErrCode, [in] String bundleName);
21 [ipccode 1] void BackupOnFileReady([in] String bundleName, [in] String fileName, [in] FileDescriptor fd,22 [ipccode 1] void BackupOnFileReady([in] String bundleName, [in] String fileName, [in] FileDescriptor fd,
@@ -74,9 +75,9 @@ interface OHOS.FileManagement.Backup.IServiceReverse{
74 [in] int incrementalRestoreOnFileReadyErrCode);75 [in] int incrementalRestoreOnFileReadyErrCode);
75 [ipccode 31] void IncrementalRestoreOnMigrateResult([in] int incrementalRestoreOnMigrateResultErrCode, [in] String bundleName);76 [ipccode 31] void IncrementalRestoreOnMigrateResult([in] int incrementalRestoreOnMigrateResultErrCode, [in] String bundleName);
76 [ipccode 32, ipcincapacity 131071] void IncrementalRestoreOnFileReadys([in] String bundleName,77 [ipccode 32, ipcincapacity 131071] void IncrementalRestoreOnFileReadys([in] String bundleName,
77- [in] String[] fileNames,78+ [in] BStringRawData fileNames,
78 [in] FileOpenResult[] openResults);79 [in] FileOpenResult[] openResults);
79 [ipccode 33] void SetBatchSize([in] unsigned int batchSize);80 [ipccode 33] void SetBatchSize([in] unsigned int batchSize);
80- [ipccode 34, ipcincapacity 131071] void BackupOnFileReadys([in] String bundleName, [in] String[] fileNames, [in] FileDescriptor[] fds, [in] int[] errCodes);81+ [ipccode 34, ipcincapacity 131071] void BackupOnFileReadys([in] String bundleName, [in] BStringRawData fileNames, [in] FileDescriptor[] fds, [in] int[] errCodes);
81- [ipccode 35, ipcincapacity 131071] void BackupOnFileReadysWithoutFd([in] String bundleName, [in] String[] fileNames, [in] int[] errCodes);82+ [ipccode 35, ipcincapacity 131071] void BackupOnFileReadysWithoutFd([in] String bundleName, [in] BStringRawData fileNames, [in] int[] errCodes);
82}83}
@@ -71,7 +71,7 @@ public:
71 const std::string &filePath, UniqueFd fd, int32_t errCode);71 const std::string &filePath, UniqueFd fd, int32_t errCode);
72 ErrCode AppFileReadyWithoutFd(const std::string &fileName, int32_t errCode) override;72 ErrCode AppFileReadyWithoutFd(const std::string &fileName, int32_t errCode) override;
73 ErrCode DefaultAppFileReadyWithoutFd(const std::string &fileName, const std::string &filePath, int32_t errCode);73 ErrCode DefaultAppFileReadyWithoutFd(const std::string &fileName, const std::string &filePath, int32_t errCode);
74- ErrCode AppFileReadys(const std::vector<std::string> &fileNames,74+ ErrCode AppFileReadys(const BStringRawData &fileNamesRD,
75 const std::vector<int> &fds, const std::vector<int> &errCodes) override;75 const std::vector<int> &fds, const std::vector<int> &errCodes) override;
76 ErrCode AppFileReadyWithoutFd(const std::string &fileName, const std::string &filePath,76 ErrCode AppFileReadyWithoutFd(const std::string &fileName, const std::string &filePath,
77 UniqueFd fd, int32_t errCode);77 UniqueFd fd, int32_t errCode);
@@ -87,7 +87,7 @@ public:
87 BizScene &scene);87 BizScene &scene);
88 88
89 ErrCode AppAncoFileReady(const std::string &fileName, const std::string &filePath, bool needDelete) override;89 ErrCode AppAncoFileReady(const std::string &fileName, const std::string &filePath, bool needDelete) override;
90- ErrCode AppFileReadysWithoutFd(const std::vector<std::string> &abnormalfileNames,90+ ErrCode AppFileReadysWithoutFd(const BStringRawData &abnormalfileNamesRD,
91 const std::vector<int> &errCodes) override;91 const std::vector<int> &errCodes) override;
92 ErrCode AppDone(ErrCode errCode) override;92 ErrCode AppDone(ErrCode errCode) override;
93 ErrCode AppDone(ErrCode errCode, const std::string &bundleName);93 ErrCode AppDone(ErrCode errCode, const std::string &bundleName);
@@ -129,7 +129,7 @@ public:
129 ErrCode AppIncrementalDone(ErrCode errCode) override;129 ErrCode AppIncrementalDone(ErrCode errCode) override;
130 ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) override;130 ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) override;
131 ErrCode GetIncrementalFileHandles(const std::string &bundleName,131 ErrCode GetIncrementalFileHandles(const std::string &bundleName,
132- const std::vector<std::string> &fileNames) override;132+ const BStringRawData &fileNamesRD) override;
133 ErrCode GetBackupInfo(const BundleName &bundleName, std::string &result) override;133 ErrCode GetBackupInfo(const BundleName &bundleName, std::string &result) override;
134 ErrCode UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result) override;134 ErrCode UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result) override;
135 ErrCode UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) override;135 ErrCode UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) override;
@@ -640,7 +640,9 @@ ErrCode Service::AppIncrementalFileReadys(const std::string &bundleName,
640 "File names and open results size mismatch");640 "File names and open results size mismatch");
641 if (session_->GetScenario() == IServiceReverseType::Scenario::RESTORE) {641 if (session_->GetScenario() == IServiceReverseType::Scenario::RESTORE) {
642 session_->GetServiceReverseProxy()->SetBatchSize(static_cast<unsigned int>(fileNames.size()));642 session_->GetServiceReverseProxy()->SetBatchSize(static_cast<unsigned int>(fileNames.size()));
643- session_->GetServiceReverseProxy()->IncrementalRestoreOnFileReadys(bundleName, fileNames, openResults);643+ BStringRawData fileNamesRD;
644+ fileNamesRD.Marshalling(StringUtils::StringVectorSerialize(fileNames));
645+ session_->GetServiceReverseProxy()->IncrementalRestoreOnFileReadys(bundleName, fileNamesRD, openResults);
644 OnAllBundlesFinished(BError(BError::Codes::OK));646 OnAllBundlesFinished(BError(BError::Codes::OK));
645 return BError(BError::Codes::OK);647 return BError(BError::Codes::OK);
646 }648 }
@@ -877,7 +879,7 @@ ErrCode Service::ProcessFileHandlesByAction(const std::string &bundleName,
877 return BError(BError::Codes::OK);879 return BError(BError::Codes::OK);
878}880}
879 881
880-ErrCode Service::GetIncrementalFileHandles(const std::string &bundleName, const std::vector<std::string> &fileNames)882+ErrCode Service::GetIncrementalFileHandles(const std::string &bundleName, const BStringRawData &fileNamesRD)
881{883{
882 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);884 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
883 try {885 try {
@@ -896,6 +898,9 @@ ErrCode Service::GetIncrementalFileHandles(const std::string &bundleName, const
896 HILOGE("action is unknown, bundleName:%{public}s", bundleName.c_str());898 HILOGE("action is unknown, bundleName:%{public}s", bundleName.c_str());
897 return BError(BError::Codes::SA_INVAL_ARG);899 return BError(BError::Codes::SA_INVAL_ARG);
898 }900 }
901+ std::string serializedData;
902+ fileNamesRD.Unmarshalling(serializedData);
903+ auto fileNames = StringUtils::StringVectorDeserialize(serializedData);
899 return ProcessFileHandlesByAction(bundleName, fileNames, action);904 return ProcessFileHandlesByAction(bundleName, fileNames, action);
900 } catch (const BError &e) {905 } catch (const BError &e) {
901 HILOGE("GetIncrementalFileHandles exception, bundleName:%{public}s", bundleName.c_str());906 HILOGE("GetIncrementalFileHandles exception, bundleName:%{public}s", bundleName.c_str());
@@ -997,13 +1002,19 @@ std::function<void()> Service::CreateIncrementalFileHandlesTask(const std::strin
997 }1002 }
998 if (!extFileNames.empty()) {1003 if (!extFileNames.empty()) {
999 std::vector<FileOpenResult> extOpenResults;1004 std::vector<FileOpenResult> extOpenResults;
1000- proxyPtr->GetIncrementalFileHandles(extFileNames, extOpenResults);1005+ BStringRawData extFileNamesRD;
1006+ extFileNamesRD.Marshalling(StringUtils::StringVectorSerialize(extFileNames));
1007+ auto err = proxyPtr->GetIncrementalFileHandles(extFileNamesRD, extOpenResults);
1008+ finalErr = err == ERR_OK ? finalErr : err;
1001 finalFileNames.insert(finalFileNames.end(), extFileNames.begin(), extFileNames.end());1009 finalFileNames.insert(finalFileNames.end(), extFileNames.begin(), extFileNames.end());
1002 openResults.insert(openResults.end(), extOpenResults.begin(), extOpenResults.end());1010 openResults.insert(openResults.end(), extOpenResults.begin(), extOpenResults.end());
1003 }1011 }
1004 auto err = ptr->AppIncrementalFileReadys(bundleName, finalFileNames, openResults);1012 auto err = ptr->AppIncrementalFileReadys(bundleName, finalFileNames, openResults);
1005 finalErr = err == ERR_OK ? finalErr : err;1013 finalErr = err == ERR_OK ? finalErr : err;
1006 if (finalErr != ERR_OK) {1014 if (finalErr != ERR_OK) {
1015+ HILOGE(
1016+ "GetIncrementalFileHandles failed, bundleName:%{public}s, errCode:%{public}d, totalFiles:%{public}zu",
1017+ bundleName.c_str(), static_cast<int>(finalErr), fileNames.size());
1007 AppRadar::Info info(bundleName, "", "");1018 AppRadar::Info info(bundleName, "", "");
1008 AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::GetIncrementalFileHandles",1019 AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::GetIncrementalFileHandles",
1009 ptr->GetUserIdDefault(),1020 ptr->GetUserIdDefault(),
@@ -423,19 +423,37 @@ ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCo
423 }423 }
424}424}
425 425 
426-ErrCode Service::AppFileReadysWithoutFd(const std::vector<std::string> &abnormalfileNames, const vector<int> &errCodes)426+ErrCode Service::AppFileReadysWithoutFd(const BStringRawData &abnormalfileNamesRD, const vector<int> &errCodes)
427{427{
428- if (session_ == nullptr) {428+ HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
429- HILOGE("AppFileReady error, session is empty");429+ try {
430- return BError(BError::Codes::SA_INVAL_ARG);430+ if (session_ == nullptr) {
431+ HILOGE("AppFileReadysWithoutFd error, session is empty");
432+ return BError(BError::Codes::SA_INVAL_ARG);
433+ }
434+ string callerName;
435+ ErrCode ret = VerifyCallerAndGetCallerName(callerName);
436+ if (ret != ERR_OK) {
437+ HILOGE("AppFileReadysWithoutFd error, Get bundle name failed, ret:%{public}d", ret);
438+ return ret;
439+ }
440+ std::string serializedData;
441+ abnormalfileNamesRD.Unmarshalling(serializedData);
442+ auto abnormalfileNames = StringUtils::StringVectorDeserialize(serializedData);
443+ HILOGI("AppFileReadysWithoutFd filenames size is, %{public}zu", abnormalfileNames.size());
444+ session_->GetServiceReverseProxy()->BackupOnFileReadysWithoutFd(callerName, abnormalfileNamesRD, errCodes);
445+ ret = ProcessReadyFiles(abnormalfileNames, errCodes, callerName);
446+ if (ret != ERR_OK) {
447+ return ret;
448+ }
449+ OnAllBundlesFinished(BError(BError::Codes::OK));
450+ return BError(BError::Codes::OK);
451+ } catch (const BError &e) {
452+ return e.GetCode(); // 任意异常产生,终止监听该任务
453+ } catch (...) {
454+ HILOGE("Unexpected exception");
455+ return EPERM;
431 }456 }
432- string callerName;
433- ErrCode ret = VerifyCallerAndGetCallerName(callerName);
434- if (ret != ERR_OK) {
435- HILOGE("AppFileReady error, Get bundle name failed, ret:%{public}d", ret);
436- return ret;
437- }
438- return session_->GetServiceReverseProxy()->BackupOnFileReadysWithoutFd(callerName, abnormalfileNames, errCodes);
439}457}
440 458 
441ErrCode Service::ProcessReadyFiles(459ErrCode Service::ProcessReadyFiles(
@@ -462,7 +480,7 @@ ErrCode Service::ProcessReadyFiles(
462 return ERR_OK;480 return ERR_OK;
463}481}
464 482 
465-ErrCode Service::AppFileReadys(const std::vector<std::string> &fileNames,483+ErrCode Service::AppFileReadys(const BStringRawData &fileNamesRD,
466 const vector<int> &fds,484 const vector<int> &fds,
467 const vector<int> &errCodes)485 const vector<int> &errCodes)
468{486{
@@ -479,8 +497,11 @@ ErrCode Service::AppFileReadys(const std::vector<std::string> &fileNames,
479 HILOGE("AppFileReady error, Get bundle name failed, ret:%{public}d", ret);497 HILOGE("AppFileReady error, Get bundle name failed, ret:%{public}d", ret);
480 return ret;498 return ret;
481 }499 }
500+ std::string serializedData;
501+ fileNamesRD.Unmarshalling(serializedData);
502+ auto fileNames = StringUtils::StringVectorDeserialize(serializedData);
482 HILOGI("AppfileReadys filenames size is, %{public}zu", fileNames.size());503 HILOGI("AppfileReadys filenames size is, %{public}zu", fileNames.size());
483- session_->GetServiceReverseProxy()->BackupOnFileReadys(callerName, fileNames, fds, errCodes);504+ session_->GetServiceReverseProxy()->BackupOnFileReadys(callerName, fileNamesRD, fds, errCodes);
484 ret = ProcessReadyFiles(fileNames, errCodes, callerName);505 ret = ProcessReadyFiles(fileNames, errCodes, callerName);
485 if (ret != ERR_OK) {506 if (ret != ERR_OK) {
486 return ret;507 return ret;
@@ -69,7 +69,7 @@ public:
69 virtual ErrCode HandleOnRelease(int32_t scenario) = 0;69 virtual ErrCode HandleOnRelease(int32_t scenario) = 0;
70 virtual ErrCode HandleGetCompatibilityInfo(const std::string &extInfo, int32_t scenario, bool isExist,70 virtual ErrCode HandleGetCompatibilityInfo(const std::string &extInfo, int32_t scenario, bool isExist,
71 std::string &compatibilityInfo) = 0;71 std::string &compatibilityInfo) = 0;
72- virtual ErrCode GetIncrementalFileHandles(const std::vector<std::string> &fileNames,72+ virtual ErrCode GetIncrementalFileHandles(const BStringRawData &fileNames,
73 std::vector<FileOpenResult> &openResults) = 0;73 std::vector<FileOpenResult> &openResults) = 0;
74public:74public:
75 BExtExtension() = default;75 BExtExtension() = default;
@@ -115,7 +115,7 @@ public:
115 MOCK_METHOD((std::tuple<ErrCode, UniqueFd, UniqueFd>), GetIncrementalFileHandle,115 MOCK_METHOD((std::tuple<ErrCode, UniqueFd, UniqueFd>), GetIncrementalFileHandle,
116 (const string &));116 (const string &));
117 MOCK_METHOD(ErrCode, GetFileHandleWithUniqueFd, (const std::string &, int32_t &, int&));117 MOCK_METHOD(ErrCode, GetFileHandleWithUniqueFd, (const std::string &, int32_t &, int&));
118- MOCK_METHOD(ErrCode, GetIncrementalFileHandles, (const std::vector<std::string> &, std::vector<FileOpenResult> &));118+ MOCK_METHOD(ErrCode, GetIncrementalFileHandles, (const BStringRawData &, std::vector<FileOpenResult> &));
119 MOCK_METHOD(std::string, GetBackupInfo, ());119 MOCK_METHOD(std::string, GetBackupInfo, ());
120 MOCK_METHOD(void, UpdateOnStartTime, ());120 MOCK_METHOD(void, UpdateOnStartTime, ());
121 MOCK_METHOD(ErrCode, IncrementalTarFileReady, (const TarMap &, const vector<struct ReportFileInfo> &,121 MOCK_METHOD(ErrCode, IncrementalTarFileReady, (const TarMap &, const vector<struct ReportFileInfo> &,
@@ -159,7 +159,7 @@ void BackupExtExtension::ReportAppStatistic(const std::string &func, ErrCode err
159 BExtExtension::extExtension->ReportAppStatistic(func, errCode);159 BExtExtension::extExtension->ReportAppStatistic(func, errCode);
160}160}
161 161
162-ErrCode BackupExtExtension::GetIncrementalFileHandles(const std::vector<std::string> &fileNames,162+ErrCode BackupExtExtension::GetIncrementalFileHandles(const BStringRawData &fileNames,
163 std::vector<FileOpenResult> &openResults)163 std::vector<FileOpenResult> &openResults)
164{164{
165 return BExtExtension::extExtension->GetIncrementalFileHandles(fileNames, openResults);165 return BExtExtension::extExtension->GetIncrementalFileHandles(fileNames, openResults);
@@ -313,20 +313,20 @@ ErrCode ServiceProxy::GetApkFileHandle(const std::string &path, const std::strin
313 return BError(BError::Codes::OK);313 return BError(BError::Codes::OK);
314}314}
315 315 
316-ErrCode ServiceProxy::AppFileReadys(const std::vector<std::string> &fileNames, const std::vector<int> &fds,316+ErrCode ServiceProxy::AppFileReadys(const BStringRawData &fileNames, const std::vector<int> &fds,
317 const std::vector<int> &errCodes)317 const std::vector<int> &errCodes)
318{318{
319 return BError(BError::Codes::OK);319 return BError(BError::Codes::OK);
320}320}
321 321
322-ErrCode ServiceProxy::AppFileReadysWithoutFd(const std::vector<std::string> &abnormalfileNames,322+ErrCode ServiceProxy::AppFileReadysWithoutFd(const BStringRawData &abnormalfileNames,
323 const std::vector<int> &errCodes)323 const std::vector<int> &errCodes)
324{324{
325 return BError(BError::Codes::OK);325 return BError(BError::Codes::OK);
326}326}
327 327
328ErrCode ServiceProxy::GetIncrementalFileHandles(const std::string &bundleName,328ErrCode ServiceProxy::GetIncrementalFileHandles(const std::string &bundleName,
329- const std::vector<std::string> &fileNames)329+ const BStringRawData &fileNames)
330{330{
331 return BError(BError::Codes::OK);331 return BError(BError::Codes::OK);
332}332}
@@ -63,11 +63,11 @@ public:
63 MOCK_METHOD(ErrCode, IncrementalRestoreOnProcessInfo, (const std::string &, const std::string &));63 MOCK_METHOD(ErrCode, IncrementalRestoreOnProcessInfo, (const std::string &, const std::string &));
64 MOCK_METHOD(ErrCode, IncrementalRestoreOnMigrateResult, (int32_t, const std::string &));64 MOCK_METHOD(ErrCode, IncrementalRestoreOnMigrateResult, (int32_t, const std::string &));
65 MOCK_METHOD(ErrCode, IncrementalRestoreOnFileReadys,65 MOCK_METHOD(ErrCode, IncrementalRestoreOnFileReadys,
66- (const std::string &, const std::vector<std::string> &, const std::vector<FileOpenResult> &));66+ (const std::string &, const BStringRawData &, const std::vector<FileOpenResult> &));
67 MOCK_METHOD(ErrCode, SetBatchSize, (uint32_t));67 MOCK_METHOD(ErrCode, SetBatchSize, (uint32_t));
68- MOCK_METHOD(ErrCode, BackupOnFileReadysWithoutFd, (const std::string &, const std::vector<std::string> &,68+ MOCK_METHOD(ErrCode, BackupOnFileReadysWithoutFd, (const std::string &, const BStringRawData &,
69 const std::vector<int> &));69 const std::vector<int> &));
70- MOCK_METHOD(ErrCode, BackupOnFileReadys, (const std::string &, const std::vector<std::string> &,70+ MOCK_METHOD(ErrCode, BackupOnFileReadys, (const std::string &, const BStringRawData &,
71 const std::vector<int> &, const std::vector<int> &));71 const std::vector<int> &, const std::vector<int> &));
72 72 
73public:73public:
@@ -45,7 +45,7 @@ MOCK_METHOD(ErrCode, UpdateDfxInfo, (int64_t, uint32_t, const std::string &));
45MOCK_METHOD(ErrCode, CleanBundleTempDir, ());45MOCK_METHOD(ErrCode, CleanBundleTempDir, ());
46MOCK_METHOD(ErrCode, HandleOnRelease, (int32_t));46MOCK_METHOD(ErrCode, HandleOnRelease, (int32_t));
47MOCK_METHOD(ErrCode, HandleGetCompatibilityInfo, (const std::string &, int32_t, bool, std::string &));47MOCK_METHOD(ErrCode, HandleGetCompatibilityInfo, (const std::string &, int32_t, bool, std::string &));
48-MOCK_METHOD(ErrCode, GetIncrementalFileHandles, (const std::vector<std::string> &, std::vector<FileOpenResult> &));48+MOCK_METHOD(ErrCode, GetIncrementalFileHandles, (const BStringRawData &, std::vector<FileOpenResult> &));
49};49};
50} // namespace OHOS::FileManagement::Backup50} // namespace OHOS::FileManagement::Backup
51#endif // OHOS_FILEMGMT_BACKUP_SVC_BACKUP_CONNECTION_MOCK_H51#endif // OHOS_FILEMGMT_BACKUP_SVC_BACKUP_CONNECTION_MOCK_H
@@ -555,19 +555,19 @@ ErrCode Service::GetApkFileHandle(const std::string &path, const std::string &fi
555 return BError(BError::Codes::OK);555 return BError(BError::Codes::OK);
556}556}
557 557 
558-ErrCode Service::AppFileReadys(const std::vector<std::string> &fileNames, const std::vector<int> &fds,558+ErrCode Service::AppFileReadys(const BStringRawData &fileNames, const std::vector<int> &fds,
559 const std::vector<int> &errCodes)559 const std::vector<int> &errCodes)
560{560{
561 return BError(BError::Codes::OK);561 return BError(BError::Codes::OK);
562}562}
563 563
564-ErrCode Service::AppFileReadysWithoutFd(const std::vector<std::string> &abnormalfileNames,564+ErrCode Service::AppFileReadysWithoutFd(const BStringRawData &abnormalfileNames,
565 const std::vector<int> &errCodes)565 const std::vector<int> &errCodes)
566{566{
567 return BError(BError::Codes::OK);567 return BError(BError::Codes::OK);
568}568}
569 569
570-ErrCode Service::GetIncrementalFileHandles(const std::string &bundleName, const std::vector<std::string> &fileNames)570+ErrCode Service::GetIncrementalFileHandles(const std::string &bundleName, const BStringRawData &fileNames)
571{571{
572 return BError(BError::Codes::OK);572 return BError(BError::Codes::OK);
573}573}
@@ -206,7 +206,7 @@ ErrCode ServiceReverseProxy::IncrementalRestoreOnMigrateResult(int32_t errCode,
206}206}
207 207 
208ErrCode ServiceReverseProxy::IncrementalRestoreOnFileReadys(const std::string &bundleName,208ErrCode ServiceReverseProxy::IncrementalRestoreOnFileReadys(const std::string &bundleName,
209- const std::vector<std::string> &fileNames, const std::vector<FileOpenResult> &openResults)209+ const BStringRawData &fileNames, const std::vector<FileOpenResult> &openResults)
210{210{
211 return BError(BError::Codes::OK);211 return BError(BError::Codes::OK);
212}212}
@@ -217,13 +217,13 @@ ErrCode ServiceReverseProxy::SetBatchSize(uint32_t size)
217}217}
218 218
219ErrCode ServiceReverseProxy::BackupOnFileReadysWithoutFd(219ErrCode ServiceReverseProxy::BackupOnFileReadysWithoutFd(
220- const std::string &bundleName, const std::vector<std::string> &fileNames, const std::vector<int> &errCodes)220+ const std::string &bundleName, const BStringRawData &fileNames, const std::vector<int> &errCodes)
221{221{
222 return BError(BError::Codes::OK);222 return BError(BError::Codes::OK);
223}223}
224 224
225ErrCode ServiceReverseProxy::BackupOnFileReadys(const std::string &bundleName,225ErrCode ServiceReverseProxy::BackupOnFileReadys(const std::string &bundleName,
226- const std::vector<std::string> &fileNames, const std::vector<int> &fds, const std::vector<int> &errCodes)226+ const BStringRawData &fileNames, const std::vector<int> &fds, const std::vector<int> &errCodes)
227{227{
228 return BError(BError::Codes::OK);228 return BError(BError::Codes::OK);
229}229}
@@ -110,7 +110,7 @@ ErrCode ExtensionProxy::GetIncrementalRpFileHandle(const std::string &fileName,
110 return 0;110 return 0;
111}111}
112 112 
113-ErrCode ExtensionProxy::GetIncrementalFileHandles(const std::vector<std::string> &fileNames,113+ErrCode ExtensionProxy::GetIncrementalFileHandles(const BStringRawData &fileNames,
114 std::vector<FileOpenResult> &openResults)114 std::vector<FileOpenResult> &openResults)
115{115{
116 return 0;116 return 0;
@@ -190,7 +190,7 @@ public:
190 return BError(BError::Codes::OK);190 return BError(BError::Codes::OK);
191 }191 }
192 192 
193- ErrCode GetIncrementalFileHandles(const std::vector<std::string> &fileNames,193+ ErrCode GetIncrementalFileHandles(const BStringRawData &fileNames,
194 std::vector<FileOpenResult> &openResults) override194 std::vector<FileOpenResult> &openResults) override
195 {195 {
196 return BError(BError::Codes::OK);196 return BError(BError::Codes::OK);
@@ -290,18 +290,18 @@ public:
290 return BError(BError::Codes::OK);290 return BError(BError::Codes::OK);
291 }291 }
292 292 
293- ErrCode AppFileReadys(const std::vector<std::string> &fileNames, const std::vector<int> &fds,293+ ErrCode AppFileReadys(const BStringRawData &fileNames, const std::vector<int> &fds,
294 const std::vector<int> &errCodes)294 const std::vector<int> &errCodes)
295 {295 {
296 return BError(BError::Codes::OK);296 return BError(BError::Codes::OK);
297 }297 }
298 298
299- ErrCode AppFileReadysWithoutFd(const std::vector<std::string> &abnormalfileNames, const std::vector<int> &errCodes)299+ ErrCode AppFileReadysWithoutFd(const BStringRawData &abnormalfileNames, const std::vector<int> &errCodes)
300 {300 {
301 return BError(BError::Codes::OK);301 return BError(BError::Codes::OK);
302 }302 }
303 303
304- ErrCode GetIncrementalFileHandles(const std::string &bundleName, const std::vector<std::string> &fileNames)304+ ErrCode GetIncrementalFileHandles(const std::string &bundleName, const BStringRawData &fileNames)
305 {305 {
306 return BError(BError::Codes::OK);306 return BError(BError::Codes::OK);
307 }307 }
@@ -230,7 +230,7 @@ public:
230 return BError(BError::Codes::OK);230 return BError(BError::Codes::OK);
231 }231 }
232 232 
233- ErrCode IncrementalRestoreOnFileReadys(const std::string &bundleName, const std::vector<std::string> &fileNames,233+ ErrCode IncrementalRestoreOnFileReadys(const std::string &bundleName, const BStringRawData &fileNames,
234 const std::vector<FileOpenResult> &openResults) override234 const std::vector<FileOpenResult> &openResults) override
235 {235 {
236 return BError(BError::Codes::OK);236 return BError(BError::Codes::OK);
@@ -241,13 +241,13 @@ public:
241 return BError(BError::Codes::OK);241 return BError(BError::Codes::OK);
242 }242 }
243 243 
244- ErrCode BackupOnFileReadysWithoutFd(const std::string &bundleName, const std::vector<std::string> &fileNames,244+ ErrCode BackupOnFileReadysWithoutFd(const std::string &bundleName, const BStringRawData &fileNames,
245 const std::vector<int> &errCodes) override245 const std::vector<int> &errCodes) override
246 {246 {
247 return BError(BError::Codes::OK);247 return BError(BError::Codes::OK);
248 }248 }
249 249 
250- ErrCode BackupOnFileReadys(const std::string &bundleName, const std::vector<std::string> &fileNames,250+ ErrCode BackupOnFileReadys(const std::string &bundleName, const BStringRawData &fileNames,
251 const std::vector<int> &fds, const std::vector<int> &errCodes) override251 const std::vector<int> &fds, const std::vector<int> &errCodes) override
252 {252 {
253 return BError(BError::Codes::OK);253 return BError(BError::Codes::OK);
@@ -686,13 +686,13 @@ ErrCode Service::GetApkFileHandle(const std::string &path, const std::string &fi
686 return BService::serviceMock->GetApkFileHandle(path, fileName, fd);686 return BService::serviceMock->GetApkFileHandle(path, fileName, fd);
687}687}
688 688 
689-ErrCode Service::AppFileReadys(const std::vector<std::string> &fileNames, const std::vector<int> &fds,689+ErrCode Service::AppFileReadys(const BStringRawData &fileNames, const std::vector<int> &fds,
690 const std::vector<int> &errCodes)690 const std::vector<int> &errCodes)
691{691{
692 return BError(BError::Codes::OK);692 return BError(BError::Codes::OK);
693}693}
694 694
695-ErrCode Service::AppFileReadysWithoutFd(const std::vector<std::string> &abnormalfileNames,695+ErrCode Service::AppFileReadysWithoutFd(const BStringRawData &abnormalfileNames,
696 const std::vector<int> &errCodes)696 const std::vector<int> &errCodes)
697{697{
698 return BError(BError::Codes::OK);698 return BError(BError::Codes::OK);
@@ -159,7 +159,7 @@ ErrCode Service::IncrementalBackupSA(std::string bundleName)
159 return BError(BError::Codes::OK);159 return BError(BError::Codes::OK);
160}160}
161 161 
162-ErrCode Service::GetIncrementalFileHandles(const std::string &bundleName, const std::vector<std::string> &fileNames)162+ErrCode Service::GetIncrementalFileHandles(const std::string &bundleName, const BStringRawData &fileNames)
163{163{
164 return BError(BError::Codes::OK);164 return BError(BError::Codes::OK);
165}165}
@@ -144,7 +144,7 @@ ErrCode Service::IncrementalBackupSA(std::string bundleName)
144 return BError(BError::Codes::OK);144 return BError(BError::Codes::OK);
145}145}
146 146 
147-ErrCode Service::GetIncrementalFileHandles(const std::string &bundleName, const std::vector<std::string> &fileNames)147+ErrCode Service::GetIncrementalFileHandles(const std::string &bundleName, const BStringRawData &fileNames)
148{148{
149 return BError(BError::Codes::OK);149 return BError(BError::Codes::OK);
150}150}
@@ -348,20 +348,20 @@ ErrCode ServiceProxy::GetApkFileHandle(const std::string &path, const std::strin
348 return BError(BError::Codes::OK);348 return BError(BError::Codes::OK);
349}349}
350 350 
351-ErrCode ServiceProxy::AppFileReadys(const std::vector<std::string> &fileNames, const std::vector<int> &fds,351+ErrCode ServiceProxy::AppFileReadys(const BStringRawData &fileNames, const std::vector<int> &fds,
352 const std::vector<int> &errCodes)352 const std::vector<int> &errCodes)
353{353{
354 return BError(BError::Codes::OK);354 return BError(BError::Codes::OK);
355}355}
356 356
357-ErrCode ServiceProxy::AppFileReadysWithoutFd(const std::vector<std::string> &abnormalfileNames,357+ErrCode ServiceProxy::AppFileReadysWithoutFd(const BStringRawData &abnormalfileNames,
358 const std::vector<int> &errCodes)358 const std::vector<int> &errCodes)
359{359{
360 return BError(BError::Codes::OK);360 return BError(BError::Codes::OK);
361}361}
362 362
363ErrCode ServiceProxy::GetIncrementalFileHandles(363ErrCode ServiceProxy::GetIncrementalFileHandles(
364- const std::string &bundleName, const std::vector<std::string> &fileNames)364+ const std::string &bundleName, const BStringRawData &fileNames)
365{365{
366 return BError(BError::Codes::OK);366 return BError(BError::Codes::OK);
367}367}
@@ -183,7 +183,7 @@ HWTEST_F(ScanResultManagerTest, ADD_BIG_FILE_TEST_001, testing::ext::TestSize.Le
183 std::string filePath = "abc/aaa/test1";183 std::string filePath = "abc/aaa/test1";
184 std::string restorePath = "";184 std::string restorePath = "";
185 struct stat sta = {};185 struct stat sta = {};
186- manager_.AddBigFile(filePath, sta, restorePath);186+ manager_.AddBigFile(filePath, sta, false, restorePath);
187 auto fileInfo = manager_.GetFileInfo();187 auto fileInfo = manager_.GetFileInfo();
188 ASSERT_NE(fileInfo, nullptr);188 ASSERT_NE(fileInfo, nullptr);
189 EXPECT_EQ(fileInfo->GetRestorePath(), "");189 EXPECT_EQ(fileInfo->GetRestorePath(), "");
@@ -205,7 +205,7 @@ HWTEST_F(ScanResultManagerTest, ADD_BIG_FILE_TEST_002, testing::ext::TestSize.Le
205 std::string filePath = "abc/aaa/test2";205 std::string filePath = "abc/aaa/test2";
206 std::string restorePath = "restore2";206 std::string restorePath = "restore2";
207 struct stat sta = {};207 struct stat sta = {};
208- manager_.AddBigFile(filePath, sta, restorePath);208+ manager_.AddBigFile(filePath, sta, false, restorePath);
209 auto fileInfo = manager_.GetFileInfo();209 auto fileInfo = manager_.GetFileInfo();
210 ASSERT_NE(fileInfo, nullptr);210 ASSERT_NE(fileInfo, nullptr);
211 EXPECT_EQ(fileInfo->GetRestorePath(), restorePath);211 EXPECT_EQ(fileInfo->GetRestorePath(), restorePath);
@@ -226,7 +226,7 @@ HWTEST_F(ScanResultManagerTest, ADD_BIG_FILE_TEST_003, testing::ext::TestSize.Le
226 std::string filePath = "abc/aaa/test3.txt";226 std::string filePath = "abc/aaa/test3.txt";
227 std::string restorePath = "";227 std::string restorePath = "";
228 struct stat sta = {};228 struct stat sta = {};
229- manager_.AddBigFile(filePath, sta, restorePath);229+ manager_.AddBigFile(filePath, sta, false, restorePath);
230 auto fileInfo = manager_.GetFileInfo();230 auto fileInfo = manager_.GetFileInfo();
231 ASSERT_NE(fileInfo, nullptr);231 ASSERT_NE(fileInfo, nullptr);
232 EXPECT_EQ(fileInfo->GetRestorePath(), restorePath);232 EXPECT_EQ(fileInfo->GetRestorePath(), restorePath);
@@ -247,7 +247,7 @@ HWTEST_F(ScanResultManagerTest, ADD_BIG_FILE_TEST_004, testing::ext::TestSize.Le
247 std::string filePath = "abc/aaa/test4.txt";247 std::string filePath = "abc/aaa/test4.txt";
248 std::string restorePath = "restore4";248 std::string restorePath = "restore4";
249 struct stat sta = {};249 struct stat sta = {};
250- manager_.AddBigFile(filePath, sta, restorePath);250+ manager_.AddBigFile(filePath, sta, false, restorePath);
251 auto fileInfo = manager_.GetFileInfo();251 auto fileInfo = manager_.GetFileInfo();
252 ASSERT_NE(fileInfo, nullptr);252 ASSERT_NE(fileInfo, nullptr);
253 EXPECT_EQ(fileInfo->GetRestorePath(), restorePath);253 EXPECT_EQ(fileInfo->GetRestorePath(), restorePath);
@@ -268,7 +268,7 @@ HWTEST_F(ScanResultManagerTest, ADD_BIG_FILE_TEST_005, testing::ext::TestSize.Le
268 std::string filePath = "abc/aaa/test5.txt_anco_aaa";268 std::string filePath = "abc/aaa/test5.txt_anco_aaa";
269 std::string restorePath = "";269 std::string restorePath = "";
270 struct stat sta = {};270 struct stat sta = {};
271- manager_.AddBigFile(filePath, sta, restorePath);271+ manager_.AddBigFile(filePath, sta, false, restorePath);
272 auto fileInfo = manager_.GetFileInfo();272 auto fileInfo = manager_.GetFileInfo();
273 ASSERT_NE(fileInfo, nullptr);273 ASSERT_NE(fileInfo, nullptr);
274 EXPECT_EQ(fileInfo->GetRestorePath(), restorePath);274 EXPECT_EQ(fileInfo->GetRestorePath(), restorePath);
@@ -289,7 +289,7 @@ HWTEST_F(ScanResultManagerTest, ADD_BIG_FILE_TEST_006, testing::ext::TestSize.Le
289 std::string filePath = "abc/aaa/test6.txt_anco_sss";289 std::string filePath = "abc/aaa/test6.txt_anco_sss";
290 std::string restorePath = "restore6";290 std::string restorePath = "restore6";
291 struct stat sta = {};291 struct stat sta = {};
292- manager_.AddBigFile(filePath, sta, restorePath);292+ manager_.AddBigFile(filePath, sta, false, restorePath);
293 auto fileInfo = manager_.GetFileInfo();293 auto fileInfo = manager_.GetFileInfo();
294 ASSERT_NE(fileInfo, nullptr);294 ASSERT_NE(fileInfo, nullptr);
295 EXPECT_EQ(fileInfo->GetRestorePath(), restorePath);295 EXPECT_EQ(fileInfo->GetRestorePath(), restorePath);
@@ -471,7 +471,7 @@ HWTEST_F(ScanResultManagerTest, WAIT_FOR_FILES_TEST_001, testing::ext::TestSize.
471 GTEST_LOG_(INFO) << "1. test wait for files";471 GTEST_LOG_(INFO) << "1. test wait for files";
472 std::string filePath = "abc/aaa/test1";472 std::string filePath = "abc/aaa/test1";
473 struct stat sta = {};473 struct stat sta = {};
474- manager_.AddBigFile(filePath, sta);474+ manager_.AddBigFile(filePath, sta, false);
475 EXPECT_EQ(manager_.pendingFileQueue_.size(), 1);475 EXPECT_EQ(manager_.pendingFileQueue_.size(), 1);
476 476 
477 auto start = std::chrono::steady_clock::now();477 auto start = std::chrono::steady_clock::now();
@@ -496,7 +496,7 @@ HWTEST_F(ScanResultManagerTest, WAIT_FOR_PACKET_FLAG_TEST_001, testing::ext::Tes
496 GTEST_LOG_(INFO) << "1. test wait for packet";496 GTEST_LOG_(INFO) << "1. test wait for packet";
497 std::string filePath = "abc/aaa/test1";497 std::string filePath = "abc/aaa/test1";
498 struct stat sta = {};498 struct stat sta = {};
499- manager_.AddBigFile(filePath, sta);499+ manager_.AddBigFile(filePath, sta, false);
500 EXPECT_EQ(manager_.pendingFileQueue_.size(), 1);500 EXPECT_EQ(manager_.pendingFileQueue_.size(), 1);
501 manager_.stopPacket_ = true;501 manager_.stopPacket_ = true;
502 manager_.StartPacket();502 manager_.StartPacket();
@@ -659,4 +659,335 @@ HWTEST_F(StringUtilsTest, STRINGUTILS_IS_PATH_WITH_DIRECTORY_TEST_001, testing::
659 EXPECT_TRUE(StringUtils::IsPathWithDirectory("\\"));659 EXPECT_TRUE(StringUtils::IsPathWithDirectory("\\"));
660 EXPECT_TRUE(StringUtils::IsPathWithDirectory("////"));660 EXPECT_TRUE(StringUtils::IsPathWithDirectory("////"));
661}661}
662+ 
663+/**
664+* @tc.number: STRINGUTILS_STRING_VECTOR_SERIALIZE_DESERIALIZE_TEST_001
665+* @tc.name: StringVectorSerialize_Deserialize_Normal
666+* @tc.desc: Test normal serialize and deserialize roundtrip
667+* @tc.size: SMALL
668+* @tc.type: FUNC
669+* @tc.level: Level 1
670+* @tc.require: NA
671+*/
672+HWTEST_F(StringUtilsTest, STRINGUTILS_STRING_VECTOR_SERIALIZE_DESERIALIZE_TEST_001, testing::ext::TestSize.Level1)
673+{
674+ GTEST_LOG_(INFO) << "StringUtilsTest-begin STRING_VECTOR_SERIALIZE_DESERIALIZE_TEST_001";
675+ std::vector<std::string> input = {"hello", "world", "/storage/Users/currentUser"};
676+ std::string serialized = StringUtils::StringVectorSerialize(input);
677+ EXPECT_FALSE(serialized.empty());
678+ std::vector<std::string> output = StringUtils::StringVectorDeserialize(serialized);
679+ EXPECT_EQ(output.size(), input.size());
680+ for (size_t i = 0; i < input.size(); ++i) {
681+ EXPECT_EQ(output[i], input[i]);
682+ }
683+ GTEST_LOG_(INFO) << "StringUtilsTest-end STRING_VECTOR_SERIALIZE_DESERIALIZE_TEST_001";
684+}
685+ 
686+/**
687+* @tc.number: STRINGUTILS_STRING_VECTOR_SERIALIZE_DESERIALIZE_TEST_002
688+* @tc.name: StringVectorSerialize_Deserialize_EmptyVector
689+* @tc.desc: Test serialize and deserialize with empty vector
690+* @tc.size: SMALL
691+* @tc.type: FUNC
692+* @tc.level: Level 1
693+* @tc.require: NA
694+*/
695+HWTEST_F(StringUtilsTest, STRINGUTILS_STRING_VECTOR_SERIALIZE_DESERIALIZE_TEST_002, testing::ext::TestSize.Level1)
696+{
697+ GTEST_LOG_(INFO) << "StringUtilsTest-begin STRING_VECTOR_SERIALIZE_DESERIALIZE_TEST_002";
698+ std::vector<std::string> input;
699+ std::string serialized = StringUtils::StringVectorSerialize(input);
700+ EXPECT_FALSE(serialized.empty());
701+ EXPECT_EQ(serialized.size(), sizeof(uint64_t));
702+ std::vector<std::string> output = StringUtils::StringVectorDeserialize(serialized);
703+ EXPECT_TRUE(output.empty());
704+ GTEST_LOG_(INFO) << "StringUtilsTest-end STRING_VECTOR_SERIALIZE_DESERIALIZE_TEST_002";
705+}
706+ 
707+/**
708+* @tc.number: STRINGUTILS_STRING_VECTOR_SERIALIZE_DESERIALIZE_TEST_003
709+* @tc.name: StringVectorSerialize_Deserialize_SingleEmptyString
710+* @tc.desc: Test serialize and deserialize with vector containing empty string
711+* @tc.size: SMALL
712+* @tc.type: FUNC
713+* @tc.level: Level 1
714+* @tc.require: NA
715+*/
716+HWTEST_F(StringUtilsTest, STRINGUTILS_STRING_VECTOR_SERIALIZE_DESERIALIZE_TEST_003, testing::ext::TestSize.Level1)
717+{
718+ GTEST_LOG_(INFO) << "StringUtilsTest-begin STRING_VECTOR_SERIALIZE_DESERIALIZE_TEST_003";
719+ std::vector<std::string> input = {""};
720+ std::string serialized = StringUtils::StringVectorSerialize(input);
721+ EXPECT_FALSE(serialized.empty());
722+ std::vector<std::string> output = StringUtils::StringVectorDeserialize(serialized);
723+ EXPECT_EQ(output.size(), 1);
724+ EXPECT_EQ(output[0], "");
725+ GTEST_LOG_(INFO) << "StringUtilsTest-end STRING_VECTOR_SERIALIZE_DESERIALIZE_TEST_003";
726+}
727+ 
728+/**
729+* @tc.number: STRINGUTILS_STRING_VECTOR_SERIALIZE_DESERIALIZE_TEST_004
730+* @tc.name: StringVectorSerialize_Deserialize_SpecialChars
731+* @tc.desc: Test serialize and deserialize with strings containing special characters
732+* @tc.size: SMALL
733+* @tc.type: FUNC
734+* @tc.level: Level 1
735+* @tc.require: NA
736+*/
737+HWTEST_F(StringUtilsTest, STRINGUTILS_STRING_VECTOR_SERIALIZE_DESERIALIZE_TEST_004, testing::ext::TestSize.Level1)
738+{
739+ GTEST_LOG_(INFO) << "StringUtilsTest-begin STRING_VECTOR_SERIALIZE_DESERIALIZE_TEST_004";
740+ std::vector<std::string> input = {"hello\nworld", "tab\there", "with\"quote", "back\\slash"};
741+ std::string serialized = StringUtils::StringVectorSerialize(input);
742+ EXPECT_FALSE(serialized.empty());
743+ std::vector<std::string> output = StringUtils::StringVectorDeserialize(serialized);
744+ EXPECT_EQ(output.size(), input.size());
745+ for (size_t i = 0; i < input.size(); ++i) {
746+ EXPECT_EQ(output[i], input[i]);
747+ }
748+ GTEST_LOG_(INFO) << "StringUtilsTest-end STRING_VECTOR_SERIALIZE_DESERIALIZE_TEST_004";
749+}
750+ 
751+/**
752+* @tc.number: STRINGUTILS_STRING_VECTOR_DESERIALIZE_TEST_005
753+* @tc.name: StringVectorDeserialize_InvalidData
754+* @tc.desc: Test deserialize with invalid data (too short, truncated)
755+* @tc.size: SMALL
756+* @tc.type: FUNC
757+* @tc.level: Level 1
758+* @tc.require: NA
759+*/
760+HWTEST_F(StringUtilsTest, STRINGUTILS_STRING_VECTOR_DESERIALIZE_TEST_005, testing::ext::TestSize.Level1)
761+{
762+ GTEST_LOG_(INFO) << "StringUtilsTest-begin STRING_VECTOR_DESERIALIZE_TEST_005";
763+ EXPECT_TRUE(StringUtils::StringVectorDeserialize("").empty());
764+ EXPECT_TRUE(StringUtils::StringVectorDeserialize("abc").empty());
765+ std::string sevenBytes(7, 'X');
766+ EXPECT_TRUE(StringUtils::StringVectorDeserialize(sevenBytes).empty());
767+ std::string truncated;
768+ uint64_t count = 1;
769+ truncated.append(reinterpret_cast<const char*>(&count), sizeof(uint64_t));
770+ EXPECT_TRUE(StringUtils::StringVectorDeserialize(truncated).empty());
771+ truncated.clear();
772+ truncated.append(reinterpret_cast<const char*>(&count), sizeof(uint64_t));
773+ uint64_t len = 5;
774+ truncated.append(reinterpret_cast<const char*>(&len), sizeof(uint64_t));
775+ EXPECT_TRUE(StringUtils::StringVectorDeserialize(truncated).empty());
776+ GTEST_LOG_(INFO) << "StringUtilsTest-end STRING_VECTOR_DESERIALIZE_TEST_005";
777+}
778+ 
779+/**
780+* @tc.number: STRINGUTILS_STRING_VECTOR_DESERIALIZE_TEST_006
781+* @tc.name: StringVectorDeserialize_TrailingGarbageData
782+* @tc.desc: Test deserialize rejects data with trailing garbage after valid content
783+* @tc.size: SMALL
784+* @tc.type: FUNC
785+* @tc.level: Level 1
786+* @tc.require: NA
787+*/
788+HWTEST_F(StringUtilsTest, STRINGUTILS_STRING_VECTOR_DESERIALIZE_TEST_006, testing::ext::TestSize.Level1)
789+{
790+ GTEST_LOG_(INFO) << "StringUtilsTest-begin STRING_VECTOR_DESERIALIZE_TEST_006";
791+ std::vector<std::string> input = {"hello"};
792+ std::string serialized = StringUtils::StringVectorSerialize(input);
793+ // append trailing garbage data
794+ serialized.append("GARBAGE");
795+ EXPECT_TRUE(StringUtils::StringVectorDeserialize(serialized).empty());
796+ // append single trailing byte
797+ serialized = StringUtils::StringVectorSerialize(input);
798+ serialized.append(1, '\0');
799+ EXPECT_TRUE(StringUtils::StringVectorDeserialize(serialized).empty());
800+ // count=0 with trailing garbage
801+ std::string zeroCount;
802+ uint64_t zero = 0;
803+ zeroCount.append(reinterpret_cast<const char*>(&zero), sizeof(uint64_t));
804+ zeroCount.append("trash");
805+ EXPECT_TRUE(StringUtils::StringVectorDeserialize(zeroCount).empty());
806+ GTEST_LOG_(INFO) << "StringUtilsTest-end STRING_VECTOR_DESERIALIZE_TEST_006";
807+}
808+ 
809+/**
810+* @tc.number: STRINGUTILS_STRING_VECTOR_DESERIALIZE_TEST_007
811+* @tc.name: StringVectorDeserialize_MaliciousLargeCount
812+* @tc.desc: Test deserialize rejects data with extremely large count value
813+* @tc.size: SMALL
814+* @tc.type: FUNC
815+* @tc.level: Level 1
816+* @tc.require: NA
817+*/
818+HWTEST_F(StringUtilsTest, STRINGUTILS_STRING_VECTOR_DESERIALIZE_TEST_007, testing::ext::TestSize.Level1)
819+{
820+ GTEST_LOG_(INFO) << "StringUtilsTest-begin STRING_VECTOR_DESERIALIZE_TEST_007";
821+ std::string malicious;
822+ uint64_t hugeCount = UINT64_MAX;
823+ malicious.append(reinterpret_cast<const char*>(&hugeCount), sizeof(uint64_t));
824+ EXPECT_TRUE(StringUtils::StringVectorDeserialize(malicious).empty());
825+ malicious.append(16, 'X');
826+ EXPECT_TRUE(StringUtils::StringVectorDeserialize(malicious).empty());
827+ uint64_t boundaryCount = 2;
828+ uint64_t bigLen = 100;
829+ std::string boundaryData;
830+ boundaryData.append(reinterpret_cast<const char*>(&boundaryCount), sizeof(uint64_t));
831+ boundaryData.append(reinterpret_cast<const char*>(&bigLen), sizeof(uint64_t));
832+ EXPECT_TRUE(StringUtils::StringVectorDeserialize(boundaryData).empty());
833+ GTEST_LOG_(INFO) << "StringUtilsTest-end STRING_VECTOR_DESERIALIZE_TEST_007";
834+}
835+ 
836+/**
837+* @tc.number: STRINGUTILS_STRING_VECTOR_DESERIALIZE_TEST_008
838+* @tc.name: StringVectorDeserialize_MaliciousLargeLen
839+* @tc.desc: Test deserialize rejects data with extremely large string length
840+* @tc.size: SMALL
841+* @tc.type: FUNC
842+* @tc.level: Level 1
843+* @tc.require: NA
844+*/
845+HWTEST_F(StringUtilsTest, STRINGUTILS_STRING_VECTOR_DESERIALIZE_TEST_008, testing::ext::TestSize.Level1)
846+{
847+ GTEST_LOG_(INFO) << "StringUtilsTest-begin STRING_VECTOR_DESERIALIZE_TEST_008";
848+ std::string malicious;
849+ uint64_t count = 1;
850+ uint64_t hugeLen = UINT64_MAX;
851+ malicious.append(reinterpret_cast<const char*>(&count), sizeof(uint64_t));
852+ malicious.append(reinterpret_cast<const char*>(&hugeLen), sizeof(uint64_t));
853+ EXPECT_TRUE(StringUtils::StringVectorDeserialize(malicious).empty());
854+ malicious.append(4, 'X');
855+ EXPECT_TRUE(StringUtils::StringVectorDeserialize(malicious).empty());
856+ GTEST_LOG_(INFO) << "StringUtilsTest-end STRING_VECTOR_DESERIALIZE_TEST_008";
857+}
858+ 
859+/**
860+* @tc.number: STRINGUTILS_STRING_VECTOR_SERIALIZE_DESERIALIZE_TEST_013
861+* @tc.name: StringVectorSerialize_ExceedsMaxSize
862+* @tc.desc: Test serialize rejects data when total size exceeds 16MB limit and accepts at boundary
863+* @tc.size: SMALL
864+* @tc.type: FUNC
865+* @tc.level: Level 1
866+* @tc.require: NA
867+*/
868+HWTEST_F(StringUtilsTest, STRINGUTILS_STRING_VECTOR_SERIALIZE_DESERIALIZE_TEST_013, testing::ext::TestSize.Level1)
869+{
870+ GTEST_LOG_(INFO) << "StringUtilsTest-begin STRING_VECTOR_SERIALIZE_DESERIALIZE_TEST_013";
871+ std::string bigStr(16 * 1024 * 1024, 'A');
872+ EXPECT_TRUE(StringUtils::StringVectorSerialize({bigStr}).empty());
873+ EXPECT_TRUE(StringUtils::StringVectorSerialize({"hello", bigStr}).empty());
874+ std::string nearLimit(16 * 1024 * 1024 - 2 * sizeof(uint64_t), 'A');
875+ std::string serialized = StringUtils::StringVectorSerialize({nearLimit});
876+ EXPECT_FALSE(serialized.empty());
877+ EXPECT_EQ(serialized.size(), static_cast<size_t>(16 * 1024 * 1024));
878+ GTEST_LOG_(INFO) << "StringUtilsTest-end STRING_VECTOR_SERIALIZE_DESERIALIZE_TEST_013";
879+}
880+ 
881+/**
882+* @tc.number: STRINGUTILS_STRING_VECTOR_DESERIALIZE_TEST_014
883+* @tc.name: StringVectorDeserialize_ExceedsMaxSize
884+* @tc.desc: Test deserialize rejects data exceeding 16MB limit and accepts at boundary
885+* @tc.size: SMALL
886+* @tc.type: FUNC
887+* @tc.level: Level 1
888+* @tc.require: NA
889+*/
890+HWTEST_F(StringUtilsTest, STRINGUTILS_STRING_VECTOR_DESERIALIZE_TEST_014, testing::ext::TestSize.Level1)
891+{
892+ GTEST_LOG_(INFO) << "StringUtilsTest-begin STRING_VECTOR_DESERIALIZE_TEST_014";
893+ std::string hugeData(16 * 1024 * 1024 + 1, 'X');
894+ EXPECT_TRUE(StringUtils::StringVectorDeserialize(hugeData).empty());
895+ std::string nearLimit(16 * 1024 * 1024 - 2 * sizeof(uint64_t), 'A');
896+ std::string serialized = StringUtils::StringVectorSerialize({nearLimit});
897+ EXPECT_EQ(serialized.size(), static_cast<size_t>(16 * 1024 * 1024));
898+ std::vector<std::string> output = StringUtils::StringVectorDeserialize(serialized);
899+ EXPECT_EQ(output.size(), 1);
900+ EXPECT_EQ(output[0], nearLimit);
901+ GTEST_LOG_(INFO) << "StringUtilsTest-end STRING_VECTOR_DESERIALIZE_TEST_014";
902+}
903+ 
904+/**
905+* @tc.number: STRINGUTILS_STRING_VECTOR_DESERIALIZE_TEST_009
906+* @tc.name: StringVectorDeserialize_PartialValidThenTruncated
907+* @tc.desc: Test deserialize rejects data where first string valid but second truncated
908+* @tc.size: SMALL
909+* @tc.type: FUNC
910+* @tc.level: Level 1
911+* @tc.require: NA
912+*/
913+HWTEST_F(StringUtilsTest, STRINGUTILS_STRING_VECTOR_DESERIALIZE_TEST_009, testing::ext::TestSize.Level1)
914+{
915+ GTEST_LOG_(INFO) << "StringUtilsTest-begin STRING_VECTOR_DESERIALIZE_TEST_009";
916+ std::vector<std::string> input = {"first", "second"};
917+ std::string serialized = StringUtils::StringVectorSerialize(input);
918+ // truncate: remove last few bytes so second string is incomplete
919+ EXPECT_TRUE(StringUtils::StringVectorDeserialize(serialized.substr(0, serialized.size() - 3)).empty());
920+ // truncate: remove len field of second string
921+ size_t firstStrEnd = sizeof(uint64_t) + sizeof(uint64_t) + 5;
922+ EXPECT_TRUE(StringUtils::StringVectorDeserialize(serialized.substr(0, firstStrEnd)).empty());
923+ GTEST_LOG_(INFO) << "StringUtilsTest-end STRING_VECTOR_DESERIALIZE_TEST_009";
924+}
925+ 
926+/**
927+* @tc.number: STRINGUTILS_STRING_VECTOR_SERIALIZE_DESERIALIZE_TEST_010
928+* @tc.name: StringVectorSerialize_Deserialize_EmptyStringsMixed
929+* @tc.desc: Test serialize and deserialize with mixed empty and non-empty strings
930+* @tc.size: SMALL
931+* @tc.type: FUNC
932+* @tc.level: Level 1
933+* @tc.require: NA
934+*/
935+HWTEST_F(StringUtilsTest, STRINGUTILS_STRING_VECTOR_SERIALIZE_DESERIALIZE_TEST_010, testing::ext::TestSize.Level1)
936+{
937+ GTEST_LOG_(INFO) << "StringUtilsTest-begin STRING_VECTOR_SERIALIZE_DESERIALIZE_TEST_010";
938+ std::vector<std::string> input = {"", "hello", "", "world", ""};
939+ std::string serialized = StringUtils::StringVectorSerialize(input);
940+ EXPECT_FALSE(serialized.empty());
941+ std::vector<std::string> output = StringUtils::StringVectorDeserialize(serialized);
942+ EXPECT_EQ(output.size(), input.size());
943+ for (size_t i = 0; i < input.size(); ++i) {
944+ EXPECT_EQ(output[i], input[i]);
945+ }
946+ GTEST_LOG_(INFO) << "StringUtilsTest-end STRING_VECTOR_SERIALIZE_DESERIALIZE_TEST_010";
947+}
948+ 
949+/**
950+* @tc.number: STRINGUTILS_STRING_VECTOR_SERIALIZE_DESERIALIZE_TEST_011
951+* @tc.name: StringVectorSerialize_Deserialize_BinaryContentWithNull
952+* @tc.desc: Test serialize and deserialize with strings containing embedded null bytes
953+* @tc.size: SMALL
954+* @tc.type: FUNC
955+* @tc.level: Level 1
956+* @tc.require: NA
957+*/
958+HWTEST_F(StringUtilsTest, STRINGUTILS_STRING_VECTOR_SERIALIZE_DESERIALIZE_TEST_011, testing::ext::TestSize.Level1)
959+{
960+ GTEST_LOG_(INFO) << "StringUtilsTest-begin STRING_VECTOR_SERIALIZE_DESERIALIZE_TEST_011";
961+ std::string withNull = "hello\0world";
962+ withNull.resize(11);
963+ std::vector<std::string> input = {withNull, "normal"};
964+ std::string serialized = StringUtils::StringVectorSerialize(input);
965+ EXPECT_FALSE(serialized.empty());
966+ std::vector<std::string> output = StringUtils::StringVectorDeserialize(serialized);
967+ EXPECT_EQ(output.size(), input.size());
968+ EXPECT_EQ(output[0].size(), 11);
969+ EXPECT_EQ(output[0], withNull);
970+ EXPECT_EQ(output[1], "normal");
971+ GTEST_LOG_(INFO) << "StringUtilsTest-end STRING_VECTOR_SERIALIZE_DESERIALIZE_TEST_011";
972+}
973+ 
974+/**
975+* @tc.number: STRINGUTILS_STRING_VECTOR_DESERIALIZE_TEST_012
976+* @tc.name: StringVectorDeserialize_CountZeroExactSize
977+* @tc.desc: Test deserialize with count=0 and exact data size (no trailing data)
978+* @tc.size: SMALL
979+* @tc.type: FUNC
980+* @tc.level: Level 1
981+* @tc.require: NA
982+*/
983+HWTEST_F(StringUtilsTest, STRINGUTILS_STRING_VECTOR_DESERIALIZE_TEST_012, testing::ext::TestSize.Level1)
984+{
985+ GTEST_LOG_(INFO) << "StringUtilsTest-begin STRING_VECTOR_DESERIALIZE_TEST_012";
986+ std::string zeroData;
987+ uint64_t zero = 0;
988+ zeroData.append(reinterpret_cast<const char*>(&zero), sizeof(uint64_t));
989+ std::vector<std::string> output = StringUtils::StringVectorDeserialize(zeroData);
990+ EXPECT_TRUE(output.empty());
991+ GTEST_LOG_(INFO) << "StringUtilsTest-end STRING_VECTOR_DESERIALIZE_TEST_012";
992+}
662} // namespace OHOS::FileManagement::Backup993} // namespace OHOS::FileManagement::Backup
@@ -32,6 +32,7 @@ struct ExtManageInfo {
32 struct stat sta {};32 struct stat sta {};
33 bool isUserTar {false};33 bool isUserTar {false};
34 bool isBigFile {false};34 bool isBigFile {false};
35+ bool isLongPath {false};
35};36};
36class BJsonEntityExtManage : public BJsonEntity {37class BJsonEntityExtManage : public BJsonEntity {
37public:38public:
@@ -17,7 +17,7 @@
17#define OHOS_FILEMGMT_BACKUP_B_RADAR_H17#define OHOS_FILEMGMT_BACKUP_B_RADAR_H
18#include <chrono>18#include <chrono>
19#include <string>19#include <string>
20-#include "iservice_reverse.h"20+#include "service_reverse_type.h"
21 21 
22namespace OHOS::FileManagement::Backup {22namespace OHOS::FileManagement::Backup {
23enum class BizStageBackup : int32_t {23enum class BizStageBackup : int32_t {
@@ -110,6 +110,7 @@ constexpr uint32_t MAX_UPDATE_TIMER = 4 * H2MS;
110constexpr uint32_t DEFAULT_TIMEOUT = 15 * 60 * 1000;110constexpr uint32_t DEFAULT_TIMEOUT = 15 * 60 * 1000;
111constexpr uint32_t TIMEOUT_INVALID = UINT32_MAX;111constexpr uint32_t TIMEOUT_INVALID = UINT32_MAX;
112constexpr int LONG_FILE_NAME_BOUNDARY_VAL = 255;112constexpr int LONG_FILE_NAME_BOUNDARY_VAL = 255;
113+constexpr int PATH_LEN_SAFE_THRESHOLD = 500;
113 114 
114constexpr int CALL_APP_ON_PROCESS_TIME_INTERVAL = 5; // 框架每隔5s去调用应用的onProcess115constexpr int CALL_APP_ON_PROCESS_TIME_INTERVAL = 5; // 框架每隔5s去调用应用的onProcess
115constexpr int APP_ON_PROCESS_MAX_TIMEOUT = 1000; // 应用的onProcess接口最大超时时间为1秒116constexpr int APP_ON_PROCESS_MAX_TIMEOUT = 1000; // 应用的onProcess接口最大超时时间为1秒
@@ -44,6 +44,7 @@ public:
44 struct stat sta_;44 struct stat sta_;
45 bool isBigFile_ = false;45 bool isBigFile_ = false;
46 bool isAncoFile_ = false;46 bool isAncoFile_ = false;
47+ bool isLongPath_ = false;
47};48};
48 49 
49struct FileInfo : public IFileInfo {50struct FileInfo : public IFileInfo {
@@ -112,7 +113,10 @@ public:
112 std::vector<std::shared_ptr<IFileInfo>> GetAllFiles();113 std::vector<std::shared_ptr<IFileInfo>> GetAllFiles();
113 void AddAllFile(std::shared_ptr<IFileInfo> &fileInfo);114 void AddAllFile(std::shared_ptr<IFileInfo> &fileInfo);
114 115 
115- void AddBigFile(const std::string& filePath, const struct stat& sta, const std::string& restorePath = "");116+ void AddBigFile(const std::string &filePath,
117+ const struct stat &sta,
118+ bool isLongPath,
119+ const std::string &restorePath = "");
116 void AddTarFile(const std::string& filename, const std::string& filePath, const struct stat& sta);120 void AddTarFile(const std::string& filename, const std::string& filePath, const struct stat& sta);
117 void AddAncoBigFile(const std::string &filePath, const std::string &restorePath, const struct stat &sta);121 void AddAncoBigFile(const std::string &filePath, const std::string &restorePath, const struct stat &sta);
118 void AddAncoTarFile(const std::string &filename, const std::string &filePath, const struct stat &sta);122 void AddAncoTarFile(const std::string &filename, const std::string &filePath, const struct stat &sta);
@@ -27,6 +27,8 @@ public:
27 static bool EndsWith(const std::string& str, const std::string& suffix);27 static bool EndsWith(const std::string& str, const std::string& suffix);
28 static std::vector<std::string> Split(const std::string& str, const std::string& delimiter);28 static std::vector<std::string> Split(const std::string& str, const std::string& delimiter);
29 static std::string Concat(const std::vector<std::string>& strs, const std::string& connector);29 static std::string Concat(const std::vector<std::string>& strs, const std::string& connector);
30+ static std::string StringVectorSerialize(const std::vector<std::string>& vec);
31+ static std::vector<std::string> StringVectorDeserialize(const std::string& data);
30 32 
31 static std::string PathAddDelimiter(const std::string& path);33 static std::string PathAddDelimiter(const std::string& path);
32 static std::string GenMappingDir(const std::string& backupDir, const std::string& restoreDir);34 static std::string GenMappingDir(const std::string& backupDir, const std::string& restoreDir);
@@ -150,8 +150,16 @@ static void ProcessFile(const ProcessInfo &info, int64_t &bigFileSize, int64_t &
150 struct stat sta = {};150 struct stat sta = {};
151 size_t restoreTempPathLen = option.enableBatch ? option.restoreTempPath.size() : 0;151 size_t restoreTempPathLen = option.enableBatch ? option.restoreTempPath.size() : 0;
152 if (StringUtils::CheckOverLongPath(info.backupPath_) + restoreTempPathLen >= BConstants::MAX_PATH_LEN) {152 if (StringUtils::CheckOverLongPath(info.backupPath_) + restoreTempPathLen >= BConstants::MAX_PATH_LEN) {
153+ HILOGE("path is too long: %{public}zu, %{public}s", info.backupPath_.size(),
154+ GetAnonyPath(info.backupPath_).c_str());
153 return;155 return;
154 }156 }
157+ bool isLongPath = false;
158+ if (option.enableBatch &&
159+ StringUtils::CheckOverLongPath(info.backupPath_) + restoreTempPathLen + BConstants::PATH_LEN_SAFE_THRESHOLD >=
160+ BConstants::MAX_PATH_LEN) {
161+ isLongPath = true;
162+ }
155 if (stat(info.backupPath_.data(), &sta) == -1) {163 if (stat(info.backupPath_.data(), &sta) == -1) {
156 HILOGE("stat file fail, errno=%{public}d", errno);164 HILOGE("stat file fail, errno=%{public}d", errno);
157 return;165 return;
@@ -161,7 +169,7 @@ static void ProcessFile(const ProcessInfo &info, int64_t &bigFileSize, int64_t &
161 option.resultManager->AddSmallFile(info.backupPath_, sta.st_size, info.restorePath_);169 option.resultManager->AddSmallFile(info.backupPath_, sta.st_size, info.restorePath_);
162 smallFileSize += sta.st_size;170 smallFileSize += sta.st_size;
163 } else {171 } else {
164- option.resultManager->AddBigFile(info.backupPath_, sta, info.restorePath_);172+ option.resultManager->AddBigFile(info.backupPath_, sta, isLongPath, info.restorePath_);
165 bigFileSize += sta.st_size;173 bigFileSize += sta.st_size;
166 }174 }
167 return;175 return;
@@ -170,7 +178,7 @@ static void ProcessFile(const ProcessInfo &info, int64_t &bigFileSize, int64_t &
170 ScanFileSingleton::GetInstance().AddSmallFile(info.backupPath_, sta.st_size, info.restorePath_);178 ScanFileSingleton::GetInstance().AddSmallFile(info.backupPath_, sta.st_size, info.restorePath_);
171 smallFileSize += sta.st_size;179 smallFileSize += sta.st_size;
172 } else {180 } else {
173- ScanFileSingleton::GetInstance().AddBigFile(info.backupPath_, sta, info.restorePath_);181+ ScanFileSingleton::GetInstance().AddBigFile(info.backupPath_, sta, isLongPath, info.restorePath_);
174 bigFileSize += sta.st_size;182 bigFileSize += sta.st_size;
175 }183 }
176}184}
@@ -286,6 +286,8 @@ std::vector<ExtManageInfo> BJsonEntityExtManage::GetExtManageInfo() const
286 string fileName = item.isMember("fileName") && item["fileName"].isString() ? item["fileName"].asString() : "";286 string fileName = item.isMember("fileName") && item["fileName"].isString() ? item["fileName"].asString() : "";
287 bool isUserTar = item.isMember("isUserTar") && item["isUserTar"].isBool() ? item["isUserTar"].asBool() : false;287 bool isUserTar = item.isMember("isUserTar") && item["isUserTar"].isBool() ? item["isUserTar"].asBool() : false;
288 bool isBigFile = item.isMember("isBigFile") && item["isBigFile"].isBool() ? item["isBigFile"].asBool() : false;288 bool isBigFile = item.isMember("isBigFile") && item["isBigFile"].isBool() ? item["isBigFile"].asBool() : false;
289+ bool isLongPath =
290+ item.isMember("isLongPath") && item["isLongPath"].isBool() ? item["isLongPath"].asBool() : false;
289 // 兼容旧版本没有isBigFile属性时,增加判断是否为bigFile291 // 兼容旧版本没有isBigFile属性时,增加判断是否为bigFile
290 if (!item.isMember("isBigFile") && fileName != "" && ExtractFileExt(fileName) != "tar") {292 if (!item.isMember("isBigFile") && fileName != "" && ExtractFileExt(fileName) != "tar") {
291 isBigFile = true;293 isBigFile = true;
@@ -294,7 +296,8 @@ std::vector<ExtManageInfo> BJsonEntityExtManage::GetExtManageInfo() const
294 isUserTar, isBigFile);296 isUserTar, isBigFile);
295 if (!fileName.empty()) {297 if (!fileName.empty()) {
296 ExtManageInfo info = {298 ExtManageInfo info = {
297- .hashName = fileName, .fileName = path, .sta = sta, .isUserTar = isUserTar, .isBigFile = isBigFile};299+ .hashName = fileName, .fileName = path, .sta = sta, .isUserTar = isUserTar, .isBigFile = isBigFile,
300+ .isLongPath = isLongPath};
298 infos.emplace_back(info);301 infos.emplace_back(info);
299 }302 }
300 }303 }
@@ -86,7 +86,10 @@ uint64_t ScanResultManager::GetMaxTarSize()
86 return maxTarSize_.load();86 return maxTarSize_.load();
87}87}
88 88 
89-void ScanResultManager::AddBigFile(const std::string& filePath, const struct stat& sta, const std::string& restorePath)89+void ScanResultManager::AddBigFile(const std::string &filePath,
90+ const struct stat &sta,
91+ bool isLongPath,
92+ const std::string &restorePath)
90{93{
91 std::lock_guard<std::mutex> lock(pendingFileMutex_);94 std::lock_guard<std::mutex> lock(pendingFileMutex_);
92 std::string hashName = StringUtils::GenHashName(filePath);95 std::string hashName = StringUtils::GenHashName(filePath);
@@ -100,9 +103,13 @@ void ScanResultManager::AddBigFile(const std::string& filePath, const struct sta
100 hashName += "." + ext;103 hashName += "." + ext;
101 }104 }
102 if (restorePath.empty()) {105 if (restorePath.empty()) {
103- pendingFileQueue_.push(std::make_shared<FileInfo>(hashName, filePath, sta, true));106+ auto file = std::make_shared<FileInfo>(hashName, filePath, sta, true);
107+ file->isLongPath_ = isLongPath;
108+ pendingFileQueue_.push(file);
104 } else {109 } else {
105- pendingFileQueue_.push(std::make_shared<CompatibleFileInfo>(hashName, filePath, sta, true, restorePath));110+ auto file = std::make_shared<CompatibleFileInfo>(hashName, filePath, sta, true, restorePath);
111+ file->isLongPath_ = isLongPath;
112+ pendingFileQueue_.push(file);
106 }113 }
107 waitFilesReady_.notify_all();114 waitFilesReady_.notify_all();
108}115}
@@ -14,6 +14,7 @@
14 */14 */
15 15 
16#include "b_utils/string_utils.h"16#include "b_utils/string_utils.h"
17+#include "securec.h"
17#include <directory_ex.h>18#include <directory_ex.h>
18#include <iomanip>19#include <iomanip>
19#include <sstream>20#include <sstream>
@@ -22,6 +23,7 @@
22 23 
23namespace OHOS::FileManagement::Backup {24namespace OHOS::FileManagement::Backup {
24constexpr size_t CLOUD_HASH_LENGTH = 33;25constexpr size_t CLOUD_HASH_LENGTH = 33;
26+constexpr size_t MAX_SERIALIZED_SIZE = 16 * 1024 * 1024;
25 27 
26bool StringUtils::EndsWith(const std::string& str, const std::string& suffix)28bool StringUtils::EndsWith(const std::string& str, const std::string& suffix)
27{29{
@@ -59,6 +61,99 @@ std::string StringUtils::Concat(const std::vector<std::string>& strs, const std:
59 return result;61 return result;
60}62}
61 63 
64+std::string StringUtils::StringVectorSerialize(const std::vector<std::string>& vec)
65+{
66+ size_t total = sizeof(uint64_t);
67+ for (const auto& str : vec) {
68+ total += sizeof(uint64_t) + str.size();
69+ }
70+ if (total > MAX_SERIALIZED_SIZE) {
71+ HILOGE("StringVectorSerialize total size %{public}zu exceeds limit %{public}zu", total, MAX_SERIALIZED_SIZE);
72+ return {};
73+ }
74+ std::string result;
75+ result.resize(total);
76+ size_t pos = 0;
77+ uint64_t count = static_cast<uint64_t>(vec.size());
78+ if (memcpy_s(&result[pos], result.size() - pos, &count, sizeof(uint64_t)) != EOK) {
79+ HILOGE("StringVectorSerialize write count failed");
80+ result.clear();
81+ return result;
82+ }
83+ pos += sizeof(uint64_t);
84+ for (const auto& str : vec) {
85+ uint64_t len = static_cast<uint64_t>(str.size());
86+ if (memcpy_s(&result[pos], result.size() - pos, &len, sizeof(uint64_t)) != EOK) {
87+ HILOGE("StringVectorSerialize write len failed");
88+ result.clear();
89+ return result;
90+ }
91+ pos += sizeof(uint64_t);
92+ if (len > 0 && memcpy_s(&result[pos], result.size() - pos, str.data(), static_cast<size_t>(len)) != EOK) {
93+ HILOGE("StringVectorSerialize write str failed");
94+ result.clear();
95+ return result;
96+ }
97+ pos += static_cast<size_t>(len);
98+ }
99+ return result;
100+}
101+ 
102+static bool ReadOneString(const std::string& data, size_t& pos, std::string& out)
103+{
104+ if (pos + sizeof(uint64_t) > data.size()) {
105+ HILOGE("StringVectorDeserialize unexpected end of data at string length");
106+ return false;
107+ }
108+ uint64_t len = 0;
109+ if (memcpy_s(&len, sizeof(uint64_t), data.data() + pos, sizeof(uint64_t)) != EOK) {
110+ HILOGE("StringVectorDeserialize read len failed");
111+ return false;
112+ }
113+ pos += sizeof(uint64_t);
114+ if (len > data.size() - pos) {
115+ HILOGE("StringVectorDeserialize unexpected end of data at string content");
116+ return false;
117+ }
118+ out.assign(data.data() + pos, static_cast<size_t>(len));
119+ pos += static_cast<size_t>(len);
120+ return true;
121+}
122+ 
123+std::vector<std::string> StringUtils::StringVectorDeserialize(const std::string& data)
124+{
125+ std::vector<std::string> result;
126+ if (data.size() < sizeof(uint64_t) || data.size() > MAX_SERIALIZED_SIZE) {
127+ HILOGE("StringVectorDeserialize data size %{public}zu invalid", data.size());
128+ return result;
129+ }
130+ size_t pos = 0;
131+ uint64_t count = 0;
132+ if (memcpy_s(&count, sizeof(uint64_t), data.data() + pos, sizeof(uint64_t)) != EOK) {
133+ HILOGE("StringVectorDeserialize read count failed");
134+ return result;
135+ }
136+ pos += sizeof(uint64_t);
137+ if (count > data.size() / sizeof(uint64_t)) {
138+ HILOGE("StringVectorDeserialize count %{public}llu too large", static_cast<unsigned long long>(count));
139+ return result;
140+ }
141+ result.reserve(static_cast<size_t>(count));
142+ for (uint64_t i = 0; i < count; ++i) {
143+ std::string item;
144+ if (!ReadOneString(data, pos, item)) {
145+ return {};
146+ }
147+ result.emplace_back(std::move(item));
148+ }
149+ if (pos != data.size()) {
150+ HILOGE("StringVectorDeserialize trailing data detected, pos=%{public}zu, dataSize=%{public}zu",
151+ pos, data.size());
152+ return {};
153+ }
154+ return result;
155+}
156+ 
62std::string StringUtils::PathAddDelimiter(const std::string& path)157std::string StringUtils::PathAddDelimiter(const std::string& path)
63{158{
64 if (path.empty()) {159 if (path.empty()) {