AppQueryInterface logic export 18/133518/13
authorDamian Pietruchowski <d.pietruchow@samsung.com>
Mon, 12 Jun 2017 13:56:50 +0000 (15:56 +0200)
committerDamian Pietruchowski <d.pietruchow@samsung.com>
Wed, 23 Aug 2017 08:39:38 +0000 (10:39 +0200)
IsPkgInstalled() and GetPkgId() have the same implementation for
wgt-backend and tpk-backend, so only GetPkgIdFromPath() should
be overrided in each backends.

Submit together:
- https://review.tizen.org/gerrit/#/c/133520/
- https://review.tizen.org/gerrit/#/c/133519/

Change-Id: I2b8edb1989ed5cf9fa9e4109292365a4721988f6
Signed-off-by: Damian Pietruchowski <d.pietruchow@samsung.com>
src/common/app_query_interface.cc [new file with mode: 0644]
src/common/app_query_interface.h

diff --git a/src/common/app_query_interface.cc b/src/common/app_query_interface.cc
new file mode 100644 (file)
index 0000000..7b30ec3
--- /dev/null
@@ -0,0 +1,48 @@
+// Copyright (c) 2017 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/app_query_interface.h"
+#include "common/pkgmgr_query.h"
+#include "common/utils/file_util.h"
+
+namespace bf = boost::filesystem;
+namespace bs = boost::system;
+
+namespace common_installer {
+
+bool AppQueryInterface::IsPkgInstalled(const std::string& arg,
+                                       uid_t uid) const {
+  // argument from commandline is package id
+  if (QueryIsPackageInstalled(arg, 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 QueryIsPackageInstalled(pkg_id, GetRequestMode(uid), uid);
+}
+
+std::string AppQueryInterface::GetPkgId(const std::string& arg) const {
+  return GetPkgIdFromPath(arg);
+}
+
+boost::filesystem::path AppQueryInterface::ExtractManifest(
+    const std::string& from) const {
+  if (!bf::exists(from))
+    return {};
+  bf::path tmp_path = GenerateTmpDir("/tmp");
+  bs::error_code code;
+  bf::create_directories(tmp_path, code);
+  if (code)
+    return {};
+  if (!ExtractToTmpDir(from.c_str(), tmp_path,
+      GetManifestFileName())) {
+      RemoveAll(tmp_path);
+    return {};
+  }
+  return tmp_path;
+}
+
+}  // namespace common_installer
index e6f275e..129725d 100644 (file)
@@ -3,6 +3,7 @@
 #ifndef COMMON_APP_QUERY_INTERFACE_H_
 #define COMMON_APP_QUERY_INTERFACE_H_
 
+#include <boost/filesystem.hpp>
 #include <sys/types.h>
 
 #include <string>
@@ -21,19 +22,26 @@ class AppQueryInterface {
   virtual ~AppQueryInterface() { }
 
   /**
-   * \brief abstract method for checking if package is installed based
+   * \brief method for checking if package is installed based
    *        on argv
    *
    * \return true if package is installed
    */
-  virtual bool IsPkgInstalled(const std::string& arg, uid_t uid) = 0;
+  bool IsPkgInstalled(const std::string& arg, uid_t uid) const;
 
   /**
-   * \brief abstract method for getting package id from package file
+   * \brief method for getting package id from package file
    *
    * \return package id
    */
-  virtual std::string GetPkgId(const std::string& arg) = 0;
+  std::string GetPkgId(const std::string& arg) const;
+
+ protected:
+  boost::filesystem::path ExtractManifest(const std::string& from) const;
+
+ private:
+  virtual std::string GetPkgIdFromPath(const std::string& path) const = 0;
+  virtual std::string GetManifestFileName() const = 0;
 };
 
 }  // namespace common_installer