implement TEP install, update 77/50977/13
authorVBS <jungh.yeon@samsung.com>
Tue, 3 Nov 2015 11:31:08 +0000 (20:31 +0900)
committerVBS <jungh.yeon@samsung.com>
Thu, 12 Nov 2015 00:56:03 +0000 (09:56 +0900)
[app-installer][pkgmgr-info][pkgmgr-server][pkgmgr-tool][slp-pkgmgr]

Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
Change-Id: Iec6ea9df7dccd2545504ca6944e46e34bcb9676b

24 files changed:
packaging/app-installers.spec
src/common/CMakeLists.txt
src/common/installer_context.h
src/common/pkgmgr_interface.cc
src/common/pkgmgr_interface.h
src/common/pkgmgr_registration.cc
src/common/pkgmgr_registration.h
src/common/step/step_backup_icons.cc [changed mode: 0755->0644]
src/common/step/step_configure.cc
src/common/step/step_copy.cc
src/common/step/step_copy_tep.cc [new file with mode: 0644]
src/common/step/step_copy_tep.h [new file with mode: 0644]
src/common/step/step_generate_xml.cc [changed mode: 0755->0644]
src/common/step/step_register_app.cc
src/common/step/step_remove_files.cc [changed mode: 0755->0644]
src/common/step/step_remove_files.h [changed mode: 0755->0644]
src/common/step/step_unregister_app.cc [changed mode: 0755->0644]
src/common/step/step_unregister_app.h [changed mode: 0755->0644]
src/common/step/step_update_tep.cc [new file with mode: 0644]
src/common/step/step_update_tep.h [new file with mode: 0644]
src/common/utils/file_util.cc
src/common/utils/file_util.h
src/tpk/step/step_parse.cc
src/tpk/tpk_installer.cc

index d72e85d..8057c7d 100644 (file)
@@ -39,6 +39,7 @@ BuildRequires:  pkgconfig(capi-appfw-app-manager)
 Requires: ca-certificates-tizen
 Requires: libtzplatform-config
 
+
 %description
 This is a meta package that installs the common application
 installers of Tizen.
@@ -62,7 +63,6 @@ Requires: %{name} = %{version}
 %description tests
 Unit tests for al modules of app-installers
 
-
 %prep
 %setup -q
 
@@ -127,7 +127,7 @@ ln -sf %{_bindir}/pkgdir-tool %{_bindir}/pkgdir_maker
 - RequestMode introduction
 
 * Fri Aug 21 2015 Pawel Sikorski <p.sikorski@samsung.com> 1.6-1
-- Icons generation fix; 
+- Icons generation fix;
 - Privilege translation for backward compatilibity
 
 * Fri Aug 21 2015 Pawel Sikorski <p.sikorski@samsung.com> 1.5-1
