已合并
fix StartAncoMove fd -1 bug #2209
rainlost创建于 7月21日
fix StartAncoMove fd -1 bug #2209
已合并
共 18 个文件变更+100-51
| @@ -98,7 +98,7 @@ public: | |||
| 98 | static ErrCode StartAncoUnPacket(const std::string &tempPath); | 98 | static ErrCode StartAncoUnPacket(const std::string &tempPath); |
| 99 | static ErrCode AddAncoMovePaths(const std::vector<std::string> &ancoSourcePath, | 99 | static ErrCode AddAncoMovePaths(const std::vector<std::string> &ancoSourcePath, |
| 100 | const std::vector<std::string> &ancoTargetPath, const std::vector<StatInfo> &ancoStats); | 100 | const std::vector<std::string> &ancoTargetPath, const std::vector<StatInfo> &ancoStats); |
| 101 | - static AncoRestoreResult StartAncoMove(UniqueFd &fd); | 101 | + static AncoRestoreResult StartAncoMove(); |
| 102 | }; | 102 | }; |
| 103 | class BackupExtExtension : public ExtensionStub { | 103 | class BackupExtExtension : public ExtensionStub { |
| 104 | friend class AncoBackupCallback; | 104 | friend class AncoBackupCallback; |
| @@ -438,7 +438,7 @@ ErrCode AncoIncrementalRestoreHelper::AddAncoMovePaths(const std::vector<std::st | |||
| 438 | return BError(BError::Codes::OK); | 438 | return BError(BError::Codes::OK); |
| 439 | } | 439 | } |
| 440 | 440 | ||
| 441 | -AncoRestoreResult AncoIncrementalRestoreHelper::StartAncoMove(UniqueFd& fd) | 441 | +AncoRestoreResult AncoIncrementalRestoreHelper::StartAncoMove() |
| 442 | { | 442 | { |
| 443 | AncoRestoreResult ancoRestoreRes; | 443 | AncoRestoreResult ancoRestoreRes; |
| 444 | auto proxy = ServiceClient::GetInstance(); | 444 | auto proxy = ServiceClient::GetInstance(); |
| @@ -446,9 +446,7 @@ AncoRestoreResult AncoIncrementalRestoreHelper::StartAncoMove(UniqueFd& fd) | |||
| 446 | HILOGE("Failed to get backup service"); | 446 | HILOGE("Failed to get backup service"); |
| 447 | return ancoRestoreRes; | 447 | return ancoRestoreRes; |
| 448 | } | 448 | } |
| 449 | - int tempfd = fd.Get(); | 449 | + auto ret = proxy->StartAncoMove(ancoRestoreRes); |
| 450 | - auto ret = proxy->StartAncoMove(tempfd, ancoRestoreRes); | ||
| 451 | - fd = UniqueFd(tempfd); | ||
| 452 | if (ret != ERR_OK) { | 450 | if (ret != ERR_OK) { |
| 453 | HILOGE("Failed to StartAncoMove. err = %{public}d", ret); | 451 | HILOGE("Failed to StartAncoMove. err = %{public}d", ret); |
| 454 | } | 452 | } |
| @@ -1588,31 +1588,35 @@ void BackupExtExtension::RestoreBigFiles(bool appendTargetPath) | |||
| 1588 | } | 1588 | } |
| 1589 | 1589 | ||
| 1590 | void BackupExtExtension::ExecuteAncoMove(const std::vector<std::string> &ancoSourcePath, | 1590 | void BackupExtExtension::ExecuteAncoMove(const std::vector<std::string> &ancoSourcePath, |
| 1591 | - const std::vector<std::string> &ancoTargetPath, const std::vector<StatInfo> &ancoStats) | 1591 | + const std::vector<std::string> &ancoTargetPath, |
| 1592 | + const std::vector<StatInfo> &ancoStats) | ||
| 1592 | { | 1593 | { |
| 1593 | if (!BConstants::CheckBundlePermissions(bundleName_)) { | 1594 | if (!BConstants::CheckBundlePermissions(bundleName_)) { |
| 1594 | return; | 1595 | return; |
| 1595 | } | 1596 | } |
| 1596 | - | 1597 | + |
| 1597 | AncoIncrementalRestoreHelper::AddAncoMovePaths(ancoSourcePath, ancoTargetPath, ancoStats); | 1598 | AncoIncrementalRestoreHelper::AddAncoMovePaths(ancoSourcePath, ancoTargetPath, ancoStats); |
| 1598 | - | 1599 | + |
| 1599 | - UniqueFd cloneFileInfoFd(-1); | ||
| 1600 | HILOGI("RestoreBigFiles bundleName_: %{public}s", bundleName_.c_str()); | 1600 | HILOGI("RestoreBigFiles bundleName_: %{public}s", bundleName_.c_str()); |
| 1601 | - ancoRestoreRes_ = AncoIncrementalRestoreHelper::StartAncoMove(cloneFileInfoFd); | 1601 | + ancoRestoreRes_ = AncoIncrementalRestoreHelper::StartAncoMove(); |
| 1602 | - | 1602 | + |
| 1603 | - if (cloneFileInfoFd <= 0) { | 1603 | + UniqueFd cloneFileInfoFd; |
| 1604 | + if (ancoRestoreRes_.dbFd != nullptr) { | ||
| 1605 | + cloneFileInfoFd = std::move(*ancoRestoreRes_.dbFd); | ||
| 1606 | + } | ||
| 1607 | + if (cloneFileInfoFd < 0) { | ||
| 1604 | HILOGE("cloneFileInfoFd invalid, fd = %{public}d", cloneFileInfoFd.Get()); | 1608 | HILOGE("cloneFileInfoFd invalid, fd = %{public}d", cloneFileInfoFd.Get()); |
| 1605 | return; | 1609 | return; |
| 1606 | } | 1610 | } |
| 1607 | - | 1611 | + |
| 1608 | if (bundleName_ != MEDIA_LIBRARY_BUNDLE_NAME) { | 1612 | if (bundleName_ != MEDIA_LIBRARY_BUNDLE_NAME) { |
| 1609 | HILOGI("Skip db copy for non-media app"); | 1613 | HILOGI("Skip db copy for non-media app"); |
| 1610 | return; | 1614 | return; |
| 1611 | } | 1615 | } |
| 1612 | - | 1616 | + |
| 1613 | std::string mediaPath = "/storage/media/local/files/.backup/restore/clone_file_info_restore.db"; | 1617 | std::string mediaPath = "/storage/media/local/files/.backup/restore/clone_file_info_restore.db"; |
| 1614 | UniqueFd mediaFd(open(mediaPath.data(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)); | 1618 | UniqueFd mediaFd(open(mediaPath.data(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)); |
| 1615 | - if (mediaFd <= 0) { | 1619 | + if (mediaFd < 0) { |
| 1616 | HILOGE("Failed to open mediaPath, fd = %{public}d", mediaFd.Get()); | 1620 | HILOGE("Failed to open mediaPath, fd = %{public}d", mediaFd.Get()); |
| 1617 | return; | 1621 | return; |
| 1618 | } | 1622 | } |
| @@ -17,6 +17,8 @@ | |||
| 17 | 17 | ||
| 18 | #include "b_error/b_error.h" | 18 | #include "b_error/b_error.h" |
| 19 | #include "filemgmt_libhilog.h" | 19 | #include "filemgmt_libhilog.h" |
| 20 | +#include "message_parcel.h" | ||
| 21 | + | ||
| 20 | #include <cstdint> | 22 | #include <cstdint> |
| 21 | 23 | ||
| 22 | namespace OHOS::FileManagement::Backup { | 24 | namespace OHOS::FileManagement::Backup { |
| @@ -24,21 +26,64 @@ using namespace std; | |||
| 24 | 26 | ||
| 25 | bool AncoRestoreResult::Marshalling(Parcel &parcel) const | 27 | bool AncoRestoreResult::Marshalling(Parcel &parcel) const |
| 26 | { | 28 | { |
| 27 | - if (!parcel.WriteInt64(successCount) || !parcel.WriteInt64(duplicateCount) || !parcel.WriteInt64(failedCount)) { | 29 | + auto messageParcel = static_cast<MessageParcel *>(&parcel); |
| 30 | + if (!messageParcel) { | ||
| 31 | + HILOGE("Failed to cast parcel to MessageParcel"); | ||
| 32 | + return false; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + if (!messageParcel->WriteInt64(successCount) || !messageParcel->WriteInt64(duplicateCount) || | ||
| 36 | + !messageParcel->WriteInt64(failedCount)) { | ||
| 28 | HILOGE("Failed to write count"); | 37 | HILOGE("Failed to write count"); |
| 29 | return false; | 38 | return false; |
| 30 | } | 39 | } |
| 31 | 40 | ||
| 41 | + int isDbFdValid = (dbFd != nullptr && dbFd->Get() >= 0) ? 1 : 0; | ||
| 42 | + if (!messageParcel->WriteInt32(isDbFdValid)) { | ||
| 43 | + HILOGE("Failed to write main file descriptor validity"); | ||
| 44 | + return false; | ||
| 45 | + } | ||
| 46 | + if (isDbFdValid) { | ||
| 47 | + if (!messageParcel->WriteFileDescriptor(dbFd->Get())) { | ||
| 48 | + HILOGE("Failed to write db file descriptor: fd=%d", dbFd->Get()); | ||
| 49 | + return false; | ||
| 50 | + } | ||
| 51 | + } | ||
| 52 | + | ||
| 32 | return true; | 53 | return true; |
| 33 | } | 54 | } |
| 34 | 55 | ||
| 35 | bool AncoRestoreResult::ReadFromParcel(Parcel &parcel) | 56 | bool AncoRestoreResult::ReadFromParcel(Parcel &parcel) |
| 36 | { | 57 | { |
| 37 | - if (!parcel.ReadInt64(successCount) || !parcel.ReadInt64(duplicateCount) || !parcel.ReadInt64(failedCount)) { | 58 | + auto messageParcel = static_cast<MessageParcel *>(&parcel); |
| 59 | + if (!messageParcel) { | ||
| 60 | + HILOGE("Failed to cast parcel to MessageParcel"); | ||
| 61 | + return false; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + if (!messageParcel->ReadInt64(successCount) || !messageParcel->ReadInt64(duplicateCount) || | ||
| 65 | + !messageParcel->ReadInt64(failedCount)) { | ||
| 38 | HILOGE("Failed to read count"); | 66 | HILOGE("Failed to read count"); |
| 39 | return false; | 67 | return false; |
| 40 | } | 68 | } |
| 41 | 69 | ||
| 70 | + int dbFdVal = -1; | ||
| 71 | + int isDbFdValid = 0; | ||
| 72 | + if (!messageParcel->ReadInt32(isDbFdValid)) { | ||
| 73 | + HILOGE("Failed to read main file descriptor validity"); | ||
| 74 | + return false; | ||
| 75 | + } | ||
| 76 | + if (isDbFdValid) { | ||
| 77 | + dbFdVal = messageParcel->ReadFileDescriptor(); | ||
| 78 | + if (dbFdVal < 0) { | ||
| 79 | + HILOGE("Failed to read db file descriptor from parcel"); | ||
| 80 | + return false; | ||
| 81 | + } | ||
| 82 | + dbFd = std::make_shared<UniqueFd>(dbFdVal); | ||
| 83 | + } else { | ||
| 84 | + dbFd = nullptr; | ||
| 85 | + } | ||
| 86 | + | ||
| 42 | return true; | 87 | return true; |
| 43 | } | 88 | } |
| 44 | 89 | ||
| @@ -78,7 +78,7 @@ public: | |||
| 78 | virtual ErrCode StartAncoUnPacket(const std::string &bundleName, const std::string &rootPath) = 0; | 78 | virtual ErrCode StartAncoUnPacket(const std::string &bundleName, const std::string &rootPath) = 0; |
| 79 | virtual ErrCode AddAncoMovePaths(const std::string &bundleName, const std::vector<std::string> &ancoSourcePath, | 79 | virtual ErrCode AddAncoMovePaths(const std::string &bundleName, const std::vector<std::string> &ancoSourcePath, |
| 80 | const std::vector<std::string> &ancoTargetPath, const std::vector<StatInfo> &ancoStats) = 0; | 80 | const std::vector<std::string> &ancoTargetPath, const std::vector<StatInfo> &ancoStats) = 0; |
| 81 | - virtual ErrCode StartAncoMove(const std::string &bundleName, int &fd, AncoRestoreResult &ancoRestoreRes) = 0; | 81 | + virtual ErrCode StartAncoMove(const std::string &bundleName, AncoRestoreResult &ancoRestoreRes) = 0; |
| 82 | // fd needs to be released by the caller. | 82 | // fd needs to be released by the caller. |
| 83 | virtual int OpenAncoFileReadOnly(const std::string &sandboxPath) = 0; | 83 | virtual int OpenAncoFileReadOnly(const std::string &sandboxPath) = 0; |
| 84 | virtual bool RemoveAncoFile(const std::string &sandboxPath) = 0; | 84 | virtual bool RemoveAncoFile(const std::string &sandboxPath) = 0; |
| @@ -18,8 +18,10 @@ | |||
| 18 | 18 | ||
| 19 | #include "parcel.h" | 19 | #include "parcel.h" |
| 20 | #include <string> | 20 | #include <string> |
| 21 | +#include <unique_fd.h> | ||
| 21 | #include <vector> | 22 | #include <vector> |
| 22 | #include <map> | 23 | #include <map> |
| 24 | +#include <memory> | ||
| 23 | 25 | ||
| 24 | namespace OHOS::FileManagement::Backup { | 26 | namespace OHOS::FileManagement::Backup { |
| 25 | using ErrCode = int; | 27 | using ErrCode = int; |
| @@ -27,6 +29,7 @@ struct AncoRestoreResult : public Parcelable { | |||
| 27 | int64_t successCount{0}; | 29 | int64_t successCount{0}; |
| 28 | int64_t duplicateCount{0}; | 30 | int64_t duplicateCount{0}; |
| 29 | int64_t failedCount{0}; | 31 | int64_t failedCount{0}; |
| 32 | + std::shared_ptr<UniqueFd> dbFd; | ||
| 30 | std::map<std::string, int64_t> endFileInfos; | 33 | std::map<std::string, int64_t> endFileInfos; |
| 31 | std::map<std::string, std::vector<ErrCode>> errFileInfos; | 34 | std::map<std::string, std::vector<ErrCode>> errFileInfos; |
| 32 | off_t bigFileSize = 0; | 35 | off_t bigFileSize = 0; |
| @@ -39,6 +42,12 @@ struct AncoRestoreResult : public Parcelable { | |||
| 39 | AncoRestoreResult(int64_t successCount_, int64_t duplicateCount_, int64_t failedCount_) | 42 | AncoRestoreResult(int64_t successCount_, int64_t duplicateCount_, int64_t failedCount_) |
| 40 | : successCount(successCount_), duplicateCount(duplicateCount_), failedCount(failedCount_) | 43 | : successCount(successCount_), duplicateCount(duplicateCount_), failedCount(failedCount_) |
| 41 | {} | 44 | {} |
| 45 | + AncoRestoreResult(int64_t successCount_, int64_t duplicateCount_, int64_t failedCount_, UniqueFd dbFd) | ||
| 46 | + : successCount(successCount_), | ||
| 47 | + duplicateCount(duplicateCount_), | ||
| 48 | + failedCount(failedCount_), | ||
| 49 | + dbFd(std::make_shared<UniqueFd>(std::move(dbFd))) | ||
| 50 | + {} | ||
| 42 | ~AncoRestoreResult() override = default; | 51 | ~AncoRestoreResult() override = default; |
| 43 | 52 | ||
| 44 | bool ReadFromParcel(Parcel &parcel); | 53 | bool ReadFromParcel(Parcel &parcel); |
| @@ -96,7 +96,7 @@ interface OHOS.FileManagement.Backup.IService{ | |||
| 96 | [ipccode 54] void StartAncoUnPacket([in] String rootPath); | 96 | [ipccode 54] void StartAncoUnPacket([in] String rootPath); |
| 97 | [ipccode 55, ipcincapacity 1024] void AddAncoMovePaths([in] String[] ancoSourcePath, [in] String[] ancoTargetPath, | 97 | [ipccode 55, ipcincapacity 1024] void AddAncoMovePaths([in] String[] ancoSourcePath, [in] String[] ancoTargetPath, |
| 98 | [in] StatInfo[] ancoStats); | 98 | [in] StatInfo[] ancoStats); |
| 99 | - [ipccode 56] void StartAncoMove([out] FileDescriptor fd, [out] AncoRestoreResult ancoRestoreRes); | 99 | + [ipccode 56] void StartAncoMove([out] AncoRestoreResult ancoRestoreRes); |
| 100 | [ipccode 57] void AppAncoFileReady([in] String fileName, [in] String filePath, [in] boolean needDelete); | 100 | [ipccode 57] void AppAncoFileReady([in] String fileName, [in] String filePath, [in] boolean needDelete); |
| 101 | [ipccode 58, ipcincapacity 1024] void AddAncoTars([in] String[] tarFiles, [in] long[] tarFileSizes, | 101 | [ipccode 58, ipcincapacity 1024] void AddAncoTars([in] String[] tarFiles, [in] long[] tarFileSizes, |
| 102 | [in] String[] tarFileNames); | 102 | [in] String[] tarFileNames); |
| @@ -165,7 +165,7 @@ public: | |||
| 165 | ErrCode StartAncoUnPacket(const std::string &rootPath) override; | 165 | ErrCode StartAncoUnPacket(const std::string &rootPath) override; |
| 166 | ErrCode AddAncoMovePaths(const std::vector<std::string> &ancoSourcePath, | 166 | ErrCode AddAncoMovePaths(const std::vector<std::string> &ancoSourcePath, |
| 167 | const std::vector<std::string> &ancoTargetPath, const std::vector<StatInfo> &ancoStats) override; | 167 | const std::vector<std::string> &ancoTargetPath, const std::vector<StatInfo> &ancoStats) override; |
| 168 | - ErrCode StartAncoMove(int &fd, AncoRestoreResult &ancoRestoreRes) override; | 168 | + ErrCode StartAncoMove(AncoRestoreResult &ancoRestoreRes) override; |
| 169 | ErrCode MigrateFile(const BPathInfo &path, const std::string &bundleName, const std::string &fileName) override; | 169 | ErrCode MigrateFile(const BPathInfo &path, const std::string &bundleName, const std::string &fileName) override; |
| 170 | ErrCode GetApkFileHandle(const std::string &path, const std::string &fileName, int &fd) override; | 170 | ErrCode GetApkFileHandle(const std::string &path, const std::string &fileName, int &fd) override; |
| 171 | // 以下都是非IPC接口 | 171 | // 以下都是非IPC接口 |
| @@ -171,10 +171,10 @@ ErrCode Service::AddAncoMovePaths(const std::vector<std::string> &ancoSourcePath | |||
| 171 | return ret; | 171 | return ret; |
| 172 | } | 172 | } |
| 173 | 173 | ||
| 174 | -ErrCode Service::StartAncoMove(int &fd, AncoRestoreResult &ancoRestoreRes) | 174 | +ErrCode Service::StartAncoMove(AncoRestoreResult &ancoRestoreRes) |
| 175 | { | 175 | { |
| 176 | auto func = [&](IEnhanceService *enhanceService, const std::string &callerName) { | 176 | auto func = [&](IEnhanceService *enhanceService, const std::string &callerName) { |
| 177 | - return enhanceService->StartAncoMove(callerName, fd, ancoRestoreRes); | 177 | + return enhanceService->StartAncoMove(callerName, ancoRestoreRes); |
| 178 | }; | 178 | }; |
| 179 | auto ret = ExecuteEnhanceServiceOperationWithAuth(func); | 179 | auto ret = ExecuteEnhanceServiceOperationWithAuth(func); |
| 180 | if (ret != ERR_OK) { | 180 | if (ret != ERR_OK) { |
| @@ -35,7 +35,7 @@ public: | |||
| 35 | MOCK_METHOD(ErrCode, StartAncoUnPacket, (const std::string &, const std::string &), (override)); | 35 | MOCK_METHOD(ErrCode, StartAncoUnPacket, (const std::string &, const std::string &), (override)); |
| 36 | MOCK_METHOD(ErrCode, AddAncoMovePaths, (const std::string &, const std::vector<std::string> &, | 36 | MOCK_METHOD(ErrCode, AddAncoMovePaths, (const std::string &, const std::vector<std::string> &, |
| 37 | const std::vector<std::string> &, const std::vector<StatInfo> &), (override)); | 37 | const std::vector<std::string> &, const std::vector<StatInfo> &), (override)); |
| 38 | - MOCK_METHOD(ErrCode, StartAncoMove, (const std::string &, int &, AncoRestoreResult &), (override)); | 38 | + MOCK_METHOD(ErrCode, StartAncoMove, (const std::string &, AncoRestoreResult &), (override)); |
| 39 | MOCK_METHOD(int, OpenAncoFileReadOnly, (const std::string &)); | 39 | MOCK_METHOD(int, OpenAncoFileReadOnly, (const std::string &)); |
| 40 | MOCK_METHOD(bool, RemoveAncoFile, (const std::string &)); | 40 | MOCK_METHOD(bool, RemoveAncoFile, (const std::string &)); |
| 41 | MOCK_METHOD(void, RemoveAncoTempDir, (const std::string &)); | 41 | MOCK_METHOD(void, RemoveAncoTempDir, (const std::string &)); |
| @@ -537,7 +537,7 @@ ErrCode Service::AddAncoMovePaths(const std::vector<std::string> &ancoSourcePath | |||
| 537 | return BError(BError::Codes::OK); | 537 | return BError(BError::Codes::OK); |
| 538 | } | 538 | } |
| 539 | 539 | ||
| 540 | -ErrCode Service::StartAncoMove(int &fd, AncoRestoreResult &ancoRestoreRes) | 540 | +ErrCode Service::StartAncoMove(AncoRestoreResult &ancoRestoreRes) |
| 541 | { | 541 | { |
| 542 | ancoRestoreRes.duplicateCount = 0; | 542 | ancoRestoreRes.duplicateCount = 0; |
| 543 | ancoRestoreRes.failedCount = 0; | 543 | ancoRestoreRes.failedCount = 0; |
| @@ -80,6 +80,7 @@ ohos_unittest("backup_ipc_struct_param_test") { | |||
| 80 | external_deps = [ | 80 | external_deps = [ |
| 81 | "hilog:libhilog", | 81 | "hilog:libhilog", |
| 82 | "c_utils:utils", | 82 | "c_utils:utils", |
| 83 | + "ipc:ipc_core", | ||
| 83 | ] | 84 | ] |
| 84 | 85 | ||
| 85 | use_exceptions = true | 86 | use_exceptions = true |
| @@ -60,7 +60,7 @@ public: | |||
| 60 | MOCK_METHOD(ErrCode, StartAncoUnPacket, (const std::string &)); | 60 | MOCK_METHOD(ErrCode, StartAncoUnPacket, (const std::string &)); |
| 61 | MOCK_METHOD(ErrCode, AddAncoMovePaths, (const std::vector<std::string> &, const std::vector<std::string> &, | 61 | MOCK_METHOD(ErrCode, AddAncoMovePaths, (const std::vector<std::string> &, const std::vector<std::string> &, |
| 62 | const std::vector<StatInfo> &)); | 62 | const std::vector<StatInfo> &)); |
| 63 | - MOCK_METHOD(ErrCode, StartAncoMove, (int &, AncoRestoreResult &)); | 63 | + MOCK_METHOD(ErrCode, StartAncoMove, (AncoRestoreResult &)); |
| 64 | 64 | ||
| 65 | int32_t InvokeSendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) | 65 | int32_t InvokeSendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) |
| 66 | { | 66 | { |
| @@ -724,17 +724,16 @@ HWTEST_F(ExtExtensionSubTest, SUB_AncoIncrementalRestoreHelper_StartAncoMove_000 | |||
| 724 | GTEST_LOG_(INFO) << "ExtExtensionSubTest-begin SUB_AncoIncrementalRestoreHelper_StartAncoMove_0000"; | 724 | GTEST_LOG_(INFO) << "ExtExtensionSubTest-begin SUB_AncoIncrementalRestoreHelper_StartAncoMove_0000"; |
| 725 | 725 | ||
| 726 | ServiceClient::serviceProxy_ = nullptr; | 726 | ServiceClient::serviceProxy_ = nullptr; |
| 727 | - UniqueFd fd(-1); | 727 | + auto res = AncoIncrementalRestoreHelper::StartAncoMove(); |
| 728 | - auto res = AncoIncrementalRestoreHelper::StartAncoMove(fd); | ||
| 729 | EXPECT_EQ(res.successCount, 0); | 728 | EXPECT_EQ(res.successCount, 0); |
| 730 | 729 | ||
| 731 | ServiceClient::serviceProxy_ = proxy; | 730 | ServiceClient::serviceProxy_ = proxy; |
| 732 | - EXPECT_CALL(*proxy, StartAncoMove(_, _)).WillOnce(Return(BError(BError::Codes::SDK_INVAL_ARG))); | 731 | + EXPECT_CALL(*proxy, StartAncoMove(_)).WillOnce(Return(BError(BError::Codes::SDK_INVAL_ARG))); |
| 733 | - res = AncoIncrementalRestoreHelper::StartAncoMove(fd); | 732 | + res = AncoIncrementalRestoreHelper::StartAncoMove(); |
| 734 | EXPECT_EQ(res.successCount, 0); | 733 | EXPECT_EQ(res.successCount, 0); |
| 735 | 734 | ||
| 736 | - EXPECT_CALL(*proxy, StartAncoMove(_, _)).WillOnce(Return(BError(BError::Codes::OK))); | 735 | + EXPECT_CALL(*proxy, StartAncoMove(_)).WillOnce(Return(BError(BError::Codes::OK))); |
| 737 | - res = AncoIncrementalRestoreHelper::StartAncoMove(fd); | 736 | + res = AncoIncrementalRestoreHelper::StartAncoMove(); |
| 738 | EXPECT_EQ(res.successCount, 0); | 737 | EXPECT_EQ(res.successCount, 0); |
| 739 | GTEST_LOG_(INFO) << "ExtExtensionSubTest-end SUB_AncoIncrementalRestoreHelper_StartAncoMove_0000"; | 738 | GTEST_LOG_(INFO) << "ExtExtensionSubTest-end SUB_AncoIncrementalRestoreHelper_StartAncoMove_0000"; |
| 740 | } | 739 | } |
| @@ -671,7 +671,7 @@ ErrCode Service::AddAncoMovePaths(const std::vector<std::string> &ancoSourcePath | |||
| 671 | return BService::serviceMock->AddAncoMovePaths(ancoSourcePath, ancoTargetPath, ancoStats); | 671 | return BService::serviceMock->AddAncoMovePaths(ancoSourcePath, ancoTargetPath, ancoStats); |
| 672 | } | 672 | } |
| 673 | 673 | ||
| 674 | -ErrCode Service::StartAncoMove(int &fd, AncoRestoreResult &ancoRestoreRes) | 674 | +ErrCode Service::StartAncoMove(AncoRestoreResult &ancoRestoreRes) |
| 675 | { | 675 | { |
| 676 | return BService::serviceMock->StartAncoMove(ancoRestoreRes); | 676 | return BService::serviceMock->StartAncoMove(ancoRestoreRes); |
| 677 | } | 677 | } |
| @@ -668,17 +668,15 @@ HWTEST_F(ServiceTest, SUB_Service_StartAncoMove_0000, testing::ext::TestSize.Lev | |||
| 668 | retAncoRestoreRes.successCount = 100; | 668 | retAncoRestoreRes.successCount = 100; |
| 669 | retAncoRestoreRes.duplicateCount = 200; | 669 | retAncoRestoreRes.duplicateCount = 200; |
| 670 | retAncoRestoreRes.failedCount = 300; | 670 | retAncoRestoreRes.failedCount = 300; |
| 671 | - int fd = -1; | 671 | + EXPECT_CALL(*mockEnhanceService, StartAncoMove(_, _)) |
| 672 | - EXPECT_CALL(*mockEnhanceService, StartAncoMove(_, _, _)) | 672 | + .WillOnce(DoAll(SetArgReferee<1>(retAncoRestoreRes), Return(BError(BError::Codes::OK)))); |
| 673 | - .WillOnce(DoAll(SetArgReferee<1>(fd), SetArgReferee<2>(retAncoRestoreRes), Return(BError(BError::Codes::OK)))); | ||
| 674 | EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)); | 673 | EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)); |
| 675 | EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP)); | 674 | EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP)); |
| 676 | EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); | 675 | EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); |
| 677 | EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")); | 676 | EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")); |
| 678 | 677 | ||
| 679 | AncoRestoreResult ancoRestoreRes; | 678 | AncoRestoreResult ancoRestoreRes; |
| 680 | - int dbFd = -1; | 679 | + EXPECT_EQ(service->StartAncoMove(ancoRestoreRes), BError(BError::Codes::OK)); |
| 681 | - EXPECT_EQ(service->StartAncoMove(dbFd, ancoRestoreRes), BError(BError::Codes::OK)); | ||
| 682 | EXPECT_EQ(ancoRestoreRes.successCount, retAncoRestoreRes.successCount); | 680 | EXPECT_EQ(ancoRestoreRes.successCount, retAncoRestoreRes.successCount); |
| 683 | EXPECT_EQ(ancoRestoreRes.duplicateCount, retAncoRestoreRes.duplicateCount); | 681 | EXPECT_EQ(ancoRestoreRes.duplicateCount, retAncoRestoreRes.duplicateCount); |
| 684 | EXPECT_EQ(ancoRestoreRes.failedCount, retAncoRestoreRes.failedCount); | 682 | EXPECT_EQ(ancoRestoreRes.failedCount, retAncoRestoreRes.failedCount); |
| @@ -701,18 +699,15 @@ HWTEST_F(ServiceTest, SUB_Service_StartAncoMove_0001, testing::ext::TestSize.Lev | |||
| 701 | retAncoRestoreRes.successCount = 100; | 699 | retAncoRestoreRes.successCount = 100; |
| 702 | retAncoRestoreRes.duplicateCount = 200; | 700 | retAncoRestoreRes.duplicateCount = 200; |
| 703 | retAncoRestoreRes.failedCount = 300; | 701 | retAncoRestoreRes.failedCount = 300; |
| 704 | - int fd = -1; | 702 | + EXPECT_CALL(*mockEnhanceService, StartAncoMove(_, _)) |
| 705 | - EXPECT_CALL(*mockEnhanceService, StartAncoMove(_, _, _)) | 703 | + .WillOnce(DoAll(SetArgReferee<1>(retAncoRestoreRes), Return(BError(BError::Codes::SA_INVAL_ARG)))); |
| 706 | - .WillOnce(DoAll(SetArgReferee<1>(fd), SetArgReferee<2>(retAncoRestoreRes), | ||
| 707 | - Return(BError(BError::Codes::SA_INVAL_ARG)))); | ||
| 708 | EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)); | 704 | EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)); |
| 709 | EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP)); | 705 | EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP)); |
| 710 | EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); | 706 | EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); |
| 711 | EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")); | 707 | EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")); |
| 712 | 708 | ||
| 713 | AncoRestoreResult ancoRestoreRes; | 709 | AncoRestoreResult ancoRestoreRes; |
| 714 | - int dbFd = -1; | 710 | + EXPECT_NE(service->StartAncoMove(ancoRestoreRes), BError(BError::Codes::OK)); |
| 715 | - EXPECT_NE(service->StartAncoMove(dbFd, ancoRestoreRes), BError(BError::Codes::OK)); | ||
| 716 | GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_StartAncoMove_0001"; | 711 | GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_StartAncoMove_0001"; |
| 717 | } | 712 | } |
| 718 | 713 | ||
| @@ -732,8 +727,7 @@ HWTEST_F(ServiceTest, SUB_Service_StartAncoMove_0002, testing::ext::TestSize.Lev | |||
| 732 | EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); | 727 | EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); |
| 733 | 728 | ||
| 734 | AncoRestoreResult ancoRestoreRes; | 729 | AncoRestoreResult ancoRestoreRes; |
| 735 | - int fd = -1; | 730 | + EXPECT_NE(service->StartAncoMove(ancoRestoreRes), BError(BError::Codes::OK)); |
| 736 | - EXPECT_NE(service->StartAncoMove(fd, ancoRestoreRes), BError(BError::Codes::OK)); | ||
| 737 | GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_StartAncoMove_0002"; | 731 | GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_StartAncoMove_0002"; |
| 738 | } | 732 | } |
| 739 | 733 | ||
| @@ -757,8 +751,7 @@ HWTEST_F(ServiceTest, SUB_Service_StartAncoMove_0003, testing::ext::TestSize.Lev | |||
| 757 | EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")); | 751 | EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")); |
| 758 | 752 | ||
| 759 | AncoRestoreResult ancoRestoreRes; | 753 | AncoRestoreResult ancoRestoreRes; |
| 760 | - int fd = -1; | 754 | + EXPECT_EQ(service->StartAncoMove(ancoRestoreRes), BError(BError::Codes::OK)); |
| 761 | - EXPECT_EQ(service->StartAncoMove(fd, ancoRestoreRes), BError(BError::Codes::OK)); | ||
| 762 | EnhanceServiceManager().GetInstance().service_ = backupService; | 755 | EnhanceServiceManager().GetInstance().service_ = backupService; |
| 763 | GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_StartAncoMove_0003"; | 756 | GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_StartAncoMove_0003"; |
| 764 | } | 757 | } |
| @@ -1204,7 +1197,7 @@ HWTEST_F(ServiceTest, SUB_Service_MigrateFilePrecheck_0000, testing::ext::TestSi | |||
| 1204 | g_verifyDataCloneResult = true; | 1197 | g_verifyDataCloneResult = true; |
| 1205 | service->session_ = sptr<SvcSessionManager>(new SvcSessionManager(wptr(service))); | 1198 | service->session_ = sptr<SvcSessionManager>(new SvcSessionManager(wptr(service))); |
| 1206 | EXPECT_CALL(*skeleton, GetCallingTokenID()).WillRepeatedly(Return(0)); | 1199 | EXPECT_CALL(*skeleton, GetCallingTokenID()).WillRepeatedly(Return(0)); |
| 1207 | - EXPECT_CALL(*token, GetTokenType(_)) | 1200 | + EXPECT_CALL(*token, GetTokenType(_)) |
| 1208 | .WillRepeatedly(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE)); | 1201 | .WillRepeatedly(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE)); |
| 1209 | EXPECT_CALL(*token, VerifyAccessToken(_, _)) | 1202 | EXPECT_CALL(*token, VerifyAccessToken(_, _)) |
| 1210 | .WillRepeatedly(Return(Security::AccessToken::PermissionState::PERMISSION_GRANTED)); | 1203 | .WillRepeatedly(Return(Security::AccessToken::PermissionState::PERMISSION_GRANTED)); |
| @@ -1258,7 +1251,7 @@ HWTEST_F(ServiceTest, SUB_Service_MigrateFile_0000, testing::ext::TestSize.Level | |||
| 1258 | EXPECT_EQ(ret, ERR_OK); | 1251 | EXPECT_EQ(ret, ERR_OK); |
| 1259 | 1252 | ||
| 1260 | EXPECT_CALL(*mockEnhanceService, MoveDirectory(_, _)).WillOnce(Return(ERR_OK)); | 1253 | EXPECT_CALL(*mockEnhanceService, MoveDirectory(_, _)).WillOnce(Return(ERR_OK)); |
| 1261 | - EXPECT_CALL(*srProxy, IncrementalRestoreOnMigrateResult(0, _)) | 1254 | + EXPECT_CALL(*srProxy, IncrementalRestoreOnMigrateResult(0, _)) |
| 1262 | .Times(testing::AtLeast(1)).WillRepeatedly(Return(ERR_OK)); | 1255 | .Times(testing::AtLeast(1)).WillRepeatedly(Return(ERR_OK)); |
| 1263 | EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); | 1256 | EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); |
| 1264 | EXPECT_CALL(*svcProxy, GetIncrementalRpFileHandle(_, _)).WillOnce(Return(ERR_OK)); | 1257 | EXPECT_CALL(*svcProxy, GetIncrementalRpFileHandle(_, _)).WillOnce(Return(ERR_OK)); |
| @@ -330,7 +330,7 @@ ErrCode ServiceProxy::AddAncoMovePaths(const std::vector<std::string> &ancoSourc | |||
| 330 | return BError(BError::Codes::OK); | 330 | return BError(BError::Codes::OK); |
| 331 | } | 331 | } |
| 332 | 332 | ||
| 333 | -ErrCode ServiceProxy::StartAncoMove(int &fd, AncoRestoreResult &ancoRestoreRes) | 333 | +ErrCode ServiceProxy::StartAncoMove(AncoRestoreResult &ancoRestoreRes) |
| 334 | { | 334 | { |
| 335 | ancoRestoreRes.duplicateCount = 0; | 335 | ancoRestoreRes.duplicateCount = 0; |
| 336 | ancoRestoreRes.failedCount = 0; | 336 | ancoRestoreRes.failedCount = 0; |
| @@ -93,7 +93,7 @@ public: | |||
| 93 | MOCK_METHOD1(StartAncoUnPacket, ErrCode(const std::string &)); | 93 | MOCK_METHOD1(StartAncoUnPacket, ErrCode(const std::string &)); |
| 94 | MOCK_METHOD3(AddAncoMovePaths, ErrCode(const std::vector<std::string> &, const std::vector<std::string> &, | 94 | MOCK_METHOD3(AddAncoMovePaths, ErrCode(const std::vector<std::string> &, const std::vector<std::string> &, |
| 95 | const std::vector<StatInfo> &)); | 95 | const std::vector<StatInfo> &)); |
| 96 | - MOCK_METHOD2(StartAncoMove, ErrCode(int &, AncoRestoreResult &)); | 96 | + MOCK_METHOD1(StartAncoMove, ErrCode(AncoRestoreResult &)); |
| 97 | MOCK_METHOD3(MigrateFile, ErrCode(const BPathInfo &, const std::string &, const std::string &)); | 97 | MOCK_METHOD3(MigrateFile, ErrCode(const BPathInfo &, const std::string &, const std::string &)); |
| 98 | MOCK_METHOD3(GetApkFileHandle, ErrCode(const std::string &, const std::string &, int &)); | 98 | MOCK_METHOD3(GetApkFileHandle, ErrCode(const std::string &, const std::string &, int &)); |
| 99 | }; | 99 | }; |