aboutsummaryrefslogtreecommitdiff
path: root/paludis/repositories/gemcutter/gemcutter_repository.cc
blob: 6540fdbd46d8b41eaad0ca58f968dc66d8c48689 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2010, 2011, 2013 Ciaran McCreesh
 *
 * This file is part of the Paludis package manager. Paludis is free software;
 * you can redistribute it and/or modify it under the terms of the GNU General
 * Public License version 2, as published by the Free Software Foundation.
 *
 * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <paludis/repositories/gemcutter/gemcutter_repository.hh>
#include <paludis/repositories/gemcutter/gemcutter_repository_store.hh>
#include <paludis/util/pimp-impl.hh>
#include <paludis/util/active_object_ptr.hh>
#include <paludis/util/deferred_construction_ptr.hh>
#include <paludis/util/stringify.hh>
#include <paludis/util/tokeniser.hh>
#include <paludis/util/make_named_values.hh>
#include <paludis/util/visitor_cast.hh>
#include <paludis/util/simple_parser.hh>
#include <paludis/util/safe_ifstream.hh>
#include <paludis/util/safe_ofstream.hh>
#include <paludis/util/fs_stat.hh>
#include <paludis/literal_metadata_key.hh>
#include <paludis/action.hh>
#include <paludis/syncer.hh>
#include <paludis/hook.hh>
#include <paludis/package_id.hh>
#include <paludis/output_manager.hh>
#include <paludis/environment.hh>
#include <list>

using namespace paludis;
using namespace paludis::gemcutter_repository;

namespace
{
    std::shared_ptr<GemcutterRepositoryStore>
    make_store(const GemcutterRepository * const repo, const GemcutterRepositoryParams & p)
    {
        return std::make_shared<GemcutterRepositoryStore>(p.environment(), repo, p.location());
    }
}

namespace paludis
{
    template <>
    struct Imp<GemcutterRepository>
    {
        const GemcutterRepositoryParams params;

        const std::shared_ptr<LiteralMetadataValueKey<std::string> > format_key;
        const std::shared_ptr<LiteralMetadataValueKey<FSPath> > location_key;

        const ActiveObjectPtr<DeferredConstructionPtr<std::shared_ptr<GemcutterRepositoryStore> > > store;

        Imp(const GemcutterRepository * const repo, const GemcutterRepositoryParams & p) :
            params(p),
            format_key(std::make_shared<LiteralMetadataValueKey<std::string> >("format", "format", mkt_significant, "gemcutter")),
            location_key(std::make_shared<LiteralMetadataValueKey<FSPath> >("location", "location", mkt_significant, params.location())),
            store(DeferredConstructionPtr<std::shared_ptr<GemcutterRepositoryStore> > (std::bind(&make_store, repo, std::cref(params))))
        {
        }
    };
}

GemcutterRepositoryConfigurationError::GemcutterRepositoryConfigurationError(const std::string & s) throw () :
    ConfigurationError("GemcutterRepository configuration error: " + s)
{
}

GemcutterRepository::GemcutterRepository(const GemcutterRepositoryParams & p) :
    Repository(
            p.environment(),
            p.name(),
            make_named_values<RepositoryCapabilities>(
                n::destination_interface() = static_cast<RepositoryDestinationInterface *>(0),
                n::environment_variable_interface() = static_cast<RepositoryEnvironmentVariableInterface *>(0),
                n::manifest_interface() = static_cast<RepositoryManifestInterface *>(0)
                )),
    _imp(this, p)
{
    _add_metadata_keys();
}

GemcutterRepository::~GemcutterRepository()
{
}

const bool
GemcutterRepository::is_unimportant() const
{
    return false;
}

void
GemcutterRepository::_add_metadata_keys()
{
    clear_metadata_keys();
    add_metadata_key(_imp->format_key);
    add_metadata_key(_imp->location_key);
}

void
GemcutterRepository::need_keys_added() const
{
}

const std::shared_ptr<const MetadataValueKey<std::string> >
GemcutterRepository::format_key() const
{
    return _imp->format_key;
}

const std::shared_ptr<const MetadataValueKey<FSPath> >
GemcutterRepository::location_key() const
{
    return _imp->location_key;
}

const std::shared_ptr<const MetadataValueKey<FSPath> >
GemcutterRepository::installed_root_key() const
{
    return nullptr;
}

