2
* Copyright © 2014 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3,
6
* as published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Thomas Voß <thomas.voss@canonical.com>
19
#include <core/trust/click/index.h>
21
#include <core/trust/click/deb822.h>
23
#include <boost/filesystem.hpp>
24
#include <boost/property_tree/ini_parser.hpp>
25
#include <boost/property_tree/ptree.hpp>
27
// Constructs a new instance, querying filesystem path setups
28
click::Index::Index(const click::Index::Configuration& configuration)
30
// Iterate over all known frameworks.
31
boost::filesystem::directory_iterator it{configuration.paths->default_frameworks_config_dir()}, itE;
32
for (; it != itE; ++it)
34
std::ifstream in{it->path().string().c_str()};
35
auto kv = click::deb822::parse_from_stream(in);
37
if (kv.count(click::Framework::Keys::base_name) == 0 || kv.count(click::Framework::Keys::base_version) == 0)
40
framework_registry->register_framework(Framework::Ptr
44
kv.at(click::Framework::Keys::base_name),
45
kv.at(click::Framework::Keys::base_version)
50
// Iterate over all configured databases.
51
boost::filesystem::directory_iterator itd{configuration.paths->default_database_config_dir()}, itdE;
52
for (; itd != itdE; ++itd)
54
boost::property_tree::ptree ptree;
55
boost::property_tree::ini_parser::read_ini(itd->path().string(), ptree);
57
auto root = ptree.get_child("Click Database").get<std::string>("root");
58
databases.push_back(std::make_shared<click::FileSystemDatabase>(
59
click::FileSystemDatabase::Configuration{root, framework_registry}
65
void click::Index::enumerate_packages(const click::Database::PackageEnumerator& enumerator) const
67
for(auto database : databases)
69
database->enumerate_packages(enumerator);
73
click::Package::Ptr click::Index::find_package_for_name(const std::string& name) const
75
for(auto database : databases)
79
return database->find_package_for_name(name);
84
return click::Package::Ptr{};