diff --git a/frameworks/native/backup_ext/include/ext_extension.h b/frameworks/native/backup_ext/include/ext_extension.h index 7315efd2a009550e9fce5531d8d6c374b42cb81e..5a51d6e2c7fe2453322951a7c69e4214f502023d 100644 --- a/frameworks/native/backup_ext/include/ext_extension.h +++ b/frameworks/native/backup_ext/include/ext_extension.h @@ -263,7 +263,7 @@ private: void DeleteBackupIncrementalTars(const string &tarName); void SetClearDataFlag(bool isClearData); std::string GetBundlePath(); - std::vector GetExtManageInfo(); + std::vector GetExtManageInfo(bool isSpecialVersion = false); ErrCode RestoreFilesForSpecialCloneCloud(); void RestoreBigFilesForSpecialCloneCloud(const ExtManageInfo &item); ErrCode RestoreTarForSpecialCloneCloud(const ExtManageInfo &item); diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index f92dbab7c8c4060c65aede57daff9306409fdac4..969046532b18cb7d31d6d218e6ab5db52ea3a4eb 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -150,9 +150,9 @@ static std::set GetIdxFileData(const string &bundleName) return cache.GetExtManage(); } -std::vector BackupExtExtension::GetExtManageInfo() +std::vector BackupExtExtension::GetExtManageInfo(bool isSpecialVersion) { - string indexFileRestorePath = GetIndexFileRestorePath(bundleName_); + string indexFileRestorePath = isSpecialVersion ? INDEX_FILE_RESTORE : GetIndexFileRestorePath(bundleName_); string filePath = BExcepUltils::Canonicalize(indexFileRestorePath); UniqueFd idxFd(open(filePath.data(), O_RDONLY)); if (idxFd < 0) { diff --git a/frameworks/native/backup_ext/src/sub_ext_extension.cpp b/frameworks/native/backup_ext/src/sub_ext_extension.cpp index 71463bde160fab05a6b77f697f6026580b140010..7afcca49258a126614bbfdd3b79b7bee0ab7bb64 100644 --- a/frameworks/native/backup_ext/src/sub_ext_extension.cpp +++ b/frameworks/native/backup_ext/src/sub_ext_extension.cpp @@ -120,7 +120,7 @@ string BackupExtExtension::GetBundlePath() std::map BackupExtExtension::GetIdxFileInfos(bool isSpecialVersion) { string restoreDir = isSpecialVersion ? "" : GetBundlePath(); - auto extManageInfo = GetExtManageInfo(); + auto extManageInfo = GetExtManageInfo(isSpecialVersion); std::map idxFileInfos; for (size_t i = 0; i < extManageInfo.size(); ++i) { std::string realPath = restoreDir + extManageInfo[i].hashName; diff --git a/frameworks/native/backup_ext/src/untar_file.cpp b/frameworks/native/backup_ext/src/untar_file.cpp index ba4baff48ffb49877aeeb0fee697c70f03153702..8ba5e3bf822f15061b0b17e9d1b7cc233261ecd8 100644 --- a/frameworks/native/backup_ext/src/untar_file.cpp +++ b/frameworks/native/backup_ext/src/untar_file.cpp @@ -385,6 +385,7 @@ bool UntarFile::DealFileTag(ErrFileInfo &errFileInfo, errFileInfo[info.fullPath].push_back(DEFAULT_ERR); return false; } + isFilter = true; return true; } info.fullPath = GenRealPath(rootPath_, info.fullPath); diff --git a/tests/unittests/backup_ext/untar_file_test.cpp b/tests/unittests/backup_ext/untar_file_test.cpp index f67ba503d2e56d996fa801bc22cf0c5cd57abc2e..79082c8cdba6b99ff9b5979023ec924d7b0d6cb8 100644 --- a/tests/unittests/backup_ext/untar_file_test.cpp +++ b/tests/unittests/backup_ext/untar_file_test.cpp @@ -487,4 +487,65 @@ HWTEST_F(UntarFileTest, SUB_Untar_File_IncrementalUnPacket_0400, testing::ext::T GTEST_LOG_(INFO) << "UntarFileTest-end SUB_Untar_File_IncrementalUnPacket_0400"; } + +/** + * @tc.number: SUB_Untar_File_IncrementalUnPacket_0500 + * @tc.name: SUB_Untar_File_IncrementalUnPacket_0500 + * @tc.desc: 测试 IncrementalUnPacket 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(UntarFileTest, SUB_Untar_File_IncrementalUnPacket_0500, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "UntarFileTest-begin SUB_Untar_File_IncrementalUnPacket_0500"; + try { + // 预置文件和目录 + TestManager tm("SUB_Untar_File_IncrementalUnPacket_0500"); + string root = tm.GetRootDirCurTest(); + string testDir = root + "/testdir/"; + if (mkdir(testDir.data(), S_IRWXU) && errno != EEXIST) { + GTEST_LOG_(INFO) << " invoked mkdir failure, errno :" << errno; + throw BError(errno); + } + string aFile = testDir + "a.txt"; + string bFile = testDir + "b.txt"; + SaveStringToFile(aFile, "hello"); + SaveStringToFile(bFile, "world"); + // 打 tar + TarMap tarMap {}; + vector smallFiles; + smallFiles.emplace_back(aFile); + smallFiles.emplace_back(bFile); + auto reportCb = [](std::string msg, int err) { + return; + }; + TarFile::GetInstance().Packet(smallFiles, "test", root, tarMap, reportCb); + // 首次恢复 + string tarFile = root + "/test.0.tar"; + string rootPath(root); + unordered_map cloudFiles; + cloudFiles.emplace(make_pair(aFile.substr(1), ReportFileInfo())); // 1: the pos of / + cloudFiles.emplace(make_pair(bFile.substr(1), ReportFileInfo())); // 1: the pos of / + auto result = UntarFile::GetInstance().IncrementalUnPacket(tarFile, rootPath, cloudFiles); + EXPECT_EQ(std::get<1>(result).size(), 2); // 1: First ele, 2: 2 files, aFile and bFile + EXPECT_EQ(std::get<0>(result), 0); + // 增量恢复,aFile 有变化 + cloudFiles.erase(aFile.substr(1)); // 1: the pos of / + result = UntarFile::GetInstance().IncrementalUnPacket(tarFile, rootPath, cloudFiles); + EXPECT_EQ(std::get<0>(result), 0); + EXPECT_EQ(std::get<1>(result).size(), 1); // 1: the first ele, 1: result size -> bFile + // 恢复归一后 clone等其他场景,rp文件没数据 + cloudFiles.erase(bFile.substr(1)); // 1: the pos of / + result = UntarFile::GetInstance().IncrementalUnPacket(tarFile, rootPath, cloudFiles); + EXPECT_EQ(std::get<0>(result), 0); + EXPECT_EQ(std::get<1>(result).size(), 2); // 1: First ele, 2: 2 files, aFile and bFile + ClearCache(); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "UntarFileTest-an exception occurred by UntarFile."; + } + GTEST_LOG_(INFO) << "UntarFileTest-end SUB_Untar_File_IncrementalUnPacket_0500"; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file