Fix test ManifestDirectInstallMode failure
[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   bs::error_code ec;
17   std::string pkg_id;
18   // argument from commandline is path to file
19   if (bf::exists(arg, ec) && ec == 0)
20     pkg_id = GetPkgIdFromPath(arg);
21   if (pkg_id.empty())
22     pkg_id = arg;
23   PkgQueryInterface pkg_query(pkg_id, uid);
24   return pkg_query.IsPackageInstalled(GetRequestMode(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