Fix TpkAppQueryInterface 65/90065/6
authorSangyoon Jang <s89.jang@samsung.com>
Fri, 30 Sep 2016 08:07:00 +0000 (17:07 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Thu, 6 Oct 2016 11:45:44 +0000 (20:45 +0900)
Don't parse again argv, argc.
They are already parsed by PkgMgrInterface.

Requires:
 - https://review.tizen.org/gerrit/90478

Change-Id: Ieb8b9468eb60d21561f6f3e54b79dbc1bd1c81a3
Signed-off-by: Sangyoon Jang <s89.jang@samsung.com>
src/tpk/tpk_app_query_interface.cc
src/tpk/tpk_app_query_interface.h

index e910fd06d3f7679fcf7aeeaeb216b862851f5639..d048ef8c43fc691edeb9eabc51e2a90892cd4a62 100644 (file)
@@ -31,47 +31,9 @@ namespace {
 
 const char kManifestFileName[] = "tizen-manifest.xml";
 
-uid_t GetUid(int argc, char** argv) {
-  uid_t uid = 0;
-  for (int i = 0; i < argc; ++i) {
-    if (!strcmp(argv[i], "-u")) {
-      if (i + 1 < argc) {
-        uid = atoi(argv[i + 1]);
-        break;
-      }
-    }
-  }
-
-  return uid;
-}
-
-std::string GetInstallationPackagePath(int argc, char** argv) {
-  std::string path;
-  for (int i = 0; i < argc; ++i) {
-    if (!strcmp(argv[i], "-i") || !strcmp(argv[i], "-w")) {
-      if (i + 1 < argc) {
-        path = argv[i + 1];
-        break;
-      }
-    }
-  }
-  return path;
-}
-
-std::string GetPkgIdFromCmd(int argc, char** argv) {
-  std::string pkgid;
-  for (int i = 0; i < argc; ++i) {
-    if (!strcmp(argv[i], "-y")) {
-      if (i + 1 < argc) {
-        pkgid = argv[i + 1];
-        break;
-      }
-    }
-  }
-  return pkgid;
-}
-
 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);
@@ -104,21 +66,16 @@ std::string GetPkgIdFromPath(const std::string& path) {
 
 namespace tpk {
 
-bool TpkAppQueryInterface::IsAppInstalledByArgv(int argc, char** argv) {
-  std::string path = GetInstallationPackagePath(argc, argv);
-  std::string pkg_id;
-  if (path.empty()) {
-    // check if it is manifest direct install
-    pkg_id = GetPkgIdFromCmd(argc, argv);
-  } else {
-    pkg_id = GetPkgIdFromPath(path);
-  }
+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;
-  uid_t uid = GetUid(argc, argv);
   return ci::QueryIsPackageInstalled(pkg_id, ci::GetRequestMode(uid), uid);
 }
 
 }  // namespace tpk
-
index e2ca0789c7bc4837fb77fee4e2b44750c533a6e8..21d682480e2c2596019d82ff34cb08c1bc5487b9 100644 (file)
@@ -9,6 +9,10 @@
 #define TPK_BACKEND_EXPORT_API
 #endif
 
+#include <sys/types.h>
+
+#include <string>
+
 #include <common/app_query_interface.h>
 
 namespace tpk {
@@ -16,7 +20,7 @@ namespace tpk {
 class TPK_BACKEND_EXPORT_API TpkAppQueryInterface
     : public common_installer::AppQueryInterface {
  public:
-  bool IsAppInstalledByArgv(int argc, char** argv) override;
+  bool IsPkgInstalled(const std::string& arg, uid_t uid) override;
 };
 
 }  // namespace tpk