Implement pkg move 16/72616/15 accepted/tizen/common/20160613.144713 accepted/tizen/ivi/20160610.114459 accepted/tizen/mobile/20160610.114409 accepted/tizen/tv/20160610.114427 accepted/tizen/wearable/20160610.114445 submit/tizen/20160610.015635
authorJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 2 Jun 2016 00:35:40 +0000 (09:35 +0900)
committerjongmyeongko <jongmyeong.ko@samsung.com>
Fri, 10 Jun 2016 00:49:35 +0000 (09:49 +0900)
Releated change : tpk-backend
https://review.tizen.org/gerrit/#/c/72618/

Change-Id: I57bb2b5deffd5294010e8b0a2512f992cb3f466a
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
Signed-off-by: jongmyeongko <jongmyeong.ko@samsung.com>
src/common/CMakeLists.txt
src/common/external_storage.cc
src/common/external_storage.h
src/common/installer_context.h
src/common/pkgmgr_interface.cc
src/common/pkgmgr_interface.h
src/common/pkgmgr_signal.cc
src/common/step/configuration/step_configure.cc
src/common/step/filesystem/step_acquire_external_storage.cc
src/common/step/filesystem/step_move_installed_storage.cc [new file with mode: 0644]
src/common/step/filesystem/step_move_installed_storage.h [new file with mode: 0644]

index 6e7591c..a681e14 100644 (file)
@@ -40,6 +40,7 @@ SET(SRCS
   step/filesystem/step_create_per_user_storage_directories.cc
   step/filesystem/step_create_storage_directories.cc
   step/filesystem/step_delta_patch.cc
+  step/filesystem/step_move_installed_storage.cc
   step/filesystem/step_recover_files.cc
   step/filesystem/step_recover_icons.cc
   step/filesystem/step_recover_manifest.cc
index 3df4a69..233b1ea 100644 (file)
@@ -46,6 +46,28 @@ ExternalStorage::ExternalStorage(RequestType type,
   } else {
     external_dirs_ = kExternalDirsForTpk;
   }
+  move_type_ = -1;
+}
+
+ExternalStorage::ExternalStorage(RequestType type,
+    const std::string& pkgid, const std::string& package_type,
+    const boost::filesystem::path& application_root, uid_t uid,
+    bool is_external_move)
+    : type_(type),
+      pkgid_(pkgid),
+      package_type_(package_type),
+      application_root_(application_root),
+      uid_(uid),
+      handle_(nullptr) {
+  if (package_type_ == kWgtType) {
+    external_dirs_.push_back(kExternalDirForWgt);
+  } else {
+    external_dirs_ = kExternalDirsForTpk;
+  }
+  if (is_external_move)
+    move_type_ = APP2EXT_MOVE_TO_EXT;
+  else
+    move_type_ = APP2EXT_MOVE_TO_PHONE;
 }
 
 ExternalStorage::~ExternalStorage() {
@@ -70,6 +92,9 @@ bool ExternalStorage::Finalize(bool success) {
     ret = handle_->interface.client_usr_post_uninstall(pkgid_.c_str(), uid_);
     break;
   }
+  case RequestType::Move: {
+    break;
+  }
   default:
     assert(false && "Not supported installation mode");
   }
