diff options
Diffstat (limited to 'apexd/apexservice_test.cpp')
-rw-r--r-- | apexd/apexservice_test.cpp | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/apexd/apexservice_test.cpp b/apexd/apexservice_test.cpp index 4c054f1..024cf50 100644 --- a/apexd/apexservice_test.cpp +++ b/apexd/apexservice_test.cpp @@ -94,6 +94,26 @@ using MountedApexData = MountedApexDatabase::MountedApexData; namespace fs = std::filesystem; +static void CleanDir(const std::string& dir) { + if (access(dir.c_str(), F_OK) != 0 && errno == ENOENT) { + LOG(WARNING) << dir << " does not exist"; + return; + } + auto status = WalkDir(dir, [](const fs::directory_entry& p) { + std::error_code ec; + fs::file_status status = p.status(ec); + ASSERT_FALSE(ec) << "Failed to stat " << p.path() << " : " << ec.message(); + if (fs::is_directory(status)) { + fs::remove_all(p.path(), ec); + } else { + fs::remove(p.path(), ec); + } + ASSERT_FALSE(ec) << "Failed to delete " << p.path() << " : " + << ec.message(); + }); + ASSERT_TRUE(IsOk(status)); +} + class ApexServiceTest : public ::testing::Test { public: ApexServiceTest() { @@ -447,21 +467,10 @@ class ApexServiceTest : public ::testing::Test { private: void CleanUp() { - auto status = WalkDir(kApexDataDir, [](const fs::directory_entry& p) { - std::error_code ec; - fs::file_status status = p.status(ec); - ASSERT_FALSE(ec) << "Failed to stat " << p.path() << " : " - << ec.message(); - if (fs::is_directory(status)) { - fs::remove_all(p.path(), ec); - } else { - fs::remove(p.path(), ec); - } - ASSERT_FALSE(ec) << "Failed to delete " << p.path() << " : " - << ec.message(); - }); - fs::remove_all(kApexSessionsDir); - ASSERT_TRUE(IsOk(status)); + CleanDir(kActiveApexPackagesDataDir); + CleanDir(kApexBackupDir); + CleanDir(kApexHashTreeDir); + CleanDir(ApexSession::GetSessionsDir()); DeleteIfExists("/data/misc_ce/0/apexdata/apex.apexd_test"); DeleteIfExists("/data/misc_ce/0/apexrollback/123456"); |