diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2020-05-29 01:15:12 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2020-05-29 01:15:12 +0000 |
commit | d68976adeefbd66fce39b3ad9de148a639f61b2c (patch) | |
tree | 83c812e730d0374501047389b9728537dfb80f8b | |
parent | 452c1fb1139a5c203574c9c4787f964380994dae (diff) | |
parent | 7d34ca25a62375e0b7c7638687d651477f78b930 (diff) | |
download | apex-d68976adeefbd66fce39b3ad9de148a639f61b2c.tar.gz |
Snap for 6538275 from 7d34ca25a62375e0b7c7638687d651477f78b930 to rvc-d1-release
Change-Id: I358dbb4db7d90045ec656924d3086042bac388a9
-rw-r--r-- | apexd/aidl/android/apex/IApexService.aidl | 2 | ||||
-rw-r--r-- | apexd/apexd.cpp | 21 | ||||
-rw-r--r-- | apexd/apexservice_test.cpp | 3 |
3 files changed, 16 insertions, 10 deletions
diff --git a/apexd/aidl/android/apex/IApexService.aidl b/apexd/aidl/android/apex/IApexService.aidl index c4405b8b..3626d9ac 100644 --- a/apexd/aidl/android/apex/IApexService.aidl +++ b/apexd/aidl/android/apex/IApexService.aidl @@ -42,7 +42,7 @@ interface IApexService { /** * Restores the snapshot of the CE apex data directory for the given user and - * apex. + * apex. Note the snapshot will be deleted after restoration succeeded. */ void restoreCeData(int user_id, int rollback_id, in @utf8InCpp String apex_name); diff --git a/apexd/apexd.cpp b/apexd/apexd.cpp index 8033a63f..0010c42c 100644 --- a/apexd/apexd.cpp +++ b/apexd/apexd.cpp @@ -1217,6 +1217,7 @@ Result<void> snapshotDataDirectory(const std::string& base_dir, /** * Restores snapshot from base_dir/apexrollback/<rollback id>/<apex name> * to base_dir/apexdata/<apex name>. + * Note the snapshot will be deleted after restoration succeeded. */ Result<void> restoreDataDirectory(const std::string& base_dir, const int rollback_id, @@ -1227,11 +1228,19 @@ Result<void> restoreDataDirectory(const std::string& base_dir, pre_restore ? kPreRestoreSuffix : "", apex_name.c_str()); auto to_path = StringPrintf("%s/%s/%s", base_dir.c_str(), kApexDataSubDir, apex_name.c_str()); - const Result<void> result = ReplaceFiles(from_path, to_path); - if (!result) { + Result<void> result = ReplaceFiles(from_path, to_path); + if (!result.ok()) { + return result; + } + result = RestoreconPath(to_path); + if (!result.ok()) { return result; } - return RestoreconPath(to_path); + result = DeleteDir(from_path); + if (!result.ok()) { + LOG(ERROR) << "Failed to delete the snapshot: " << result.error(); + } + return {}; } void snapshotOrRestoreDeIfNeeded(const std::string& base_dir, @@ -1403,12 +1412,6 @@ void restorePreRestoreSnapshotsIfPresent(const std::string& base_dir, << ": " << result.error(); } } - - Result<void> result = DeleteDir(pre_restore_snapshot_path); - if (!result) { - LOG(ERROR) << "Deletion of pre-restore snapshot failed: " - << result.error(); - } } } diff --git a/apexd/apexservice_test.cpp b/apexd/apexservice_test.cpp index adcc5d62..4c054f10 100644 --- a/apexd/apexservice_test.cpp +++ b/apexd/apexservice_test.cpp @@ -873,6 +873,9 @@ TEST_F(ApexServiceTest, RestoreCeData) { "/data/misc_ce/0/apexdata/apex.apexd_test/oldfile.txt")); ASSERT_FALSE(RegularFileExists( "/data/misc_ce/0/apexdata/apex.apexd_test/newfile.txt")); + // The snapshot should be deleted after restoration. + ASSERT_FALSE( + DirExists("/data/misc_ce/0/apexrollback/123456/apex.apexd_test")); } TEST_F(ApexServiceTest, DestroyDeSnapshots_DeSys) { |