@@ -138,6 +163,31 @@ bool ExternalStorage::Initialize(
     ret = handle_->interface.client_usr_pre_upgrade(pkgid_.c_str(), glist,
                                                     external_size, uid_);
     break;
+  case RequestType::Move:
+    if (move_type_ == -1) {
+      LOG(ERROR) << "Invalid request [" << move_type_ << "]";
+      ret = -1;
+      break;
+    }
+
+    ret = app2ext_usr_get_app_location(pkgid_.c_str(), uid_);
+    if (ret == APP2EXT_ERROR_INVALID_ARGUMENTS) {
+      LOG(ERROR) << "Failed to get installed location [" << pkgid_ << "]";
+      ret = -1;
+      break;
+    }
+
+    if ((ret == APP2EXT_SD_CARD && move_type_ == APP2EXT_MOVE_TO_EXT) ||
+        (ret == APP2EXT_INTERNAL_MEM && move_type_ == APP2EXT_MOVE_TO_PHONE)) {
+      LOG(ERROR) << "Invalid move request [" << move_type_ << "]";
+      ret = -1;
+      break;
+    }
+
+    ret = handle_->interface.client_usr_move(pkgid_.c_str(), glist,
+                                     (app2ext_move_type_t)move_type_,
+                                     uid_);
+    break;
   case RequestType::Uninstall:
     ret = handle_->interface.client_usr_pre_uninstall(pkgid_.c_str(), uid_);
     break;
@@ -164,6 +214,22 @@ bool ExternalStorage::Initialize(
   return ret == 0;
 }
 
+std::unique_ptr<ExternalStorage> ExternalStorage::MoveInstalledStorage(
+    RequestType type, const boost::filesystem::path& application_root,
+    const std::string& pkgid, const std::string& package_type,
+    uid_t uid, bool is_external_move) {
+
+  std::unique_ptr<ExternalStorage> external_storage(
+    new ExternalStorage(type, pkgid, package_type, application_root, uid,
+                       is_external_move));
+  if (!external_storage->Initialize(application_root)) {
+    LOG(WARNING) << "Cannot initialize external storage for move";
+    return nullptr;
+  }
+
+  return external_storage;
+}
+
 std::unique_ptr<ExternalStorage> ExternalStorage::AcquireExternalStorage(
     RequestType type, const boost::filesystem::path& application_root,
     const std::string& pkgid, const std::string& package_type,
index dca7a3d..05d7f4f 100644 (file)
@@ -19,6 +19,11 @@ namespace common_installer {
 
 class ExternalStorage final {
  public:
+  static std::unique_ptr<ExternalStorage> MoveInstalledStorage(
+      RequestType type, const boost::filesystem::path& application_root,
+      const std::string& pkgid, const std::string& package_type,
+      uid_t uid, bool is_external_move);
+
   static std::unique_ptr<ExternalStorage> AcquireExternalStorage(
       RequestType type, const boost::filesystem::path& application_root,
       const std::string& pkgid, const std::string& package_type,
@@ -26,7 +31,12 @@ class ExternalStorage final {
 
   ExternalStorage(RequestType type, const std::string& pkgid,
                   const std::string& package_type,
-                  const boost::filesystem::path& application_root,  uid_t uid);
+                  const boost::filesystem::path& application_root, uid_t uid);
+
+  ExternalStorage(RequestType type, const std::string& pkgid,
+                  const std::string& package_type,
+                  const boost::filesystem::path& application_root, uid_t uid,
+                  bool is_external_move);
   ~ExternalStorage();
 
   bool Commit();
@@ -43,6 +53,7 @@ class ExternalStorage final {
   std::string package_type_;
   boost::filesystem::path application_root_;
   uid_t uid_;
+  int move_type_;
   app2ext_handle* handle_;
   std::vector<std::string> external_dirs_;
 };
index d018a96..2cafbec 100644 (file)
@@ -236,6 +236,11 @@ class InstallerContext {
   Property<bool> is_tep_move;
 
   /**
+  * \brief boolean property that indicates request is external move or not
+  */
+  Property<bool> is_move_to_external;
+
+  /**
    * \brief path to temporary directory when package files are unpacked
    *        before coping them to final destination
    */
index 8b331c7..8c2154f 100644 (file)
@@ -156,6 +156,10 @@ bool PkgMgrInterface::GetIsTepMove() {
   return (pkgmgr_installer_get_tep_move_type(pi_) == 1)?true:false;
 }
 
+bool PkgMgrInterface::GetIsMoveToExternal() {
+  return (pkgmgr_installer_get_move_type(pi_) == 1);
+}
+
 bool PkgMgrInterface::GetIsPreloadRequest() {
   return (pkgmgr_installer_get_is_preload(pi_) == 1)?
       true:(install_mode_ == InstallationMode::OFFLINE)?
index cb91c54..e2dee7d 100644 (file)
@@ -104,6 +104,13 @@ class PkgMgrInterface {
   bool GetIsTepMove();
 
   /**
+  * Returns True if move request is to external. Otherwise, return false
+  *
+  * \return True if move request is to external. Otherwise, return false
+  */
+  bool GetIsMoveToExternal();
+
+  /**
   * Returns True if the request is for preload. Otherwise, return false
   *
   * \return True if the request is for preload. Otherwise, return false
index db8391c..0175f99 100644 (file)
@@ -27,6 +27,7 @@ const std::map<ci::RequestType, const char*> kEventStr = {
   {ci::RequestType::Uninstall, PKGMGR_INSTALLER_UNINSTALL_EVENT_STR},
   {ci::RequestType::Update, PKGMGR_INSTALLER_UPGRADE_EVENT_STR},
   {ci::RequestType::Delta, PKGMGR_INSTALLER_UPGRADE_EVENT_STR},
+  {ci::RequestType::Move, PKGMGR_INSTALLER_MOVE_EVENT_STR},
   {ci::RequestType::MountInstall, PKGMGR_INSTALLER_INSTALL_EVENT_STR},
   {ci::RequestType::MountUpdate, PKGMGR_INSTALLER_UPGRADE_EVENT_STR},
   {ci::RequestType::ManifestDirectInstall, PKGMGR_INSTALLER_INSTALL_EVENT_STR},
index 5acb1fc..39fdf0a 100644 (file)
@@ -72,6 +72,10 @@ Step::Status StepConfigure::process() {
       context_->pkgid.set(kStrEmpty);
       context_->file_path.set(pkgmgr_->GetRequestInfo());
       break;
+    case RequestType::Move:
+      context_->pkgid.set(pkgmgr_->GetRequestInfo());
+      context_->is_move_to_external.set(pkgmgr_->GetIsMoveToExternal());
+      break;
     case RequestType::Recovery:
       context_->file_path.set(pkgmgr_->GetRequestInfo());
       context_->pkgid.set(kStrEmpty);
index 1d2e2aa..71483d2 100644 (file)
@@ -44,7 +44,8 @@ Step::Status StepAcquireExternalStorage::process() {
 
   if (storage == Storage::EXTERNAL ||
       (!strcmp(manifest->installlocation, kPreferExternal) &&
-      storage == Storage::NONE)) {
+      storage == Storage::NONE) ||
+      context_->request_type.get() == RequestType::Move) {
     context_->external_storage =
         ExternalStorage::AcquireExternalStorage(context_->request_type.get(),
             context_->root_application_path.get(),
diff --git a/src/common/step/filesystem/step_move_installed_storage.cc b/src/common/step/filesystem/step_move_installed_storage.cc
new file mode 100644 (file)
index 0000000..2ca8f18
--- /dev/null
@@ -0,0 +1,30 @@
+// Copyright (c) 2016 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/filesystem/step_move_installed_storage.h"
+
+#include "common/external_storage.h"
+
+namespace common_installer {
+namespace filesystem {
+
+Step::Status StepMoveInstalledStorage::process() {
+  context_->external_storage =
+      ExternalStorage::MoveInstalledStorage(context_->request_type.get(),
+          context_->root_application_path.get(),
+          context_->pkgid.get(),
+          context_->pkg_type.get(),
+          context_->uid.get(),
+          context_->is_move_to_external.get());
+  if (!context_->external_storage) {
+    LOG(ERROR) << "Cannot initialize external storage for move";
+    return Status::APP_DIR_ERROR;
+  }
+
+  return Status::OK;
+}
+
+}  // namespace filesystem
+}  // namespace common_installer
+
diff --git a/src/common/step/filesystem/step_move_installed_storage.h b/src/common/step/filesystem/step_move_installed_storage.h
new file mode 100644 (file)
index 0000000..f58c21b
--- /dev/null
@@ -0,0 +1,30 @@
+// Copyright (c) 2016 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_FILESYSTEM_STEP_MOVE_INSTALLED_STORAGE_H_
+#define COMMON_STEP_FILESYSTEM_STEP_MOVE_INSTALLED_STORAGE_H_
+
+#include "common/installer_context.h"
+#include "common/step/step.h"
+
+namespace common_installer {
+namespace filesystem {
+
+class StepMoveInstalledStorage : public Step {
+ public:
+  using Step::Step;
+
+  Status process() override;
+
+  Status clean() override { return Status::OK; }
+  Status undo() override { return Status::OK; }
+  Status precheck() override { return Status::OK; }
+
+  STEP_NAME(MoveInstalledStorage)
+};
+
+}  // namespace filesystem
+}  // namespace common_installer
+
+#endif  // COMMON_STEP_FILESYSTEM_STEP_MOVE_INSTALLED_STORAGE_H_