summaryrefslogtreecommitdiff
path: root/partition_installer.cpp
diff options
context:
space:
mode:
authorYo Chiang <yochiang@google.com>2020-08-24 17:05:00 +0800
committerYo Chiang <yochiang@google.com>2020-08-24 17:14:26 +0800
commit53692200123327c6bf8165bcd98eb9fb01290db6 (patch)
treeb4a36ff130218761a692858f189b37740da7a0de /partition_installer.cpp
parent281584b0709f64b5ee224f70944512753072bb3b (diff)
downloadgsid-53692200123327c6bf8165bcd98eb9fb01290db6.tar.gz
Refactor and rename Finish() to CheckInstallState()
CheckInstallState() returns IGsiService::INSTALL_OK if installation completes successfully, else an error code. Remove the PartitionInstaller::succeeded_ field as checking the value of CheckInstallState() is enough. Bug: 165471299 Test: Observe logcat when DSU installation fails Change-Id: Ie4d798c963c0d537ed5ab35713e1f8faacb89af2
Diffstat (limited to 'partition_installer.cpp')
-rw-r--r--partition_installer.cpp16
1 files changed, 6 insertions, 10 deletions
diff --git a/partition_installer.cpp b/partition_installer.cpp
index 4de181e..d7fab11 100644
--- a/partition_installer.cpp
+++ b/partition_installer.cpp
@@ -56,13 +56,14 @@ PartitionInstaller::PartitionInstaller(GsiService* service, const std::string& i
}
PartitionInstaller::~PartitionInstaller() {
- if (Finish() != IGsiService::INSTALL_OK || !succeeded_) {
+ if (CheckInstallState() != 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();
}
@@ -97,7 +98,6 @@ int PartitionInstaller::StartInstall() {
if (!Format()) {
return IGsiService::INSTALL_ERROR_GENERIC;
}
- succeeded_ = true;
} else {
// Map ${name}_gsi so we can write to it.
system_device_ = OpenPartition(GetBackingFile(name_));
@@ -309,26 +309,22 @@ bool PartitionInstaller::Format() {
return true;
}
-int PartitionInstaller::Finish() {
- if (readOnly_ && gsi_bytes_written_ != size_) {
+int PartitionInstaller::CheckInstallState() {
+ if (readOnly_ && !IsFinishedWriting()) {
// We cannot boot if the image is incomplete.
LOG(ERROR) << "image incomplete; expected " << size_ << " bytes, waiting for "
<< (size_ - gsi_bytes_written_) << " bytes";
return IGsiService::INSTALL_ERROR_GENERIC;
}
- if (system_device_ != nullptr && fsync(system_device_->fd())) {
- PLOG(ERROR) << "fsync failed for " << name_ << "_gsi";
+ if (system_device_ != nullptr && fsync(GetPartitionFd())) {
+ PLOG(ERROR) << "fsync failed for " << GetBackingFile(name_);
return IGsiService::INSTALL_ERROR_GENERIC;
}
- system_device_ = {};
-
// If files moved (are no longer pinned), the metadata file will be invalid.
// This check can be removed once b/133967059 is fixed.
if (!images_->Validate()) {
return IGsiService::INSTALL_ERROR_GENERIC;
}
-
- succeeded_ = true;
return IGsiService::INSTALL_OK;
}