void
GemcutterRepository::invalidate()
{
    _imp.reset(new Imp<GemcutterRepository>(this, _imp->params));
    _add_metadata_keys();
}

bool
GemcutterRepository::has_category_named(const CategoryNamePart & c, const RepositoryContentMayExcludes &) const
{
    return _imp->store->has_category_named(c);
}

bool
GemcutterRepository::has_package_named(const QualifiedPackageName & q, const RepositoryContentMayExcludes &) const
{
    return _imp->store->has_package_named(q);
}

std::shared_ptr<const CategoryNamePartSet>
GemcutterRepository::category_names(const RepositoryContentMayExcludes &) const
{
    return _imp->store->category_names();
}

std::shared_ptr<const CategoryNamePartSet>
GemcutterRepository::unimportant_category_names(const RepositoryContentMayExcludes &) const
{
    return _imp->store->unimportant_category_names();
}

std::shared_ptr<const CategoryNamePartSet>
GemcutterRepository::category_names_containing_package(const PackageNamePart & p, const RepositoryContentMayExcludes & x) const
{
    return Repository::category_names_containing_package(p, x);
}

std::shared_ptr<const QualifiedPackageNameSet>
GemcutterRepository::package_names(const CategoryNamePart & c, const RepositoryContentMayExcludes &) const
{
    return _imp->store->package_names(c);
}

std::shared_ptr<const PackageIDSequence>
GemcutterRepository::package_ids(const QualifiedPackageName & p, const RepositoryContentMayExcludes &) const
{
    return _imp->store->package_ids(p);
}

bool
GemcutterRepository::some_ids_might_support_action(const SupportsActionTestBase & a) const
{
    return a.make_accept_returning(
        [&] (const SupportsActionTest<InstallAction> &)      { return true; },
        [&] (const SupportsActionTest<FetchAction> &)        { return true; },
        [&] (const SupportsActionTest<PretendFetchAction> &) { return false; },
        [&] (const SupportsActionTest<ConfigAction> &)       { return false; },
        [&] (const SupportsActionTest<PretendAction> &)      { return false; },
        [&] (const SupportsActionTest<InfoAction> &)         { return false; },
        [&] (const SupportsActionTest<UninstallAction> &)    { return false; }
        );
}

bool
GemcutterRepository::some_ids_might_not_be_masked() const
{
    return true;
}

bool
GemcutterRepository::sync(const std::string &, const std::string &, const std::shared_ptr<OutputManager> &) const
{
    return false;
}

std::shared_ptr<Repository>
GemcutterRepository::repository_factory_create(
        Environment * const env,
        const std::function<std::string (const std::string &)> & f)
{
    Context context("When making repository repository from repo_file '" + f("repo_file") + "':");

    std::string name_str(f("name"));
    if (name_str.empty())
        name_str = "gemcutter";

    std::string location_str(f("location"));
    if (location_str.empty())
        throw GemcutterRepositoryConfigurationError("Key 'location' not specified or empty");

    return std::make_shared<GemcutterRepository>(
            make_named_values<GemcutterRepositoryParams>(
                n::environment() = env,
                n::location() = FSPath(location_str),
                n::name() = RepositoryName(name_str)
                ));
}

RepositoryName
GemcutterRepository::repository_factory_name(
        const Environment * const,
        const std::function<std::string (const std::string &)> & f)
{
    if (f("name").empty())
        return RepositoryName("gemcutter");
    else
        return RepositoryName(f("name"));
}

std::shared_ptr<const RepositoryNameSet>
GemcutterRepository::repository_factory_dependencies(
        const Environment * const,
        const std::function<std::string (const std::string &)> &)
{
    return std::make_shared<RepositoryNameSet>();
}

void
GemcutterRepository::populate_sets() const
{
}

HookResult
GemcutterRepository::perform_hook(const Hook &, const std::shared_ptr<OutputManager> &)
{
    return make_named_values<HookResult>(n::max_exit_status() = 0, n::output() = "");
}

const std::shared_ptr<const MetadataCollectionKey<Map<std::string, std::string> > >
GemcutterRepository::sync_host_key() const
{
    return nullptr;
}

const std::shared_ptr<const Set<std::string> >
GemcutterRepository::maybe_expand_licence_nonrecursively(const std::string &) const
{
    return nullptr;
}

namespace paludis
{
    template class Pimp<gemcutter_repository::GemcutterRepository>;
}