summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJW Wang <wangchun@google.com>2020-05-28 01:54:09 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-05-28 01:54:09 +0000
commit7d34ca25a62375e0b7c7638687d651477f78b930 (patch)
tree83c812e730d0374501047389b9728537dfb80f8b
parent6ccf1e16ddc2a96ac87f3b4e649aecbf68c908e7 (diff)
parent72bafdd2f312680b47edd4509248367e99641de2 (diff)
downloadapex-7d34ca25a62375e0b7c7638687d651477f78b930.tar.gz
Merge "Delete snapshots after restore is done successfully (1/n)" into rvc-dev am: 72bafdd2f3
Change-Id: I4af1698902df14810d925844b7e99246e0540972
-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) {