From 53979b243a6c7071609c8ef6561675ecd92404f0 Mon Sep 17 00:00:00 2001 From: VBS Date: Tue, 3 Nov 2015 20:31:08 +0900 Subject: [PATCH] implement TEP install, update [app-installer][pkgmgr-info][pkgmgr-server][pkgmgr-tool][slp-pkgmgr] Signed-off-by: Junghyun Yeon Change-Id: Iec6ea9df7dccd2545504ca6944e46e34bcb9676b --- packaging/app-installers.spec | 4 +- src/common/CMakeLists.txt | 2 + src/common/installer_context.h | 10 +++++ src/common/pkgmgr_interface.cc | 11 +++++ src/common/pkgmgr_interface.h | 15 +++++++ src/common/pkgmgr_registration.cc | 46 ++++++++++++++++++++ src/common/pkgmgr_registration.h | 23 ++++++++++ src/common/step/step_backup_icons.cc | 0 src/common/step/step_configure.cc | 8 ++++ src/common/step/step_copy.cc | 1 - src/common/step/step_copy_tep.cc | 76 ++++++++++++++++++++++++++++++++++ src/common/step/step_copy_tep.h | 61 +++++++++++++++++++++++++++ src/common/step/step_generate_xml.cc | 0 src/common/step/step_register_app.cc | 11 ++--- src/common/step/step_remove_files.cc | 0 src/common/step/step_remove_files.h | 0 src/common/step/step_unregister_app.cc | 0 src/common/step/step_unregister_app.h | 0 src/common/step/step_update_tep.cc | 48 +++++++++++++++++++++ src/common/step/step_update_tep.h | 30 ++++++++++++++ src/common/utils/file_util.cc | 19 ++++++++- src/common/utils/file_util.h | 3 ++ src/tpk/step/step_parse.cc | 4 ++ src/tpk/tpk_installer.cc | 7 ++++ 24 files changed, 369 insertions(+), 10 deletions(-) mode change 100755 => 100644 src/common/step/step_backup_icons.cc create mode 100644 src/common/step/step_copy_tep.cc create mode 100644 src/common/step/step_copy_tep.h mode change 100755 => 100644 src/common/step/step_generate_xml.cc mode change 100755 => 100644 src/common/step/step_remove_files.cc mode change 100755 => 100644 src/common/step/step_remove_files.h mode change 100755 => 100644 src/common/step/step_unregister_app.cc mode change 100755 => 100644 src/common/step/step_unregister_app.h create mode 100644 src/common/step/step_update_tep.cc create mode 100644 src/common/step/step_update_tep.h diff --git a/packaging/app-installers.spec b/packaging/app-installers.spec index d72e85d..8057c7d 100644 --- a/packaging/app-installers.spec +++ b/packaging/app-installers.spec @@ -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 1.6-1 -- Icons generation fix; +- Icons generation fix; - Privilege translation for backward compatilibity * Fri Aug 21 2015 Pawel Sikorski 1.5-1 diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index d0d3617..401635f 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -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 ) diff --git a/src/common/installer_context.h b/src/common/installer_context.h index f03906a..6f2cb09 100644 --- a/src/common/installer_context.h +++ b/src/common/installer_context.h @@ -245,6 +245,16 @@ class InstallerContext { Property file_path; /** + * \brief tep file path used for TEP installation process + */ + Property tep_path; + + /** + * \brief boolean property that indicates tep file should be moved or not + */ + Property is_tep_move; + + /** * \brief path to temporary directory when package files are unpacked * before coping them to final destination */ diff --git a/src/common/pkgmgr_interface.cc b/src/common/pkgmgr_interface.cc index 7191276..67e72c1 100644 --- a/src/common/pkgmgr_interface.cc +++ b/src/common/pkgmgr_interface.cc @@ -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 diff --git a/src/common/pkgmgr_interface.h b/src/common/pkgmgr_interface.h index 35ed5a5..ce3ce8c 100644 --- a/src/common/pkgmgr_interface.h +++ b/src/common/pkgmgr_interface.h @@ -13,6 +13,7 @@ #include "common/request.h" #include "common/utils/macros.h" #include "common/utils/logging.h" +#include 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 * diff --git a/src/common/pkgmgr_registration.cc b/src/common/pkgmgr_registration.cc index 20658e3..6a7c314 100644 --- a/src/common/pkgmgr_registration.cc +++ b/src/common/pkgmgr_registration.cc @@ -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(kAppinstTags)) : + pkgmgr_parser_parse_manifest_for_installation_withtep( + xml_path.c_str(), tep_path.c_str(), + const_cast(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) { diff --git a/src/common/pkgmgr_registration.h b/src/common/pkgmgr_registration.h index 02f3436..937763d 100644 --- a/src/common/pkgmgr_registration.h +++ b/src/common/pkgmgr_registration.h @@ -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 * diff --git a/src/common/step/step_backup_icons.cc b/src/common/step/step_backup_icons.cc old mode 100755 new mode 100644 diff --git a/src/common/step/step_configure.cc b/src/common/step/step_configure.cc index c128065..49f4916 100644 --- a/src/common/step/step_configure.cc +++ b/src/common/step/step_configure.cc @@ -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()); diff --git a/src/common/step/step_copy.cc b/src/common/step/step_copy.cc index d690546..5b09a55 100644 --- a/src/common/step/step_copy.cc +++ b/src/common/step/step_copy.cc @@ -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 index 0000000..cfd5c08 --- /dev/null +++ b/src/common/step/step_copy_tep.cc @@ -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 +#include +#include + +#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 index 0000000..ceead18 --- /dev/null +++ b/src/common/step/step_copy_tep.h @@ -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_ diff --git a/src/common/step/step_generate_xml.cc b/src/common/step/step_generate_xml.cc old mode 100755 new mode 100644 diff --git a/src/common/step/step_register_app.cc b/src/common/step/step_register_app.cc index 483b7ea..0b13603 100644 --- a/src/common/step/step_register_app.cc +++ b/src/common/step/step_register_app.cc @@ -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; } diff --git a/src/common/step/step_remove_files.cc b/src/common/step/step_remove_files.cc old mode 100755 new mode 100644 diff --git a/src/common/step/step_remove_files.h b/src/common/step/step_remove_files.h old mode 100755 new mode 100644 diff --git a/src/common/step/step_unregister_app.cc b/src/common/step/step_unregister_app.cc old mode 100755 new mode 100644 diff --git a/src/common/step/step_unregister_app.h b/src/common/step/step_unregister_app.h old mode 100755 new mode 100644 diff --git a/src/common/step/step_update_tep.cc b/src/common/step/step_update_tep.cc new file mode 100644 index 0000000..3089bd3 --- /dev/null +++ b/src/common/step/step_update_tep.cc @@ -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 +#include +#include + +#include +#include + +#include +#include +#include +#include + +#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 index 0000000..adf19eb --- /dev/null +++ b/src/common/step/step_update_tep.h @@ -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_ diff --git a/src/common/utils/file_util.cc b/src/common/utils/file_util.cc index 2567944..2674003 100644 --- a/src/common/utils/file_util.cc +++ b/src/common/utils/file_util.cc @@ -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; diff --git a/src/common/utils/file_util.h b/src/common/utils/file_util.h index f1ab81b..c1fb6c2 100644 --- a/src/common/utils/file_util.h +++ b/src/common/utils/file_util.h @@ -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); diff --git a/src/tpk/step/step_parse.cc b/src/tpk/step/step_parse.cc index cec786c..32cb161 100644 --- a/src/tpk/step/step_parse.cc +++ b/src/tpk/step/step_parse.cc @@ -399,12 +399,16 @@ common_installer::Step::Status StepParse::process() { manifest_x* manifest = static_cast(calloc(1, sizeof(manifest_x))); + if (!FillManifestX(const_cast(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 info = std::static_pointer_cast( diff --git a/src/tpk/tpk_installer.cc b/src/tpk/tpk_installer.cc index 2172f1b..feee133 100644 --- a/src/tpk/tpk_installer.cc +++ b/src/tpk/tpk_installer.cc @@ -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(); AddStep(); AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -109,6 +112,7 @@ void TpkInstaller::UpdateSteps() { AddStep(); AddStep(); AddStep(); + AddStep(); AddStep(); // TODO(t.iwanek): handle coping storage directories AddStep(); @@ -116,6 +120,9 @@ void TpkInstaller::UpdateSteps() { AddStep(); AddStep(); AddStep(); + /* TODO(jungh.yeon): this temporary step will be removed + * when secondary parsing procedure has removed*/ + AddStep(); } void TpkInstaller::UninstallSteps() { -- 2.7.4