diff options
author | Yo Chiang <yochiang@google.com> | 2020-08-24 17:21:10 +0800 |
---|---|---|
committer | Yo Chiang <yochiang@google.com> | 2020-08-24 17:21:10 +0800 |
commit | f194dcec2e4508ecd7055b087e611e14e074885a (patch) | |
tree | 4c08971f2be2b2a1321bff8dbcd56173137c555c /partition_installer.cpp | |
parent | 53692200123327c6bf8165bcd98eb9fb01290db6 (diff) | |
download | gsid-f194dcec2e4508ecd7055b087e611e14e074885a.tar.gz |
Refactor ~PartitionInstaller() and add FinishInstall()
Distill the error checking and resource management logic in
~PartitionInstaller() and PostInstallCleanup() into a public
method FinishInstall().
FinishInstall() does the opposite of StartInstall(). It checks the
installation result, release device handles and cleans up any failed
installation files. Then it returns an error code indicating the
installation status.
Bug: 165471299
Test: Observe logcat when DSU installation fails
Change-Id: Iee004bc29dc875c8cf656e11fe8fd259e3003992
Diffstat (limited to 'partition_installer.cpp')
-rw-r--r-- | partition_installer.cpp | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/partition_installer.cpp b/partition_installer.cpp index d7fab11..35ac884 100644 --- a/partition_installer.cpp +++ b/partition_installer.cpp @@ -56,35 +56,32 @@ PartitionInstaller::PartitionInstaller(GsiService* service, const std::string& i } PartitionInstaller::~PartitionInstaller() { - if (CheckInstallState() != IGsiService::INSTALL_OK) { + if (FinishInstall() != IGsiService::INSTALL_OK) { LOG(ERROR) << "Installation failed: install_dir=" << install_dir_ << ", dsu_slot=" << active_dsu_ << ", partition_name=" << name_; - // Close open handles before we remove files. - system_device_ = nullptr; - PostInstallCleanup(images_.get()); } - system_device_ = nullptr; if (IsAshmemMapped()) { UnmapAshmem(); } } -void PartitionInstaller::PostInstallCleanup() { - auto manager = ImageManager::Open(MetadataDir(active_dsu_), install_dir_); - if (!manager) { - LOG(ERROR) << "Could not open image manager"; - return; +int PartitionInstaller::FinishInstall() { + if (finished_) { + return finished_status_; } - return PostInstallCleanup(manager.get()); -} - -void PartitionInstaller::PostInstallCleanup(ImageManager* manager) { - std::string file = GetBackingFile(name_); - if (manager->IsImageMapped(file)) { - LOG(ERROR) << "unmap " << file; - manager->UnmapImageDevice(file); + finished_ = true; + finished_status_ = CheckInstallState(); + system_device_ = nullptr; + if (finished_status_ != IGsiService::INSTALL_OK) { + auto file = GetBackingFile(name_); + LOG(ERROR) << "Installation failed, clean up: " << file; + if (images_->IsImageMapped(file)) { + LOG(ERROR) << "unmap " << file; + images_->UnmapImageDevice(file); + } + images_->DeleteBackingImage(file); } - manager->DeleteBackingImage(file); + return finished_status_; } int PartitionInstaller::StartInstall() { |