From a7435ee29720e66acf88630e5fd0006b85fd3eae Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Tue, 22 Mar 2016 16:22:09 +0900 Subject: [PATCH] add force-remove feature for installer usage(root only): tpk-backend -d {pkgid} --preload --force-remove Change-Id: I705cada8e5d41055371cb97101197d8b44f4074f Signed-off-by: jongmyeongko --- src/common/installer_context.h | 5 +++++ src/common/pkgmgr_interface.cc | 5 +++++ src/common/pkgmgr_interface.h | 7 +++++++ src/common/step/configuration/step_configure.cc | 5 +++++ src/common/step/configuration/step_configure.h | 1 + src/common/step/configuration/step_parse_manifest.cc | 4 ++++ src/common/step/pkgmgr/step_check_blacklist.cc | 3 ++- src/common/step/pkgmgr/step_check_removable.cc | 4 +++- 8 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/common/installer_context.h b/src/common/installer_context.h index 53d2391..30bb474 100644 --- a/src/common/installer_context.h +++ b/src/common/installer_context.h @@ -285,6 +285,11 @@ class InstallerContext { * \brief preload request received from pkgmgr_installer */ Property is_preload_request; + + /** + * \brief force-remove request received from pkgmgr_installer + */ + Property force_remove; }; } // namespace common_installer diff --git a/src/common/pkgmgr_interface.cc b/src/common/pkgmgr_interface.cc index eaa6e3e..925eb53 100644 --- a/src/common/pkgmgr_interface.cc +++ b/src/common/pkgmgr_interface.cc @@ -154,4 +154,9 @@ bool PkgMgrInterface::GetIsPreloadRequest() { true:false; } +bool PkgMgrInterface::GetIsForceRemoval() { + // root only + return (getuid() == 0 && pkgmgr_installer_get_force_removal(pi_) == 1); +} + } // namespace common_installer diff --git a/src/common/pkgmgr_interface.h b/src/common/pkgmgr_interface.h index a5690fb..8da3a5c 100644 --- a/src/common/pkgmgr_interface.h +++ b/src/common/pkgmgr_interface.h @@ -110,6 +110,13 @@ class PkgMgrInterface { bool GetIsPreloadRequest(); /** + * Returns True if the request is for force-remove. Otherwise, return false + * + * \return True if the request is for force-remove. Otherwise, return false + */ + bool GetIsForceRemoval(); + + /** * Get Raw pointer to pkgmgr_installer object * NOTE: It should not be used (PkgMgrInterface can destroy it * diff --git a/src/common/step/configuration/step_configure.cc b/src/common/step/configuration/step_configure.cc index a0c4d28..0f9d415 100644 --- a/src/common/step/configuration/step_configure.cc +++ b/src/common/step/configuration/step_configure.cc @@ -52,6 +52,7 @@ Step::Status StepConfigure::process() { } break; case RequestType::Uninstall: + SetupIsForceRemoval(); context_->pkgid.set(pkgmgr_->GetRequestInfo()); context_->file_path.set(kStrEmpty); break; @@ -199,5 +200,9 @@ void StepConfigure::SetupIsPreloadRequest() { context_->is_preload_request.set(pkgmgr_->GetIsPreloadRequest()); } +void StepConfigure::SetupIsForceRemoval() { + context_->force_remove.set(pkgmgr_->GetIsForceRemoval()); +} + } // namespace configuration } // namespace common_installer diff --git a/src/common/step/configuration/step_configure.h b/src/common/step/configuration/step_configure.h index d7561ef..902fc0d 100644 --- a/src/common/step/configuration/step_configure.h +++ b/src/common/step/configuration/step_configure.h @@ -60,6 +60,7 @@ class StepConfigure : public Step { void SetupRequestType(); void SetupFileCreationMask(); void SetupIsPreloadRequest(); + void SetupIsForceRemoval(); PkgMgrPtr pkgmgr_; diff --git a/src/common/step/configuration/step_parse_manifest.cc b/src/common/step/configuration/step_parse_manifest.cc index 8f119ea..cd98f89 100644 --- a/src/common/step/configuration/step_parse_manifest.cc +++ b/src/common/step/configuration/step_parse_manifest.cc @@ -177,6 +177,10 @@ bool StepParseManifest::FillPackageInfo(manifest_x* manifest) { if (req_type == RequestType::ManifestDirectInstall || req_type == RequestType::ManifestDirectUpdate) manifest->type = strdup("rpm"); + if (!context_->is_preload_request.get()) { + LOG(ERROR) << "Non-preload rpm installation not allowed"; + return false; + } else manifest->type = strdup("tpk"); } else { diff --git a/src/common/step/pkgmgr/step_check_blacklist.cc b/src/common/step/pkgmgr/step_check_blacklist.cc index a0b2ba0..ff033c1 100644 --- a/src/common/step/pkgmgr/step_check_blacklist.cc +++ b/src/common/step/pkgmgr/step_check_blacklist.cc @@ -13,7 +13,8 @@ namespace common_installer { namespace pkgmgr { Step::Status StepCheckBlacklist::process() { - if (context_->installation_mode.get() == InstallationMode::OFFLINE) + if (context_->installation_mode.get() == InstallationMode::OFFLINE || + context_->is_preload_request.get()) return Status::OK; bool result; pkgmgr_client* pc = pkgmgr_client_new(PC_REQUEST); diff --git a/src/common/step/pkgmgr/step_check_removable.cc b/src/common/step/pkgmgr/step_check_removable.cc index d2ff27c..12959b4 100644 --- a/src/common/step/pkgmgr/step_check_removable.cc +++ b/src/common/step/pkgmgr/step_check_removable.cc @@ -13,8 +13,10 @@ namespace common_installer { namespace pkgmgr { Step::Status StepCheckRemovable::process() { - pkgmgrinfo_pkginfo_h handle; + if (context_->force_remove.get()) + return Status::OK; + pkgmgrinfo_pkginfo_h handle; int ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(context_->pkgid.get().c_str(), context_->uid.get(), &handle); if (ret != PMINFO_R_OK) { -- 2.7.4