1 // Copyright (c) 2020 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.
5 #include "common/archive_info.h"
8 #include <manifest_parser/utils/logging.h>
9 #include <package-manager-plugin.h>
11 #include <common/utils/file_util.h>
19 namespace common_installer {
21 bool ArchiveInfo::GetPkgDetailInfo(package_manager_pkg_detail_info_t* info) {
27 snprintf(info->pkg_type, sizeof(info->pkg_type), "%s", type_.c_str());
28 snprintf(info->pkg_name, sizeof(info->pkg_name), "%s", pkgid_.c_str());
29 snprintf(info->pkgid, sizeof(info->pkgid), "%s", pkgid_.c_str());
30 snprintf(info->version, sizeof(info->version), "%s", version_.c_str());
31 snprintf(info->api_version, sizeof(info->api_version), "%s",
32 api_version_.c_str());
33 snprintf(info->author, sizeof(info->author), "%s", author_.c_str());
34 snprintf(info->label, sizeof(info->label), "%s", label_.c_str());
35 snprintf(info->pkg_description, sizeof(info->pkg_description), "%s",
36 description_.c_str());
38 for (const auto& priv : privileges_) {
39 char* priv_str = strdup(priv.first.c_str());
41 LOG(ERROR) << "Out of memory";
42 g_list_free_full(info->dependency_list, free);
45 info->privilege_list = g_list_append(info->privilege_list, priv_str);
48 for (const auto& dependency : dependencies_) {
49 pkg_dependency_info_t* dep =
50 static_cast<pkg_dependency_info_t*>
51 (calloc(1, sizeof(pkg_dependency_info_t)));
53 LOG(ERROR) << "Out of memory";
54 g_list_free_full(info->dependency_list, free);
57 snprintf(dep->pkgid, sizeof(dep->pkgid), "%s",
58 std::get<0>(dependency).c_str());
59 snprintf(dep->type, sizeof(dep->type), "%s",
60 std::get<1>(dependency).c_str());
61 snprintf(dep->required_version, sizeof(dep->required_version), "%s",
62 std::get<2>(dependency).c_str());
63 info->dependency_list = g_list_append(info->dependency_list, dep);
67 reinterpret_cast<char*>(malloc(sizeof(char) * icon_buf_.size()));
68 if (!info->icon_buf) {
69 LOG(ERROR) << "Out of memory";
70 g_list_free_full(info->dependency_list, free);
74 std::copy(icon_buf_.begin(), icon_buf_.end(), info->icon_buf);
75 info->icon_size = icon_buf_.size();
80 void ArchiveInfo::RemoveTmpDir(const std::string& tmp_dir) {
81 common_installer::RemoveAll(tmp_dir);
84 } // namespace common_installer