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