index d0d3617..401635f 100644 (file)
@@ -17,6 +17,7 @@ SET(SRCS
   step/step_check_signature.cc
   step/step_configure.cc
   step/step_copy.cc
+  step/step_copy_tep.cc
   step/step_copy_backup.cc
   step/step_copy_storage_directories.cc
   step/step_create_storage_directories.cc
@@ -45,6 +46,7 @@ SET(SRCS
   step/step_unregister_app.cc
   step/step_update_app.cc
   step/step_update_security.cc
+  step/step_update_tep.cc
   utils/file_util.cc
   utils/string_util.cc
 )
index f03906a..6f2cb09 100644 (file)
@@ -245,6 +245,16 @@ class InstallerContext {
   Property<boost::filesystem::path> file_path;
 
   /**
+   * \brief tep file path used for TEP installation process
+   */
+  Property<boost::filesystem::path> tep_path;
+
+  /**
+  * \brief boolean property that indicates tep file should be moved or not
+  */
+  Property<bool> is_tep_move;
+
+  /**
    * \brief path to temporary directory when package files are unpacked
    *        before coping them to final destination
    */
index 7191276..67e72c1 100644 (file)
@@ -69,4 +69,15 @@ const char* PkgMgrInterface::GetRequestInfo() const {
   return pkgmgr_installer_get_request_info(pi_);
 }
 
+boost::filesystem::path PkgMgrInterface::GetTepPath() const {
+  if (pkgmgr_installer_get_tep_path(pi_) == nullptr)
+    return boost::filesystem::path("");
+  else
+    return boost::filesystem::path(pkgmgr_installer_get_tep_path(pi_));
+}
+
+bool PkgMgrInterface::GetIsTepMove() {
+  return (pkgmgr_installer_get_tep_move_type(pi_) == 1)?true:false;
+}
+
 }  // namespace common_installer
index 35ed5a5..ce3ce8c 100644 (file)
@@ -13,6 +13,7 @@
 #include "common/request.h"
 #include "common/utils/macros.h"
 #include "common/utils/logging.h"
+#include <boost/filesystem/path.hpp>
 
 namespace common_installer {
 
@@ -52,6 +53,20 @@ class PkgMgrInterface {
         AppQueryInterface* interface = nullptr);
 
   /**
+  * Returns TEP path passed from pkgmgr_installer
+  *
+  * \return TEP path retrieved from pkgmgr_installer
+  */
+  boost::filesystem::path GetTepPath() const;
+
+  /**
+  * Returns True if TEP file should be moved. Otherwise, return false
+  *
+  * \return True if TEP file should be moved. Otherwise, return false
+  */
+  bool GetIsTepMove();
+
+  /**
    * Get Raw pointer to pkgmgr_installer object
    * NOTE: It should not be used (PkgMgrInterface can destroy it
    *
index 20658e3..6a7c314 100644 (file)
@@ -73,6 +73,36 @@ int PkgmgrForeachPrivilegeCallback(const char* privilege_name,
 
 namespace common_installer {
 
+bool RegisterAppInPkgmgrWithTep(const bf::path& tep_path,
+                         const bf::path& xml_path,
+                         const std::string & pkgid,
+                         const CertificateInfo & cert_info,
+                         uid_t uid,
+                         RequestMode request_mode) {
+  int ret = request_mode != RequestMode::GLOBAL ?
+      pkgmgr_parser_parse_usr_manifest_for_installation_withtep(
+          xml_path.c_str(), tep_path.c_str(),
+          uid, const_cast<char* const*>(kAppinstTags)) :
+      pkgmgr_parser_parse_manifest_for_installation_withtep(
+          xml_path.c_str(), tep_path.c_str(),
+          const_cast<char* const*>(kAppinstTags));
+
+  if (ret) {
+    LOG(ERROR) << "Failed to register package: " << xml_path << ", "
+        "error code=" << ret;
+    return false;
+  }
+
+  if (!!cert_info.author_certificate.get()) {
+    if (!RegisterAuthorCertificate(cert_info, pkgid, uid)) {
+      LOG(ERROR) << "Failed to register author certificate";
+      return false;
+    }
+  }
+
+  return true;
+}
+
 bool RegisterAppInPkgmgr(const bf::path& xml_path,
                          const std::string& pkgid,
                          const CertificateInfo& cert_info,
@@ -99,6 +129,22 @@ bool RegisterAppInPkgmgr(const bf::path& xml_path,
   return true;
 }
 
+bool UpdateTepInfoInPkgmgr(const bf::path& tep_path, const std::string& pkgid,
+                        uid_t uid, RequestMode request_mode) {
+  int ret = request_mode != RequestMode::GLOBAL ?
+        pkgmgr_parser_usr_update_tep(
+            pkgid.c_str(), tep_path.string().c_str(), uid) :
+        pkgmgr_parser_update_tep(
+            pkgid.c_str(), tep_path.string().c_str());
+
+  if (ret != 0) {
+    LOG(ERROR) << "Failed to upgrade tep info: " << pkgid;
+    return false;
+  }
+
+  return true;
+}
+
 bool UpgradeAppInPkgmgr(const bf::path& xml_path, const std::string& pkgid,
                         const CertificateInfo& cert_info, uid_t uid,
                         RequestMode request_mode) {
index 02f3436..937763d 100644 (file)
@@ -33,6 +33,13 @@ bool RegisterAppInPkgmgr(const boost::filesystem::path& xml_path,
                          uid_t uid,
                          RequestMode request_mode);
 
+bool RegisterAppInPkgmgrWithTep(const boost::filesystem::path& tep_path,
+                         const boost::filesystem::path& xml_path,
+                         const std::string& pkgid,
+                         const CertificateInfo& cert_info,
+                         uid_t uid,
+                         RequestMode request_mode);
+
 /**
  * \brief Adapter interface for external PkgMgr module used for upgrading
  *        package within pkgmgr
@@ -52,6 +59,22 @@ bool UpgradeAppInPkgmgr(const boost::filesystem::path& xml_path,
                         RequestMode request_mode);
 
 /**
+ * \brief Adapter interface for external PkgMgr module used for updating
+ *        tep info about package within pkgmgr
+ *
+ * \param tep_path path of tep file
+ * \param pkgid package pkgid
+ * \param uid user id
+ * \param request_mode current request mode
+ *
+ * \return true if success
+ */
+bool UpdateTepInfoInPkgmgr(const boost::filesystem::path& tep_path,
+                           const std::string& pkgid,
+                           uid_t uid,
+                           RequestMode request_mode);
+
+/**
  * \brief Adapter interface for external PkgMgr module used for deregistering
  *        package into pkgmgr
  *
old mode 100755 (executable)
new mode 100644 (file)
index c128065..49f4916 100644 (file)
@@ -30,10 +30,18 @@ Step::Status StepConfigure::process() {
     case RequestType::Install:
       context_->file_path.set(pkgmgr_->GetRequestInfo());
       context_->pkgid.set(kStrEmpty);
+      if (!pkgmgr_->GetTepPath().empty()) {
+        context_->tep_path.set(pkgmgr_->GetTepPath());
+        context_->is_tep_move.set(pkgmgr_->GetIsTepMove());
+      }
       break;
     case RequestType::Update:
       context_->file_path.set(pkgmgr_->GetRequestInfo());
       context_->pkgid.set(kStrEmpty);
+      if (!pkgmgr_->GetTepPath().empty()) {
+        context_->tep_path.set(pkgmgr_->GetTepPath());
+        context_->is_tep_move.set(pkgmgr_->GetIsTepMove());
+      }
       break;
     case RequestType::Uninstall:
       context_->pkgid.set(pkgmgr_->GetRequestInfo());
index d690546..5b09a55 100644 (file)
@@ -73,7 +73,6 @@ Step::Status StepCopy::process() {
     LOG(ERROR) << "Cannot move widget directory to install path";
     return Status::ERROR;
   }
-
   LOG(INFO) << "Successfully move: " << context_->unpacked_dir_path.get()
             << " to: " << install_path << " directory";
   return Status::OK;
diff --git a/src/common/step/step_copy_tep.cc b/src/common/step/step_copy_tep.cc
new file mode 100644 (file)
index 0000000..cfd5c08
--- /dev/null
@@ -0,0 +1,76 @@
+/* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "common/step/step_copy_tep.h"
+
+#include <cassert>
+#include <cstring>
+#include <string>
+
+#include "common/utils/file_util.h"
+
+namespace common_installer {
+namespace filesystem {
+
+namespace bf = boost::filesystem;
+namespace bs = boost::system;
+
+Step::Status StepCopyTep::precheck() {
+  if (context_->root_application_path.get().empty()) {
+    LOG(ERROR) << "root_application_path attribute is empty";
+    return Step::Status::INVALID_VALUE;
+  }
+
+  if (!boost::filesystem::exists(context_->root_application_path.get())) {
+    LOG(ERROR) << "root_application_path ("
+               << context_->root_application_path.get()
+               << ") path does not exist";
+    return Step::Status::INVALID_VALUE;
+  }
+
+  if (context_->pkgid.get().empty()) {
+    LOG(ERROR) << "pkgid attribute is empty";
+    return Step::Status::INVALID_VALUE;
+  }
+
+  return Step::Status::OK;
+}
+
+Step::Status StepCopyTep::process() {
+
+  if (context_->tep_path.get().empty())
+    return Step::Status::OK;
+
+  context_->pkg_path.set(
+    context_->root_application_path.get() / context_->pkgid.get());
+
+  bf::path tep_path = context_->pkg_path.get() / "res" / context_->tep_path.get().filename();
+  bs::error_code error;
+
+  if (context_->is_tep_move.get()) {
+    if (!MoveFile(context_->tep_path.get(), tep_path)) {
+      LOG(ERROR) << "Cannnot move TEP file into install path";
+      return Step::Status::ERROR;
+    }
+  } else {
+    if (!CopyFile(context_->tep_path.get(), tep_path)) {
+      LOG(ERROR) << "Cannot copy TEP file [" << context_->tep_path.get() <<
+          "] into install path [" << tep_path << "]";
+      return Step::Status::ERROR;
+    }
+  }
+  context_->tep_path.set(tep_path);
+
+  return Step::Status::OK;
+}
+
+Step::Status StepCopyTep::undo() {
+  if (bf::exists(context_->tep_path.get()))
+    bf::remove_all(context_->tep_path.get());
+  return Status::OK;
+}
+
+}  // namespace filesystem
+}  // namespace common_installer
diff --git a/src/common/step/step_copy_tep.h b/src/common/step/step_copy_tep.h
new file mode 100644 (file)
index 0000000..ceead18
--- /dev/null
@@ -0,0 +1,61 @@
+/* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_STEP_STEP_COPY_TEP_H_
+#define COMMON_STEP_STEP_COPY_TEP_H_
+
+#include "common/installer_context.h"
+
+#include "common/step/step.h"
+#include "common/utils/logging.h"
+
+namespace common_installer {
+namespace filesystem {
+
+/**
+ * \brief step responsible for moving/copying TEP files from designated path to
+ *        final installed package destination during INSTALLATION/UPDATE.
+ *        Used by WGT and TPK
+ */
+class StepCopyTep : public Step {
+ public:
+  using Step::Step;
+
+  /**
+   * \brief main logic of moving/copying files
+   *
+   * \return Status::OK if success, Status::ERROR otherwise
+   */
+  Status process() override;
+
+  /**
+   * \brief empty method
+   *
+   * \return Status::OK
+   */
+  Status clean() override { return Status::OK; }
+
+  /**
+   * \brief removes files from final package destination
+   *
+   * \return Status::OK if success, Status::ERROR otherwise
+   */
+  Status undo() override;
+
+  /**
+   * \brief checks if necessary paths/data are provided
+   *
+   * \return Status::OK if success, Status::ERROR otherwise
+   */
+  Status precheck() override;
+
+  SCOPE_LOG_TAG(CopyTEP)
+
+};
+
+}  // namespace filesystem
+}  // namespace common_installer
+
+#endif  // COMMON_STEP_STEP_TEPCOPY_H_
old mode 100755 (executable)
new mode 100644 (file)
index 483b7ea..0b13603 100644 (file)
@@ -31,11 +31,12 @@ Step::Status StepRegisterApplication::precheck() {
 }
 
 Step::Status StepRegisterApplication::process() {
-  if (!RegisterAppInPkgmgr(context_->xml_path.get(),
-                           context_->pkgid.get(),
-                           context_->certificate_info.get(),
-                           context_->uid.get(),
-                           context_->request_mode.get())) {
+  if (!RegisterAppInPkgmgrWithTep(context_->tep_path.get(),
+                                  context_->xml_path.get(),
+                                  context_->pkgid.get(),
+                                  context_->certificate_info.get(),
+                                  context_->uid.get(),
+                                  context_->request_mode.get())) {
     LOG(ERROR) << "Failed to register the app";
     return Step::Status::ERROR;
   }
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
diff --git a/src/common/step/step_update_tep.cc b/src/common/step/step_update_tep.cc
new file mode 100644 (file)
index 0000000..3089bd3
--- /dev/null
@@ -0,0 +1,48 @@
+// 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_update_tep.h"
+
+#include <pkgmgr-info.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <boost/filesystem.hpp>
+#include <vcore/Certificate.h>
+
+#include <cassert>
+#include <cstdio>
+#include <cstring>
+#include <string>
+
+#include "common/pkgmgr_registration.h"
+#include "common/utils/file_util.h"
+
+namespace bf = boost::filesystem;
+
+namespace common_installer {
+namespace pkgmgr {
+
+Step::Status StepUpdateTep::process() {
+  if (context_->tep_path.get().empty())
+    return Status::OK;
+
+  if (!UpdateTepInfoInPkgmgr(context_->tep_path.get(),
+                          context_->pkgid.get(),
+                          context_->uid.get(),
+                          context_->request_mode.get())) {
+    LOG(ERROR) << "Cannot update tep info for application";
+    return Status::ERROR;
+  }
+
+  LOG(INFO) << "Successfully update the tep info for application";
+  return Status::OK;
+}
+
+Step::Status StepUpdateTep::undo() {
+  return Status::OK;
+}
+
+}  // namespace pkgmgr
+}  // namespace common_installer
diff --git a/src/common/step/step_update_tep.h b/src/common/step/step_update_tep.h
new file mode 100644 (file)
index 0000000..adf19eb
--- /dev/null
@@ -0,0 +1,30 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_STEP_STEP_UPDATE_TEP_H_
+#define COMMON_STEP_STEP_UPDATE_TEP_H_
+
+#include "common/installer_context.h"
+#include "common/step/step.h"
+#include "common/utils/logging.h"
+
+namespace common_installer {
+namespace pkgmgr {
+
+class StepUpdateTep : public Step {
+ public:
+  using Step::Step;
+
+  Status process() override;
+  Status clean() override { return Status::OK; }
+  Status undo() override;
+  Status precheck() override { return Status::OK; };
+
+  SCOPE_LOG_TAG(UpdateTep)
+};
+
+}  // namespace pkgmgr
+}  // namespace common_installer
+
+#endif  // COMMON_STEP_STEP_UPDATE_TEP_H_
index 2567944..2674003 100644 (file)
@@ -159,6 +159,17 @@ bool CopyDir(const bf::path& src, const bf::path& dst) {
   return true;
 }
 
+bool CopyFile(const bf::path& src, const bf::path& dst) {
+  bs::error_code error;
+
+  bf::copy_file(src, dst, bf::copy_option::overwrite_if_exists, error);
+  if (error) {
+    LOG(WARNING) << "copy file " << src << " due to error [" << error << "]";
+    return false;
+  }
+  return true;
+}
+
 bool MoveDir(const bf::path& src, const bf::path& dst) {
   if (bf::exists(dst))
     return false;
@@ -185,14 +196,18 @@ bool MoveFile(const bf::path& src, const bf::path& dst) {
   bs::error_code error;
   bf::rename(src, dst, error);
   if (error) {
-    LOG(WARNING) << "Cannot move file: " << src << ". Will copy/remove...";
+    LOG(WARNING) << "Cannot move file: " << src <<
+        ". Will copy/remove... with error [" << error << "]";
     bf::copy_file(src, dst, bf::copy_option::overwrite_if_exists, error);
     if (error) {
+      LOG(WARNING) << "Cannot copy file " << src <<
+          " due to error [" << error << "]";
       return false;
     }
     bf::remove_all(src, error);
     if (error) {
-      LOG(ERROR) << "Cannot remove old file when coping: " << src;
+      LOG(ERROR) << "Cannot remove old file when coping: " << src <<
+          "with error [" << error << "]";
     }
   }
   return true;
index f1ab81b..c1fb6c2 100644 (file)
@@ -14,6 +14,9 @@ bool CreateDir(const boost::filesystem::path& path);
 bool CopyDir(const boost::filesystem::path& src,
              const boost::filesystem::path& dst);
 
+bool CopyFile(const boost::filesystem::path& src,
+             const boost::filesystem::path& dst);
+
 bool MoveDir(const boost::filesystem::path& src,
              const boost::filesystem::path& dst);
 
index cec786c..32cb161 100644 (file)
@@ -399,12 +399,16 @@ common_installer::Step::Status StepParse::process() {
 
   manifest_x* manifest =
       static_cast<manifest_x*>(calloc(1, sizeof(manifest_x)));
+
   if (!FillManifestX(const_cast<manifest_x*>(manifest))) {
     LOG(ERROR) << "[Parse] Storing manifest_x failed. "
                <<  parser_->GetErrorMessage();
     return common_installer::Step::Status::ERROR;
   }
 
+  if (!context_->tep_path.get().empty())
+    manifest->tep_name = context_->tep_path.get().c_str();
+
   // Copy data from ManifestData to InstallerContext
   std::shared_ptr<const PackageInfo> info =
       std::static_pointer_cast<const PackageInfo>(
index 2172f1b..feee133 100644 (file)
@@ -7,6 +7,7 @@
 #include "common/step/step_create_icons.h"
 #include "common/step/step_create_storage_directories.h"
 #include "common/step/step_copy.h"
+#include "common/step/step_copy_tep.h"
 #include "common/step/step_copy_backup.h"
 #include "common/step/step_check_old_certificate.h"
 #include "common/step/step_fail.h"
@@ -35,6 +36,7 @@
 #include "common/step/step_unzip.h"
 #include "common/step/step_update_app.h"
 #include "common/step/step_update_security.h"
+#include "common/step/step_update_tep.h"
 #include "common/utils/logging.h"
 #include "tpk/step/step_create_symbolic_link.h"
 #include "tpk/step/step_parse.h"
@@ -89,6 +91,7 @@ void TpkInstaller::InstallSteps() {
   AddStep<ci::security::StepPrivilegeCompatibility>();
   AddStep<ci::security::StepRollbackInstallationSecurity>();
   AddStep<ci::filesystem::StepCopy>();
+  AddStep<ci::filesystem::StepCopyTep>();
   AddStep<ci::filesystem::StepCreateStorageDirectories>();
   AddStep<tpk::filesystem::StepCreateSymbolicLink>();
   AddStep<ci::filesystem::StepCreateIcons>();
@@ -109,6 +112,7 @@ void TpkInstaller::UpdateSteps() {
   AddStep<ci::backup::StepBackupManifest>();
   AddStep<ci::backup::StepBackupIcons>();
   AddStep<ci::backup::StepCopyBackup>();
+  AddStep<ci::filesystem::StepCopyTep>();
   AddStep<ci::filesystem::StepCreateStorageDirectories>();
   // TODO(t.iwanek): handle coping storage directories
   AddStep<tpk::filesystem::StepCreateSymbolicLink>();
@@ -116,6 +120,9 @@ void TpkInstaller::UpdateSteps() {
   AddStep<ci::security::StepUpdateSecurity>();
   AddStep<ci::pkgmgr::StepGenerateXml>();
   AddStep<ci::pkgmgr::StepUpdateApplication>();
+  /* TODO(jungh.yeon): this temporary step will be removed
+  * when secondary parsing procedure has removed*/
+  AddStep<ci::pkgmgr::StepUpdateTep>();
 }
 
 void TpkInstaller::UninstallSteps() {