From 08c58a1984d90ac93c25f51ac6a566ab08ca441f Mon Sep 17 00:00:00 2001 From: Damian Pietruchowski Date: Mon, 12 Jun 2017 16:01:32 +0200 Subject: [PATCH] AppQueryInterface logic export IsPkgInstalled() and GetPkgId() have the same implementation for wgt-backend and tpk-backend, so only GetPkgIdFromPath() should be overrided in each backend. Submit together: - https://review.tizen.org/gerrit/#/c/133520/ - https://review.tizen.org/gerrit/#/c/133518/ Change-Id: I40b61fbea37838ccd372b964fe3cf54eb5f5f5a6 Signed-off-by: Damian Pietruchowski --- src/wgt/wgt_app_query_interface.cc | 62 +++++++++++++------------------------- src/wgt/wgt_app_query_interface.h | 19 +++--------- 2 files changed, 25 insertions(+), 56 deletions(-) diff --git a/src/wgt/wgt_app_query_interface.cc b/src/wgt/wgt_app_query_interface.cc index 7b2eee4..908cd6b 100644 --- a/src/wgt/wgt_app_query_interface.cc +++ b/src/wgt/wgt_app_query_interface.cc @@ -37,20 +37,26 @@ namespace { const char kHybridConfigLocation[] = "res/wgt/config.xml"; const char kTizenManifestLocation[] = "tizen-manifest.xml"; -std::string GetPkgIdFromPath(const std::string& path) { - if (!bf::exists(path)) - return {}; - bf::path tmp_path = common_installer::GenerateTmpDir("/tmp"); - bs::error_code code; - bf::create_directories(tmp_path, code); - if (code) - return {}; - if (!common_installer::ExtractToTmpDir(path.c_str(), tmp_path, - "config.xml")) { - ci::RemoveAll(tmp_path); +std::string ReadPkgidFromRecovery(const std::string& recovery_path) { + std::unique_ptr recovery_file = + ci::recovery::RecoveryFile::OpenRecoveryFileForPath(recovery_path); + recovery_file->Detach(); + return recovery_file->pkgid(); +} + +} // namespace + +namespace wgt { + +std::string WgtAppQueryInterface::GetManifestFileName() const { + return "config.xml"; +} + +std::string WgtAppQueryInterface::GetPkgIdFromPath( + const std::string& path) const { + bf::path tmp_path = ExtractManifest(path); + if (tmp_path.empty()) return {}; - } - bf::path config_path = tmp_path / "config.xml"; std::vector> handlers = { std::make_shared(), std::make_shared() @@ -59,6 +65,7 @@ std::string GetPkgIdFromPath(const std::string& path) { new parser::ManifestHandlerRegistry(handlers)); std::unique_ptr parser( new parser::ManifestParser(std::move(registry))); + bf::path config_path = tmp_path / GetManifestFileName(); if (!parser->ParseManifest(config_path)) { ci::RemoveAll(tmp_path); return {}; @@ -76,31 +83,8 @@ std::string GetPkgIdFromPath(const std::string& path) { return pkg_id; } -std::string ReadPkgidFromRecovery(const std::string& recovery_path) { - std::unique_ptr recovery_file = - ci::recovery::RecoveryFile::OpenRecoveryFileForPath(recovery_path); - recovery_file->Detach(); - return recovery_file->pkgid(); -} - -} // namespace - -namespace wgt { - -bool WgtAppQueryInterface::IsPkgInstalled(const std::string& arg, uid_t uid) { - // argument from commandline is package id - if (ci::QueryIsPackageInstalled(arg, ci::GetRequestMode(uid), uid)) - return true; - - // argument from commandline is path to file - std::string pkg_id = GetPkgIdFromPath(arg); - if (pkg_id.empty()) - return false; - return ci::QueryIsPackageInstalled(pkg_id, ci::GetRequestMode(uid), uid); -} - bool WgtAppQueryInterface::IsHybridApplication(const std::string& arg, - uid_t uid) { + uid_t uid) const { std::string info; bool is_recovery = arg.find("wgt-recovery-") != std::string::npos; if (is_recovery) @@ -128,8 +112,4 @@ bool WgtAppQueryInterface::IsHybridApplication(const std::string& arg, return false; } -std::string WgtAppQueryInterface::GetPkgId(const std::string& arg) { - return GetPkgIdFromPath(arg); -} - } // namespace wgt diff --git a/src/wgt/wgt_app_query_interface.h b/src/wgt/wgt_app_query_interface.h index 3610da9..c19d46a 100644 --- a/src/wgt/wgt_app_query_interface.h +++ b/src/wgt/wgt_app_query_interface.h @@ -21,27 +21,16 @@ namespace wgt { class WgtAppQueryInterface : public common_installer::AppQueryInterface { public: /** - * \brief method for checking if package is installed based - * on argv - * - * \return true if package is installed - */ - bool IsPkgInstalled(const std::string& arg, uid_t uid) override; - - /** * \brief This method is workaround for detecting installation of hybrid * application. * * \return true if package is hybrid */ - bool IsHybridApplication(const std::string& arg, uid_t uid); + bool IsHybridApplication(const std::string& arg, uid_t uid) const; - /** - * \brief method for getting package id from package file - * - * \return package id - */ - std::string GetPkgId(const std::string& arg) override; + private: + std::string GetPkgIdFromPath(const std::string& path) const override; + std::string GetManifestFileName() const override; }; } // namespace wgt -- 2.7.4