Change clean operations not to return failure 13/223113/7
authorIlho Kim <ilho159.kim@samsung.com>
Thu, 23 Jan 2020 01:38:06 +0000 (10:38 +0900)
committerilho kim <ilho159.kim@samsung.com>
Fri, 14 Feb 2020 05:49:44 +0000 (05:49 +0000)
Change-Id: I1d8f931c39853133252161b433fe5722fae45b55
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/common/step/backup/step_backup_manifest.cc
src/common/step/backup/step_copy_backup.cc
src/common/step/filesystem/step_update_storage_directories.cc
src/common/step/filesystem/step_update_tep.cc
src/common/step/mount/step_mount_install.cc
src/common/step/mount/step_mount_update.cc
src/common/step/mount/step_mount_update.h
src/common/step/pkgmgr/step_remove_manifest.cc
src/common/step/pkgmgr/step_run_parser_plugins.cc
src/common/step/security/step_revoke_security.cc
src/common/step/security/step_signature.cc

index e1f2f38..59c8ef1 100644 (file)
@@ -19,6 +19,7 @@
 
 namespace bf = boost::filesystem;
 namespace bs = boost::system;
+namespace ci = common_installer;
 
 namespace common_installer {
 namespace backup {
@@ -48,13 +49,8 @@ Step::Status StepBackupManifest::process() {
 }
 
 Step::Status StepBackupManifest::clean() {
-  bs::error_code error;
-  bf::remove(context_->backup_xml_path.get(), error);
-  if (error) {
-    LOG(WARNING) << "Cannot remove backup manifest file";
-    return Status::MANIFEST_ERROR;
-  }
-  LOG(DEBUG) << "Manifest backup removed";
+  LOG(DEBUG) << "Remove manifest backup";
+  ci::Remove(context_->backup_xml_path.get());
   return Status::OK;
 }
 
index c5a8352..163ed58 100644 (file)
@@ -101,11 +101,8 @@ Step::Status StepCopyBackup::clean() {
   recovery_file->set_cleanup(true);
   recovery_file->WriteAndCommitFileContent();
 
-  if (!CleanBackupDirectory()) {
-    LOG(DEBUG) << "Cannot remove backup directory";
-    return Status::APP_DIR_ERROR;
-  }
-  LOG(DEBUG) << "Applications files backup directory removed";
+  LOG(DEBUG) << "Remove Applications files backup directory";
+  CleanBackupDirectory();
 
   if (context_->external_storage)
     context_->external_storage->Commit();
@@ -288,13 +285,7 @@ bool StepCopyBackup::NewContent() {
 }
 
 bool StepCopyBackup::CleanBackupDirectory() {
-  if (bf::exists(backup_path_)) {
-    bs::error_code error;
-    bf::remove_all(backup_path_, error);
-    if (error)
-      return false;
-  }
-  return true;
+  return ci::RemoveAll(backup_path_);
 }
 
 bool StepCopyBackup::RollbackApplicationDirectory() {
index e4acb5e..c10685c 100644 (file)
@@ -145,13 +145,10 @@ Step::Status StepUpdateStorageDirectories::clean() {
   if (mode_ == UpdateMode::NONE)
     return Status::OK;
 
-  if (context_->request_mode.get() == RequestMode::GLOBAL) {
-    if (!CleanUpdatePerUserStorageDirectories())
-      return Status::APP_DIR_ERROR;
-  } else {
-    if (!CleanUpdateStorageDirectories())
-      return Status::APP_DIR_ERROR;
-  }
+  if (context_->request_mode.get() == RequestMode::GLOBAL)
+    CleanUpdatePerUserStorageDirectories();
+  else
+    CleanUpdateStorageDirectories();
   return Status::OK;
 }
 
index d81e870..9221fcf 100644 (file)
@@ -78,11 +78,7 @@ Step::Status StepUpdateTep::clean() {
         strcmp(context_->old_manifest_data.get()->tep_name,
                context_->manifest_data.get()->tep_name)) {
       bf::path old_tep = context_->old_manifest_data.get()->tep_name;
-      bs::error_code error;
-      bf::remove(old_tep, error);
-      if (error) {
-        LOG(WARNING) << "Failed to cleanup old tep package from sd card";
-      }
+      Remove(old_tep);
     }
   }
   return Status::OK;
index 0714136..4505fbd 100644 (file)
@@ -68,7 +68,9 @@ Step::Status StepMountInstall::UmountPackagePath() {
 }
 
 Step::Status StepMountInstall::clean() {
-  return UmountPackagePath();
+  UmountPackagePath();
+
+  return Status::OK;
 }
 
 Step::Status StepMountInstall::undo() {
index 76452cf..2850b6b 100644 (file)
@@ -53,29 +53,30 @@ Step::Status StepMountUpdate::process() {
   return Status::OK;
 }
 
-Step::Status StepMountUpdate::clean() {
-  bf::path backup_zip_location =
-      GetBackupPathForZipFile(GetZipPackageLocation(
-          context_->GetPkgPath(), context_->pkgid.get()));
-  bs::error_code error;
-  bf::remove(backup_zip_location, error);
-
+Step::Status StepMountUpdate::UmountPackagePath() {
   bf::path mount_point = GetMountLocation(context_->GetPkgPath());
   TzipInterface tzip_final(mount_point);
   if (!tzip_final.UnmountZip()) {
     LOG(ERROR) << "Failed to unmount zip package after installation";
     return Status::APP_DIR_ERROR;
   }
+
+  return Status::OK;
+}
+
+Step::Status StepMountUpdate::clean() {
+  bf::path backup_zip_location =
+      GetBackupPathForZipFile(GetZipPackageLocation(
+          context_->GetPkgPath(), context_->pkgid.get()));
+  Remove(backup_zip_location);
+
+  UmountPackagePath();
+
   return Status::OK;
 }
 
 Step::Status StepMountUpdate::undo() {
-  bf::path mount_point = GetMountLocation(context_->GetPkgPath());
-  TzipInterface tzip_final(mount_point);
-  if (!tzip_final.UnmountZip()) {
-    LOG(ERROR) << "Failed to unmount zip package after installation";
-    return Status::APP_DIR_ERROR;
-  }
+  UmountPackagePath();
 
   bf::path zip_location = GetZipPackageLocation(
         context_->GetPkgPath(), context_->pkgid.get());
@@ -91,6 +92,8 @@ Step::Status StepMountUpdate::undo() {
     }
 
     // mount previous file for re-registration of trust anchor
+    bf::path mount_point = GetMountLocation(context_->GetPkgPath());
+    TzipInterface tzip_final(mount_point);
     bf::path zip_destination_path =
       GetZipPackageLocation(context_->GetPkgPath(), context_->pkgid.get());
     if (!tzip_final.MountZip(zip_destination_path)) {
index cd02e4d..b77672d 100644 (file)
@@ -35,6 +35,9 @@ class StepMountUpdate : public Step {
   Status undo() override;
   Status precheck() override;
 
+ protected:
+  Status UmountPackagePath();
+
   STEP_NAME(MountUpdate)
 };
 
index 70fb69a..c56feb9 100644 (file)
@@ -33,14 +33,9 @@ common_installer::Step::Status StepRemoveManifest::clean() {
   } else {
     manifest_path = context_->xml_path.get();
   }
-  bs::error_code error;
-  bf::remove(manifest_path, error);
 
-  if (error) {
-    LOG(ERROR) << "Failed to remove xml manifest file";
-    return Status::MANIFEST_ERROR;
-  }
-  LOG(DEBUG) << "Manifest file removed";
+  LOG(DEBUG) << "Remove manifest file";
+  Remove(manifest_path);
   return Status::OK;
 }
 
index a68d464..6aa6e86 100644 (file)
@@ -145,10 +145,10 @@ Step::Status StepRunParserPlugin::undo() {
 }
 
 Step::Status StepRunParserPlugin::clean() {
-  if (!ProcessPlugins(context_->xml_path.get(),
-                      context_->manifest_data.get(),
-                      Plugin::ActionType::Clean))
-    return Status::ERROR;
+  ProcessPlugins(context_->xml_path.get(),
+                 context_->manifest_data.get(),
+                 Plugin::ActionType::Clean);
+
   return Status::OK;
 }
 
index 0868030..87f0492 100644 (file)
@@ -37,9 +37,9 @@ Step::Status StepRevokeSecurity::clean() {
       LOG(ERROR) << "error_message: " << error_message;
       on_error(Status::SECURITY_ERROR, error_message);
     }
-    return Status::SECURITY_ERROR;
+  } else {
+    LOG(DEBUG) << "Security context uninstalled";
   }
-  LOG(DEBUG) << "Security context uninstalled";
   return Status::OK;
 }
 
index ce0f841..39553e4 100644 (file)
@@ -11,6 +11,7 @@
 #include <string>
 
 #include "common/certificate_validation.h"
+#include "common/utils/file_util.h"
 
 namespace bf = boost::filesystem;
 namespace ci = common_installer;
@@ -140,8 +141,7 @@ Step::Status StepSignature::undo() {
 }
 
 Step::Status StepSignature::clean() {
-  if (bf::exists(signature_->GetBackupPath()))
-    bf::remove(signature_->GetBackupPath());
+  Remove(signature_->GetBackupPath());
 
   return Step::Status::OK;
 }