AppQueryInterface logic export 20/133520/8
authorDamian Pietruchowski <d.pietruchow@samsung.com>
Mon, 12 Jun 2017 14:03:42 +0000 (16:03 +0200)
committerDamian Pietruchowski <d.pietruchow@samsung.com>
Wed, 23 Aug 2017 11:23:12 +0000 (13:23 +0200)
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/133518/
- https://review.tizen.org/gerrit/#/c/133519/

Change-Id: I280e6d6c2bc718c34238bb3a96c81b4584e5d964
Signed-off-by: Damian Pietruchowski <d.pietruchow@samsung.com>
src/tpk/tpk_app_query_interface.cc
src/tpk/tpk_app_query_interface.h

index 49adc0f4528f7fb8b215f7d4247ea90602cf3d0a..1f44687006194d3875936735c0b61774351d44b1 100644 (file)
@@ -31,19 +31,19 @@ namespace {
 
 const char kManifestFileName[] = "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,
-      kManifestFileName)) {
-    ci::RemoveAll(tmp_path);
+}  // namespace
+
+namespace tpk {
+
+std::string TpkAppQueryInterface::GetManifestFileName() const {
+  return std::string(kManifestFileName);
+}
+
+std::string TpkAppQueryInterface::GetPkgIdFromPath(
+    const std::string& path) const {
+  bf::path tmp_path = ExtractManifest(path);
+  if (tmp_path.empty())
     return {};
-  }
   bf::path manifest_path = tmp_path / kManifestFileName;
   if (!bf::exists(manifest_path)) {
     ci::RemoveAll(tmp_path);
@@ -62,24 +62,4 @@ std::string GetPkgIdFromPath(const std::string& path) {
   return pkg_id;
 }
 
-}  // namespace
-
-namespace tpk {
-
-bool TpkAppQueryInterface::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);
-}
-
-std::string TpkAppQueryInterface::GetPkgId(const std::string& arg) {
-  return GetPkgIdFromPath(arg);
-}
-
 }  // namespace tpk
index 011a9f502421b64e6e4450b6c90a643e9a35ec3a..a34c95215dfe6209fe7a69378fff84a8c8570c6d 100644 (file)
@@ -19,9 +19,9 @@ namespace tpk {
 
 class TPK_BACKEND_EXPORT_API TpkAppQueryInterface
     : public common_installer::AppQueryInterface {
- public:
-  bool IsPkgInstalled(const std::string& arg, uid_t uid) override;
-  std::string GetPkgId(const std::string& arg) override;
+ private:
+  std::string GetPkgIdFromPath(const std::string& path) const override;
+  std::string GetManifestFileName() const override;
 };
 
 }  // namespace tpk