Fix ReadonlyUpdateInstall's recovery 38/243138/2
authorIlho Kim <ilho159.kim@samsung.com>
Thu, 3 Sep 2020 08:45:30 +0000 (17:45 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Fri, 4 Sep 2020 05:43:42 +0000 (14:43 +0900)
When performing the recovery of ReadonlyUpdateInstall
the xml of package that performed ReadonlyUpdateInstall should be removed

Change-Id: Id2b86b26a8a7b81e2b96dab441d23021c0892157
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/common/step/filesystem/step_recover_manifest.cc
src/common/step/filesystem/step_recover_manifest.h

index 0b2be0b..55d0ec9 100644 (file)
@@ -19,7 +19,7 @@ namespace common_installer {
 namespace filesystem {
 
 Step::Status StepRecoverManifest::RecoveryNew() {
-  if (!SetXmlPaths()) {
+  if (!SetXmlPaths(context_->is_readonly_package.get())) {
     LOG(DEBUG) << "Manifest recovery not needed";
     return Status::OK;
   }
@@ -29,7 +29,7 @@ Step::Status StepRecoverManifest::RecoveryNew() {
 }
 
 Step::Status StepRecoverManifest::RecoveryUpdate() {
-  if (!SetXmlPaths()) {
+  if (!SetXmlPaths(context_->is_readonly_package.get())) {
     LOG(DEBUG) << "Manifest recovery not needed";
     return Status::OK;
   }
@@ -44,8 +44,23 @@ Step::Status StepRecoverManifest::RecoveryUpdate() {
   return Status::OK;
 }
 
+Step::Status StepRecoverManifest::RecoveryReadonlyUpdateInstall() {
+  if (!SetXmlPaths(false)) {
+    LOG(DEBUG) << "Manifest recovery not needed";
+    return Status::OK;
+  }
+  if (bf::exists(context_->xml_path.get())) {
+    if (!Remove(context_->xml_path.get())) {
+      LOG(ERROR) << "Cannot move manifest file to restore its location";
+      return Status::RECOVERY_ERROR;
+    }
+  }
+  LOG(INFO) << "Manifest recovery done";
+  return Status::OK;
+}
+
 Step::Status StepRecoverManifest::Cleanup() {
-  if (!SetXmlPaths()) {
+  if (!SetXmlPaths(context_->is_readonly_package.get())) {
     LOG(DEBUG) << "Manifest recovery not needed";
     return Status::OK;
   }
@@ -59,12 +74,11 @@ Step::Status StepRecoverManifest::Cleanup() {
   return Status::OK;
 }
 
-bool StepRecoverManifest::SetXmlPaths() {
+bool StepRecoverManifest::SetXmlPaths(bool is_readonly_package) {
   if (context_->pkgid.get().empty())
     return false;
   bf::path xml_path =
-      bf::path(getUserManifestPath(context_->uid.get(),
-          context_->is_readonly_package.get()))
+      bf::path(getUserManifestPath(context_->uid.get(), is_readonly_package))
       / context_->pkgid.get();
   xml_path += ".xml";
   context_->xml_path.set(xml_path);
index 9fab414..c7301b4 100644 (file)
@@ -27,10 +27,11 @@ class StepRecoverManifest : public recovery::StepRecovery {
 
   Status RecoveryNew() override;
   Status RecoveryUpdate() override;
+  Status RecoveryReadonlyUpdateInstall() override;
   Status Cleanup() override;
 
  private:
-  bool SetXmlPaths();
+  bool SetXmlPaths(bool is_readonly_package);
 
   STEP_NAME(RecoverManifest)
 };