--- /dev/null
+// 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
#ifndef COMMON_APP_QUERY_INTERFACE_H_
#define COMMON_APP_QUERY_INTERFACE_H_
+#include <boost/filesystem.hpp>
#include <sys/types.h>
#include <string>
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