AppQueryInterface logic export
[platform/core/appfw/app-installers.git] / src / common / app_query_interface.cc
1 // Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache-2.0 license that can be
3 // found in the LICENSE file.
4
5 #include "common/app_query_interface.h"
6 #include "common/pkgmgr_query.h"
7 #include "common/utils/file_util.h"
8
9 namespace bf = boost::filesystem;
10 namespace bs = boost::system;
11
12 namespace common_installer {
13
14 bool AppQueryInterface::IsPkgInstalled(const std::string& arg,
15                                        uid_t uid) const {
16   // argument from commandline is package id
17   if (QueryIsPackageInstalled(arg, GetRequestMode(uid), uid))
18     return true;
19
20   // argument from commandline is path to file
21   std::string pkg_id = GetPkgIdFromPath(arg);
22   if (pkg_id.empty())
23     return false;
24   return QueryIsPackageInstalled(pkg_id, GetRequestMode(uid), uid);
25 }
26
27 std::string AppQueryInterface::GetPkgId(const std::string& arg) const {
28   return GetPkgIdFromPath(arg);
29 }
30
31 boost::filesystem::path AppQueryInterface::ExtractManifest(
32     const std::string& from) const {
33   if (!bf::exists(from))
34     return {};
35   bf::path tmp_path = GenerateTmpDir("/tmp");
36   bs::error_code code;
37   bf::create_directories(tmp_path, code);
38   if (code)
39     return {};
40   if (!ExtractToTmpDir(from.c_str(), tmp_path,
41       GetManifestFileName())) {
42       RemoveAll(tmp_path);
43     return {};
44   }
45   return tmp_path;
46 }
47
48 }  // namespace common_installer