96ad6a3262588954d50cdcf2f206771fe450b8e7
[platform/core/appfw/app-installers.git] / src / pkg_initdb / manifest_loader.cc
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.
4
5 #include <boost/filesystem/path.hpp>
6 #include <boost/filesystem/operations.hpp>
7
8 #include <tzplatform_config.h>
9
10 #include <tpk_manifest_handlers/package_handler.h>
11 #include <tpk_manifest_handlers/tpk_config_parser.h>
12
13 #include <iostream>
14 #include <list>
15 #include <string>
16
17 #include "pkg_initdb/manifest_loader.h"
18
19 namespace bf = boost::filesystem;
20
21 ManifestLoader::ManifestLoader(const std::string& path) {
22   path_ = bf::path(path);
23 }
24
25 std::list<ManifestInfo> ManifestLoader::LoadManifest() {
26   std::list<ManifestInfo> list;
27   std::cerr << "Loading manifest files from " << path_ << std::endl;
28   for (bf::directory_iterator iter(path_); iter != bf::directory_iterator();
29        ++iter) {
30     if (!bf::is_regular_file(iter->path()))
31       continue;
32
33     tpk::parse::TPKConfigParser parser;
34     if (!parser.ParseManifest(iter->path())) {
35       std::cerr << "Failed to parse tizen manifest file: "
36                 << parser.GetErrorMessage() << std::endl;
37       continue;
38     }
39     auto package_info =
40         std::static_pointer_cast<const tpk::parse::PackageInfo>(
41             parser.GetManifestData(tpk::parse::PackageInfo::key()));
42     if (!package_info) {
43       std::cerr << "Failed to get package info" << std::endl;
44       continue;
45     }
46     std::string type = package_info->type();
47     if (type.empty())
48       type = "tpk";
49
50     list.emplace_back(
51         std::make_tuple(iter->path().string(), package_info->package(), type));
52   }
53
54   return list;
55 }