Minor improvements for force-uninstall step 07/58907/5
authorArkadiusz Szulakiewicz <a.szulakiewi@partner.samsung.com>
Thu, 4 Feb 2016 16:34:27 +0000 (17:34 +0100)
committerArkadiusz Szulakiewicz <a.szulakiewi@partner.samsung.com>
Wed, 10 Feb 2016 13:20:12 +0000 (14:20 +0100)
Change-Id: If2fe882812653272f2b5724e5a37e2f01a914214

src/common/step/step_remove_files.cc
src/common/step/step_remove_files.h
src/common/step/step_remove_icons.cc
src/common/step/step_remove_icons.h

index 30dc7cf..d44bd85 100644 (file)
@@ -4,17 +4,15 @@
 
 #include "common/step/step_remove_files.h"
 
+#include <boost/filesystem/operations.hpp>
 #include <boost/system/error_code.hpp>
 
-#include "common/backup_paths.h"
-#include "common/utils/file_util.h"
+namespace bs = boost::system;
+namespace bf = boost::filesystem;
 
 namespace common_installer {
 namespace filesystem {
 
-namespace bs = boost::system;
-namespace bf = boost::filesystem;
-
 Step::Status StepRemoveFiles::precheck() {
   if (!context_->manifest_data.get()) {
     LOG(ERROR) << "manifest_data attribute is empty";
@@ -35,31 +33,15 @@ Step::Status StepRemoveFiles::precheck() {
 }
 
 Step::Status StepRemoveFiles::process() {
-  bf::path backup_path = GetBackupPathForPackagePath(context_->pkg_path.get());
-  if (!MoveDir(context_->pkg_path.get(), backup_path)) {
-    LOG(ERROR) << "Cannot remove widget files from its location";
-  }
-  LOG(DEBUG) << "Removed directory: " << context_->pkg_path.get();
-  return Status::OK;
-}
-
-Step::Status StepRemoveFiles::clean() {
   bs::error_code error;
-  bf::path backup_path = GetBackupPathForPackagePath(context_->pkg_path.get());
-  bf::remove_all(backup_path, error);
-  return Status::OK;
-}
+  bf::path pkg_path(context_->pkg_path.get());
+  bf::remove_all(pkg_path, error);
 
-Step::Status StepRemoveFiles::undo() {
-  bf::path backup_path = GetBackupPathForPackagePath(context_->pkg_path.get());
-  if (bf::exists(backup_path)) {
-    LOG(DEBUG) << "Restoring directory: " << context_->pkg_path.get();
-    if (!MoveDir(backup_path, context_->pkg_path.get())) {
-      LOG(ERROR) << "Cannot restore widget files";
-      return Status::APP_DIR_ERROR;
-    }
+  if (error) {
+    LOG(ERROR) << "Can't remove directory:" << context_->pkg_path.get().c_str();
+  } else {
+    LOG(DEBUG) << "Removed directory: " << context_->pkg_path.get();
   }
-
   return Status::OK;
 }
 
index 0b6a671..a2e9cf8 100644 (file)
@@ -19,8 +19,8 @@ class StepRemoveFiles : public Step {
   using Step::Step;
 
   Status process() override;
-  Status clean() override;
-  Status undo() override;
+  Status clean() override { return Status::OK; }
+  Status undo() override  { return Status::OK; }
   Status precheck() override;
 
   SCOPE_LOG_TAG(Remove)
index de3304b..11720b8 100644 (file)
@@ -4,22 +4,21 @@
 
 #include "common/step/step_remove_icons.h"
 
+#include <boost/filesystem/operations.hpp>
 #include <boost/system/error_code.hpp>
 #include <pkgmgr-info.h>
 
 #include <cstring>
 #include <string>
 
-#include "common/backup_paths.h"
-#include "common/utils/file_util.h"
 #include "common/utils/glist_range.h"
 
-namespace common_installer {
-namespace filesystem {
-
 namespace bs = boost::system;
 namespace bf = boost::filesystem;
 
+namespace common_installer {
+namespace filesystem {
+
 Step::Status StepRemoveIcons::precheck() {
   if (!context_->manifest_data.get()) {
     LOG(ERROR) << "manifest_data attribute is empty";
@@ -34,14 +33,17 @@ Step::Status StepRemoveIcons::process() {
       iter != bf::directory_iterator(); ++iter) {
     if (!bf::is_regular_file(iter->path()))
       continue;
+    bs::error_code error;
     for (application_x* app :
         GListRange<application_x*>(
            context_->manifest_data.get()->application)) {
       if (app->icon) {
         std::string filename = iter->path().filename().string();
         if (filename.find(app->appid) == 0) {
-          bf::path icon_backup = GetBackupPathForIconFile(iter->path());
-          backups_.emplace_back(iter->path(), icon_backup);
+          bf::remove(iter->path(), error);
+          if (error) {
+            LOG(WARNING) << "Failed to remove: " << filename;
+          }
         }
       }
     }
@@ -49,33 +51,5 @@ Step::Status StepRemoveIcons::process() {
   return Status::OK;
 }
 
-Step::Status StepRemoveIcons::clean() {
-  bs::error_code error;
-  if (!backups_.empty()) {
-    LOG(DEBUG) << "Clean up icons files...";
-    for (auto& pair : backups_) {
-      bf::remove(pair.first, error);
-      if (error) {
-        LOG(WARNING) << "Failed to remove: " << pair.first;
-      }
-    }
-  }
-  return Status::OK;
-}
-
-Step::Status StepRemoveIcons::undo() {
-  Step::Status ret = Status::OK;
-  if (!backups_.empty()) {
-    LOG(DEBUG) << "Restoring icons files...";
-    for (auto& pair : backups_) {
-      if (!MoveFile(pair.first, pair.second)) {
-        LOG(ERROR) << "Failed to restore: " << pair.second;
-        // We need to try to restore all icons anyway...
-        ret = Status::ICON_ERROR;
-      }
-    }
-  }
-  return ret;
-}
 }  // namespace filesystem
 }  // namespace common_installer
index 1782044..1d259bd 100644 (file)
@@ -23,14 +23,10 @@ class StepRemoveIcons : public Step {
   using Step::Step;
 
   Status process() override;
-  Status clean() override;
-  Status undo() override;
+  Status clean() override { return Status::OK; }
+  Status undo() override { return Status::OK; }
   Status precheck() override;
 
- private:
-  std::vector<std::pair<boost::filesystem::path, boost::filesystem::path>>
-      backups_;
-
   SCOPE_LOG_TAG(RemoveIcons)
 };