From 12ef9d3b698b9859305799cbf5f23307d708aead Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Thu, 7 Jul 2016 19:19:57 +0900 Subject: [PATCH] Implement pkg enable/disable Related changes [pkgmgr-tool] https://review.tizen.org/gerrit/78916 [slp-pkgmgr] https://review.tizen.org/gerrit/78917 [pkgmgr-server] https://review.tizen.org/gerrit/78918 [tpk-backend] https://review.tizen.org/gerrit/#/c/79070/ Change-Id: Ie0467a66d133cec859108229a4a499ebcf4d6b21 Signed-off-by: Junghyun Yeon --- src/common/CMakeLists.txt | 1 + src/common/pkgmgr_interface.cc | 4 ++ src/common/pkgmgr_registration.cc | 26 ++++++++++ src/common/pkgmgr_registration.h | 26 ++++++++++ src/common/pkgmgr_signal.cc | 2 + src/common/request.h | 4 +- src/common/step/configuration/step_configure.cc | 4 ++ .../step/pkgmgr/step_update_pkg_disable_info.cc | 57 ++++++++++++++++++++++ .../step/pkgmgr/step_update_pkg_disable_info.h | 36 ++++++++++++++ 9 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 src/common/step/pkgmgr/step_update_pkg_disable_info.cc create mode 100644 src/common/step/pkgmgr/step_update_pkg_disable_info.h diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index c64a9b0..d0cfdbb 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -69,6 +69,7 @@ SET(SRCS step/pkgmgr/step_run_parser_plugins.cc step/pkgmgr/step_unregister_app.cc step/pkgmgr/step_update_app.cc + step/pkgmgr/step_update_pkg_disable_info.cc step/rds/step_rds_modify.cc step/rds/step_rds_parse.cc step/recovery/step_open_recovery_file.cc diff --git a/src/common/pkgmgr_interface.cc b/src/common/pkgmgr_interface.cc index 8c2154f..879c959 100644 --- a/src/common/pkgmgr_interface.cc +++ b/src/common/pkgmgr_interface.cc @@ -136,6 +136,10 @@ RequestType PkgMgrInterface::GetRequestType() const { return RequestType::MountInstall; else return RequestType::MountUpdate; + case PKGMGR_REQ_DISABLE_PKG: + return RequestType::DisablePkg; + case PKGMGR_REQ_ENABLE_PKG: + return RequestType::EnablePkg; default: return RequestType::Unknown; } diff --git a/src/common/pkgmgr_registration.cc b/src/common/pkgmgr_registration.cc index 537a670..410fa6f 100644 --- a/src/common/pkgmgr_registration.cc +++ b/src/common/pkgmgr_registration.cc @@ -253,4 +253,30 @@ bool UpdateTepInfoInPkgmgr(const bf::path& tep_path, const std::string& pkgid, return true; } +bool DisablePkgInPkgmgr(const std::string& pkgid, uid_t uid, + RequestMode request_mode) { + int ret = request_mode != RequestMode::GLOBAL ? + pkgmgr_parser_update_pkg_disable_info_in_usr_db(pkgid.c_str(), uid, 1) : + pkgmgr_parser_update_pkg_disable_info_in_db(pkgid.c_str(), 1); + if (ret != 0) { + LOG(ERROR) << "Failed to disable pkg: " << pkgid; + return false; + } + + return true; +} + +bool EnablePkgInPkgmgr(const std::string& pkgid, uid_t uid, + RequestMode request_mode) { + int ret = request_mode != RequestMode::GLOBAL ? + pkgmgr_parser_update_pkg_disable_info_in_usr_db(pkgid.c_str(), uid, 0) : + pkgmgr_parser_update_pkg_disable_info_in_db(pkgid.c_str(), 0); + if (ret != 0) { + LOG(ERROR) << "Failed to enable pkg: " << pkgid; + return false; + } + + return true; +} + } // namespace common_installer diff --git a/src/common/pkgmgr_registration.h b/src/common/pkgmgr_registration.h index 5eb3ba8..70d71b1 100644 --- a/src/common/pkgmgr_registration.h +++ b/src/common/pkgmgr_registration.h @@ -87,6 +87,32 @@ bool UpdateTepInfoInPkgmgr(const boost::filesystem::path& tep_path, uid_t uid, RequestMode request_mode); +/** + * \brief Adapter interface for external PkgMgr module used for updating + * pkg disable info about package within pkgmgr + * + * \param pkgid package pkgid + * \param uid user id + * \param request_mode current request mode + * + * \return true if success + */ +bool DisablePkgInPkgmgr(const std::string& pkgid, uid_t uid, + RequestMode request_mode); + +/** + * \brief Adapter interface for external PkgMgr module used for updating + * pkg enable info about package within pkgmgr + * + * \param pkgid package pkgid + * \param uid user id + * \param request_mode current request mode + * + * \return true if success + */ +bool EnablePkgInPkgmgr(const std::string& pkgid, uid_t uid, + RequestMode request_mode); + } // namespace common_installer #endif // COMMON_PKGMGR_REGISTRATION_H_ diff --git a/src/common/pkgmgr_signal.cc b/src/common/pkgmgr_signal.cc index 96cb01a..9c38de2 100644 --- a/src/common/pkgmgr_signal.cc +++ b/src/common/pkgmgr_signal.cc @@ -32,6 +32,8 @@ const std::map kEventStr = { {ci::RequestType::MountUpdate, PKGMGR_INSTALLER_UPGRADE_EVENT_STR}, {ci::RequestType::ManifestDirectInstall, PKGMGR_INSTALLER_INSTALL_EVENT_STR}, {ci::RequestType::ManifestDirectUpdate, PKGMGR_INSTALLER_UPGRADE_EVENT_STR}, + {ci::RequestType::DisablePkg, PKGMGR_INSTALLER_UNINSTALL_EVENT_STR}, + {ci::RequestType::EnablePkg, PKGMGR_INSTALLER_INSTALL_EVENT_STR}, {ci::RequestType::Unknown, PKGMGR_INSTALLER_UNKNOWN_EVENT_STR} }; diff --git a/src/common/request.h b/src/common/request.h index fc67605..9b29019 100644 --- a/src/common/request.h +++ b/src/common/request.h @@ -25,7 +25,9 @@ enum class RequestType : int { MountInstall, MountUpdate, ManifestDirectInstall, - ManifestDirectUpdate + ManifestDirectUpdate, + DisablePkg, + EnablePkg }; /** Request mode (USER vs GLOBAL) */ diff --git a/src/common/step/configuration/step_configure.cc b/src/common/step/configuration/step_configure.cc index 39fdf0a..25694cc 100644 --- a/src/common/step/configuration/step_configure.cc +++ b/src/common/step/configuration/step_configure.cc @@ -104,6 +104,10 @@ Step::Status StepConfigure::process() { context_->xml_path.set(xml_path); break; } + case RequestType::DisablePkg: + case RequestType::EnablePkg: + context_->pkgid.set(pkgmgr_->GetRequestInfo()); + break; default: LOG(ERROR) << "Only installation, update and uninstallation is now supported"; diff --git a/src/common/step/pkgmgr/step_update_pkg_disable_info.cc b/src/common/step/pkgmgr/step_update_pkg_disable_info.cc new file mode 100644 index 0000000..521ae5c --- /dev/null +++ b/src/common/step/pkgmgr/step_update_pkg_disable_info.cc @@ -0,0 +1,57 @@ +// 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/pkgmgr/step_update_pkg_disable_info.h" +#include "common/pkgmgr_registration.h" + +namespace common_installer { +namespace pkgmgr { + +StepUpdatePkgDisableInfo::StepUpdatePkgDisableInfo( + common_installer::InstallerContext* context, ActionType action_type) + : Step(context), action_type_(action_type) {} + +Step::Status StepUpdatePkgDisableInfo::precheck() { + if (context_->pkgid.get().empty()) { + LOG(ERROR) << "pkgid attribute is empty"; + return Status::PACKAGE_NOT_FOUND; + } + + return Step::Status::OK; +} + +Step::Status StepUpdatePkgDisableInfo::process() { + if (action_type_ == ActionType::Disable) { + if (!DisablePkgInPkgmgr(context_->pkgid.get(), context_->uid.get(), context_->request_mode.get())) { + LOG(ERROR) << "Failed to update pkg info to disable :" << context_->pkgid.get(); + return Status::REGISTER_ERROR; + } + } else { + if (!EnablePkgInPkgmgr(context_->pkgid.get(), context_->uid.get(), context_->request_mode.get())) { + LOG(ERROR) << "Failed to update pkg info to enable :" << context_->pkgid.get(); + return Status::REGISTER_ERROR; + } + } + LOG(DEBUG) << "Successfully set pkg enable/disable info"; + return Status::OK; +} + +Step::Status StepUpdatePkgDisableInfo::undo() { + if (action_type_ == ActionType::Disable) { + if (!EnablePkgInPkgmgr(context_->pkgid.get(), context_->uid.get(), context_->request_mode.get())) { + LOG(ERROR) << "Failed to update pkg info to enable : " << context_->pkgid.get(); + return Status::REGISTER_ERROR; + } + } else { + if (!DisablePkgInPkgmgr(context_->pkgid.get(), context_->uid.get(), context_->request_mode.get())) { + LOG(ERROR) << "Failed to update pkg info to disable : " << context_->pkgid.get(); + return Status::REGISTER_ERROR; + } + } + LOG(DEBUG) << "Successfully undo pkg enable/disable info"; + return Status::OK; +} + +} // namespace pkgmgr +} // namespace common_installer diff --git a/src/common/step/pkgmgr/step_update_pkg_disable_info.h b/src/common/step/pkgmgr/step_update_pkg_disable_info.h new file mode 100644 index 0000000..5e95adc --- /dev/null +++ b/src/common/step/pkgmgr/step_update_pkg_disable_info.h @@ -0,0 +1,36 @@ +// 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_PKGMGR_STEP_UPDATE_PKG_DISABLE_INFO_H_ +#define COMMON_STEP_PKGMGR_STEP_UPDATE_PKG_DISABLE_INFO_H_ + +#include +#include +#include + +namespace common_installer { +namespace pkgmgr { + +class StepUpdatePkgDisableInfo : public common_installer::Step { + public: + using Step::Step; + enum class ActionType { Disable, Enable }; + + explicit StepUpdatePkgDisableInfo(common_installer::InstallerContext* context, + ActionType action_type); + + Step::Status process() override; + Step::Status clean() override { return Status::OK; } + Step::Status undo() override; + Status precheck() override; + + private: + ActionType action_type_; + STEP_NAME(UpdatePkgDisableInfo) +}; + +} // namespace pkgmgr +} // namespace common_installer + +#endif //COMMON_STEP_PKGMGR_STEP_UPDATE_PKG_DISABLE_INFO_H_ -- 2.7.4