Remove boost dependency
[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 <filesystem>
6
7 #include "common/app_query_interface.h"
8 #include "common/utils/pkgmgr_query.h"
9 #include "common/utils/file_util.h"
10
11 namespace fs = std::filesystem;
12
13 namespace common_installer {
14
15 bool AppQueryInterface::IsPkgInstalled(const std::string& arg,
16     uid_t uid) const {
17   std::error_code ec;
18   std::string pkg_id;
19   // argument from commandline is path to file
20   if (fs::exists(arg, ec) && ec.value() == 0)
21     pkg_id = GetPkgIdFromPath(arg);
22   if (pkg_id.empty())
23     pkg_id = arg;
24   PkgQueryInterface pkg_query(pkg_id, uid, true);
25   return pkg_query.IsPackageInstalled(GetRequestMode(uid));
26 }
27
28 std::string AppQueryInterface::GetPkgId(const std::string& arg) const {
29   return GetPkgIdFromPath(arg);
30 }
31
32 fs::path AppQueryInterface::ExtractManifest(
33     const std::string& from) const {
34   if (!fs::exists(from))
35     return {};
36   fs::path tmp_path = GenerateTmpDir("/tmp");
37   std::error_code code;
38   fs::create_directories(tmp_path, code);
39   if (code)
40     return {};
41   if (!ExtractToTmpDir(from.c_str(), tmp_path,
42       GetManifestFileName())) {
43       RemoveAll(tmp_path);
44     return {};
45   }
46   return tmp_path;
47 }
48
49 bool AppQueryInterface::ClearTemporaryFile(
50     const fs::path& path) const {
51   return RemoveAll(path);
52 }
53
54 }  // namespace common_installer