Fix StepUpdateTep's undo
[platform/core/appfw/app-installers.git] / src / common / step / filesystem / step_update_tep.cc
index 1b6f211..41b5117 100644 (file)
@@ -11,7 +11,7 @@
 #include <cstring>
 #include <string>
 
-#include "common/backup_paths.h"
+#include "common/utils/paths.h"
 #include "common/pkgmgr_registration.h"
 #include "common/utils/file_util.h"
 
@@ -38,11 +38,12 @@ Step::Status StepUpdateTep::process() {
   // preserve old tep path if no new tep is supplied
   if (context_->tep_path.get().empty() &&
       context_->old_manifest_data.get()->tep_name) {
+    if (context_->manifest_data.get()->tep_name)
+      free(context_->manifest_data.get()->tep_name);
     context_->manifest_data.get()->tep_name =
         strdup(context_->old_manifest_data.get()->tep_name);
 
-    // TODO(t.iwanek): some factoring in more inteligent way would be great for
-    // this. Tep doesn't need to be copied in mount update as this mode is not
+    // Tep doesn't need to be copied in mount update as this mode is not
     // creating new package directory so tep is in place.
     if (context_->request_type.get() == RequestType::MountUpdate)
       return Status::OK;
@@ -52,7 +53,7 @@ Step::Status StepUpdateTep::process() {
       bf::path new_path = context_->manifest_data.get()->tep_name;
       bf::path backup_path =
           GetInternalTepPath(
-              GetBackupPathForPackagePath(context_->pkg_path.get()));
+              GetBackupPathForPackagePath(context_->GetPkgPath()));
       backup_path /= new_path.filename();
       if (!bf::exists(new_path.parent_path())) {
         bs::error_code error;
@@ -77,21 +78,16 @@ 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;
 }
 
 Step::Status StepUpdateTep::undo() {
-  bs::error_code error;
-  if (bf::exists(context_->tep_path.get())) {
-    bf::remove_all(context_->tep_path.get(), error);
-  }
+  const bf::path& remove_path = context_->tep_path.get();
+  RemoveAll(context_->old_manifest_data.get()->tep_name ?
+      remove_path : remove_path.parent_path());
   return Status::OK;
 }