summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMohammad Islam <samiul@google.com>2020-07-15 13:51:15 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-07-15 13:51:15 +0000
commit63721367292156a04254d0a7f96cd8a81905315d (patch)
tree125755eeb30a5b36c5caef49b878b83f66f84c83
parentc4daa3918e94579b558cae88623aa16c8d4eda49 (diff)
parent839a20cff5c898c2755c2c289b7b52a797b38a43 (diff)
downloadplatform_system_apex-63721367292156a04254d0a7f96cd8a81905315d.tar.gz
platform_system_apex-63721367292156a04254d0a7f96cd8a81905315d.tar.bz2
platform_system_apex-63721367292156a04254d0a7f96cd8a81905315d.zip
Merge "Replace HandlePackages with OpenApexFiles to create a linear flow" am: 51aa2b56b1 am: 839a20cff5
Original change: https://android-review.googlesource.com/c/platform/system/apex/+/1312193 Change-Id: Iae4263276a05739c2e3a0e691f5d3a830a07d5cf
-rw-r--r--apexd/apexd.cpp54
1 files changed, 29 insertions, 25 deletions
diff --git a/apexd/apexd.cpp b/apexd/apexd.cpp
index b5e4d97c..695be836 100644
--- a/apexd/apexd.cpp
+++ b/apexd/apexd.cpp
@@ -624,20 +624,23 @@ Result<void> PostinstallPackages(const std::vector<ApexFile>& apexes) {
&StagePostInstall);
}
-template <typename RetType, typename Fn>
-RetType HandlePackages(const std::vector<std::string>& paths, Fn fn) {
- // 1) Open all APEXes.
- std::vector<ApexFile> apex_files;
+// Converts a list of apex file paths into a list of ApexFile objects
+//
+// Returns error when trying to open empty set of inputs.
+Result<std::vector<ApexFile>> OpenApexFiles(
+ const std::vector<std::string>& paths) {
+ if (paths.empty()) {
+ return Errorf("Empty set of inputs");
+ }
+ std::vector<ApexFile> ret;
for (const std::string& path : paths) {
Result<ApexFile> apex_file = ApexFile::Open(path);
if (!apex_file.ok()) {
return apex_file.error();
}
- apex_files.emplace_back(std::move(*apex_file));
+ ret.emplace_back(std::move(*apex_file));
}
-
- // 2) Dispatch.
- return fn(apex_files);
+ return ret;
}
Result<void> ValidateStagingShimApex(const ApexFile& to) {
@@ -694,21 +697,20 @@ Result<void> VerifyPackageInstall(const ApexFile& apex_file) {
template <typename VerifyApexFn>
Result<std::vector<ApexFile>> verifyPackages(
const std::vector<std::string>& paths, const VerifyApexFn& verify_apex_fn) {
- if (paths.empty()) {
- return Errorf("Empty set of inputs");
+ Result<std::vector<ApexFile>> apex_files = OpenApexFiles(paths);
+ if (!apex_files.ok()) {
+ return apex_files.error();
}
+
LOG(DEBUG) << "verifyPackages() for " << Join(paths, ',');
- auto verify_fn = [&](std::vector<ApexFile>& apexes) {
- for (const ApexFile& apex_file : apexes) {
- Result<void> result = verify_apex_fn(apex_file);
- if (!result.ok()) {
- return Result<std::vector<ApexFile>>(result.error());
- }
+ for (const ApexFile& apex_file : *apex_files) {
+ Result<void> result = verify_apex_fn(apex_file);
+ if (!result.ok()) {
+ return result.error();
}
- return Result<std::vector<ApexFile>>(std::move(apexes));
- };
- return HandlePackages<Result<std::vector<ApexFile>>>(paths, verify_fn);
+ }
+ return std::move(*apex_files);
}
Result<ApexFile> verifySessionDir(const int session_id) {
@@ -1656,19 +1658,21 @@ void scanStagedSessionsDirAndStage() {
}
Result<void> preinstallPackages(const std::vector<std::string>& paths) {
- if (paths.empty()) {
- return Errorf("Empty set of inputs");
+ Result<std::vector<ApexFile>> apex_files = OpenApexFiles(paths);
+ if (!apex_files.ok()) {
+ return apex_files.error();
}
LOG(DEBUG) << "preinstallPackages() for " << Join(paths, ',');
- return HandlePackages<Result<void>>(paths, PreinstallPackages);
+ return PreinstallPackages(*apex_files);
}
Result<void> postinstallPackages(const std::vector<std::string>& paths) {
- if (paths.empty()) {
- return Errorf("Empty set of inputs");
+ Result<std::vector<ApexFile>> apex_files = OpenApexFiles(paths);
+ if (!apex_files.ok()) {
+ return apex_files.error();
}
LOG(DEBUG) << "postinstallPackages() for " << Join(paths, ',');
- return HandlePackages<Result<void>>(paths, PostinstallPackages);
+ return PostinstallPackages(*apex_files);
}
namespace {