summaryrefslogtreecommitdiff
path: root/apexd/apexservice_test.cpp
diff options
context:
space:
mode:
authorNikita Ioffe <ioffe@google.com>2020-10-05 15:53:16 +0100
committerNikita Ioffe <ioffe@google.com>2021-01-21 21:31:02 +0000
commit66bd61adb95077787c37bf4aa914cb242a52d413 (patch)
treeb83253037c2515255867bf9e24cbbd49191a291f /apexd/apexservice_test.cpp
parent22613b7917e90d3f75cbd107bc49f82895381388 (diff)
Fallback to /data/apex/sessions if /metadata partition is absent
There might be devices that support updatable apex, but don't have /metadata partition. For them we need to fallback to storing sessions on /data/apex/sessions. This change implements this logic by introducing GetSessionsDir static method which will pick first existing directory between /metadata/apex/sessions and /data/apex/sessions. The evaluation will happen only once, all other calls to GetSessionsDir will return the cached value. Additionally, the logic for migrating sessions from /data/apex/sessions to /metadata/apex/sessions is changed a little bit. Now apexd will iterate over entires in /data/apex/sessions, and then recursively copy their content to the corresponding directory under /metadata/apex/sessions, and then delete the entry under /data/apex/sessions. This way a directory created by init (/data/apex/sessions) is kept, which makes it easier to write unit tests for apexd. Logic is implemented as function inside apexd_utils.h for the ease of unit testing. Test: atest ApexTestCases Test: atest apexd_host_tests Test: atest CtsStagedInstallHostTestCases Bug: 169932155 Bug: 176314162 Merged-In: Ifea8840ee5f1e56428d80bbb3b4e5e078176a578 Change-Id: Ia5e31e53edb411a023c8b090b7eb53ae977adc3e (cherry picked from commit 7ffc3f6bd74b0b5567e6425090e9d13b6f5d4172) (cherry picked from commit 69e06a1ddf509e4fc0734e044655d2b876b2bf45)
Diffstat (limited to 'apexd/apexservice_test.cpp')
-rw-r--r--apexd/apexservice_test.cpp39
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");