summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJW Wang <wangchun@google.com>2020-05-28 01:40:19 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-05-28 01:40:19 +0000
commit72bafdd2f312680b47edd4509248367e99641de2 (patch)
tree83c812e730d0374501047389b9728537dfb80f8b
parent881eaef9474267028c5578db551f6d98efabb007 (diff)
parent3c6c290235473117c26c9bd6f42a5010f8af30a8 (diff)
downloadplatform_system_apex-72bafdd2f312680b47edd4509248367e99641de2.tar.gz
platform_system_apex-72bafdd2f312680b47edd4509248367e99641de2.tar.bz2
platform_system_apex-72bafdd2f312680b47edd4509248367e99641de2.zip
Merge "Delete snapshots after restore is done successfully (1/n)" into rvc-dev
-rw-r--r--apexd/aidl/android/apex/IApexService.aidl2
-rw-r--r--apexd/apexd.cpp21
-rw-r--r--apexd/apexservice_test.cpp3
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) {