Fix crash occured during ReinstallSteps
[platform/core/appfw/app-installers.git] / src / common / step / security / step_update_security.cc
index dfcd499..0903017 100644 (file)
@@ -12,29 +12,45 @@ namespace common_installer {
 namespace security {
 
 Step::Status StepUpdateSecurity::process() {
+  AddRecoveryInfo();
+
   std::string error_message;
-  if (!RegisterSecurityContextForManifest(
-      context_->pkgid.get(), context_->pkg_path.get(), context_->uid.get(),
-      &context_->certificate_info.get(), context_->manifest_data.get(),
-      &error_message)) {
+  if (!RegisterSecurityContextForManifest(context_, &error_message)) {
     if (!error_message.empty()) {
       LOG(ERROR) << "error_message: " << error_message;
       on_error(Status::SECURITY_ERROR, error_message);
     }
     return Status::SECURITY_ERROR;
   }
+  if (context_->request_type.get() != RequestType::ReadonlyUpdateUninstall) {
+    if (!RegisterSecurityContextForPath(
+        context_->pkgid.get(), context_->GetPkgPath(), context_->uid.get(),
+        context_->is_readonly_package.get(), &error_message)) {
+      if (!error_message.empty()) {
+        LOG(ERROR) << "error_message: " << error_message;
+        on_error(Status::SECURITY_ERROR, error_message);
+      }
+      return Status::SECURITY_ERROR;
+    }
+  }
   LOG(DEBUG) << "Security context updated";
   return Status::OK;
 }
 
 Step::Status StepUpdateSecurity::undo() {
   std::string error_message;
-  if (!RegisterSecurityContextForManifest(
-      context_->pkgid.get(), context_->pkg_path.get(), context_->uid.get(),
-      &context_->certificate_info.get(), context_->manifest_data.get(),
-      &error_message)) {
+  if (!RegisterSecurityContextForManifest(context_, &error_message)) {
+    if (!error_message.empty()) {
+      LOG(ERROR) << "error_message: " << error_message;
+    }
+    return Status::SECURITY_ERROR;
+  }
+  if (!RegisterSecurityContextForPath(
+      context_->pkgid.get(), context_->GetPkgPath(), context_->uid.get(),
+      context_->is_readonly_package.get(), &error_message)) {
     if (!error_message.empty()) {
       LOG(ERROR) << "error_message: " << error_message;
+      on_error(Status::SECURITY_ERROR, error_message);
     }
     return Status::SECURITY_ERROR;
   }
@@ -42,5 +58,15 @@ Step::Status StepUpdateSecurity::undo() {
   return Status::OK;
 }
 
+void StepUpdateSecurity::AddRecoveryInfo() {
+  recovery::RecoveryFile* recovery_file =
+      context_->recovery_info.get().recovery_file.get();
+  if (!recovery_file)
+    return;
+
+  recovery_file->set_security_operation_done(true);
+  recovery_file->WriteAndCommitFileContent();
+}
+
 }  // namespace security
 }  // namespace common_installer