Add RequestType::Clear 45/58245/4
authorTomasz Iwanek <t.iwanek@samsung.com>
Thu, 28 Jan 2016 12:50:42 +0000 (13:50 +0100)
committerjongmyeong ko <jongmyeong.ko@samsung.com>
Wed, 3 Feb 2016 01:24:55 +0000 (17:24 -0800)
Add single step that will be run for wgt and tpk backend to
clear data/ directory of package in pkgmgr clear request.

Requires:
 - https://review.tizen.org/gerrit/58243,
 - https://review.tizen.org/gerrit/58244.

Change-Id: I273cbde462588b43584e4c5aa49d3f590eb73715

src/common/CMakeLists.txt
src/common/pkgmgr_interface.cc
src/common/pkgmgr_signal.cc
src/common/request.h
src/common/step/step_clear_data.cc [new file with mode: 0644]
src/common/step/step_clear_data.h [new file with mode: 0644]
src/common/step/step_configure.cc

index e83acd8..b81b621 100644 (file)
@@ -18,6 +18,7 @@ SET(SRCS
   step/step_check_blacklist.cc
   step/step_check_old_certificate.cc
   step/step_check_signature.cc
+  step/step_clear_data.cc
   step/step_configure.cc
   step/step_copy.cc
   step/step_copy_tep.cc
index 594eaac..ea7a2bc 100644 (file)
@@ -95,6 +95,8 @@ RequestType PkgMgrInterface::GetRequestType() const {
       return RequestType::Uninstall;
     case PKGMGR_REQ_REINSTALL:
       return RequestType::Reinstall;
+    case PKGMGR_REQ_CLEAR:
+      return RequestType::Clear;
     case PKGMGR_REQ_RECOVER:
       return RequestType::Recovery;
     case PKGMGR_REQ_MANIFEST_DIRECT_INSTALL:
index b850f70..9e00bf1 100644 (file)
@@ -23,6 +23,7 @@ const std::map<ci::RequestType, const char*> kEventStr = {
   {ci::RequestType::Install, PKGMGR_INSTALLER_INSTALL_EVENT_STR},
   {ci::RequestType::Recovery, PKGMGR_INSTALLER_INSTALL_EVENT_STR},
   {ci::RequestType::Reinstall, PKGMGR_INSTALLER_INSTALL_EVENT_STR},
+  {ci::RequestType::Clear, PKGMGR_INSTALLER_CLEAR_EVENT_STR},
   {ci::RequestType::Uninstall, PKGMGR_INSTALLER_UNINSTALL_EVENT_STR},
   {ci::RequestType::Update, PKGMGR_INSTALLER_UPGRADE_EVENT_STR},
   {ci::RequestType::Delta, PKGMGR_INSTALLER_UPGRADE_EVENT_STR},
index a475223..a5df38e 100644 (file)
@@ -14,6 +14,7 @@ enum class RequestType : int {
   Update,
   Uninstall,
   Reinstall,
+  Clear,
   Delta,
   Recovery,
   ManifestDirectInstall,
diff --git a/src/common/step/step_clear_data.cc b/src/common/step/step_clear_data.cc
new file mode 100644 (file)
index 0000000..e0007c2
--- /dev/null
@@ -0,0 +1,51 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#include "common/step/step_clear_data.h"
+
+#include <boost/filesystem/operations.hpp>
+#include <boost/filesystem/path.hpp>
+#include <boost/system/error_code.hpp>
+
+namespace bf = boost::filesystem;
+namespace bs = boost::system;
+
+namespace {
+
+const char kDataDirectory[] = "data";
+
+}  // namespace
+
+namespace common_installer {
+namespace filesystem {
+
+Step::Status StepClearData::precheck() {
+  if (context_->pkgid.get().empty()) {
+    LOG(ERROR) << "Pkgid is not set";
+    return Status::INVALID_VALUE;
+  }
+  return Status::OK;
+}
+
+Step::Status StepClearData::process() {
+  Status status = Status::OK;
+  context_->pkg_path.set(
+      context_->root_application_path.get() / context_->pkgid.get());
+  bf::path data_directory = context_->pkg_path.get() / kDataDirectory;
+  for (auto iter = bf::directory_iterator(data_directory);
+      iter != bf::directory_iterator(); ++iter) {
+    bs::error_code error;
+    bf::remove_all(iter->path(), error);
+    if (error) {
+      LOG(ERROR) << "Failed to remove: " << iter->path();
+      status = Status::APP_DIR_ERROR;
+    }
+  }
+  LOG(DEBUG) << "Removing files from " << data_directory << " finished";
+  return status;
+}
+
+}  // namespace filesystem
+}  // namespace common_installer
+
diff --git a/src/common/step/step_clear_data.h b/src/common/step/step_clear_data.h
new file mode 100644 (file)
index 0000000..5e5d12d
--- /dev/null
@@ -0,0 +1,37 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_STEP_STEP_CLEAR_DATA_H_
+#define COMMON_STEP_STEP_CLEAR_DATA_H_
+
+#include <manifest_parser/utils/logging.h>
+
+#include <string>
+
+#include "common/installer_context.h"
+#include "common/step/step.h"
+
+namespace common_installer {
+namespace filesystem {
+
+/**
+ * \brief Step responsible removing data/ directory in pkgmgr clear request
+ *        Used by WGT and TPK backend
+ */
+class StepClearData : public Step {
+ public:
+  using Step::Step;
+
+  Status process() override;
+  Status undo() override { return Status::OK; }
+  Status clean() override { return Status::OK; }
+  Status precheck() override;
+
+  SCOPE_LOG_TAG(ClearData)
+};
+
+}  // namespace filesystem
+}  // namespace common_installer
+
+#endif  // COMMON_STEP_STEP_CLEAR_DATA_H_
index dad9627..25f113f 100644 (file)
@@ -62,6 +62,9 @@ Step::Status StepConfigure::process() {
       context_->pkgid.set(kStrEmpty);
       context_->file_path.set(kStrEmpty);
       break;
+    case RequestType::Clear:
+      context_->pkgid.set(pkgmgr_->GetRequestInfo());
+      break;
     case RequestType::Delta:
       context_->unpacked_dir_path.set(kStrEmpty);
       context_->pkgid.set(kStrEmpty);