aboutsummaryrefslogtreecommitdiff
path: root/paludis/repository.hh
blob: 7fa40ec06132771ae3ce1e39aa7acd64f542ca8e (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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2005, 2006 Ciaran McCreesh <ciaranm@gentoo.org>
 *
 * 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
 */

#ifndef PALUDIS_GUARD_PALUDIS_REPOSITORY_HH
#define PALUDIS_GUARD_PALUDIS_REPOSITORY_HH 1

#include <paludis/dep_atom.hh>
#include <paludis/name.hh>
#include <paludis/util/attributes.hh>
#include <paludis/util/counted_ptr.hh>
#include <paludis/util/exception.hh>
#include <paludis/util/virtual_constructor.hh>
#include <paludis/version_metadata.hh>
#include <paludis/version_spec.hh>

#include <map>
#include <string>

/** \file
 * Declarations for the Repository class.
 */

namespace paludis
{
    class Environment;

    /**
     * A Repository provides a representation of a physical repository to a
     * PackageDatabase.
     *
     * We make pretty heavy use of the non-virtual interface idiom here. See
     * \ref EffCpp items 35 and 37.
     */
    class Repository :
        private InstantiationPolicy<Repository, instantiation_method::NonCopyableTag>,
        public InternalCounted<Repository>
    {
        private:
            const RepositoryName _name;

        protected:
            /**
             * Our repository information.
             */
            std::map<std::string, std::string> _info;

            /**
             * Constructor.
             */
            Repository(const RepositoryName &);

            /**
             * Override in descendents: fetch the metadata.
             */
            virtual VersionMetadata::ConstPointer do_version_metadata(
                    const CategoryNamePart &, const PackageNamePart &,
                    const VersionSpec &) const = 0;

            /**
             * Override in descendents: check for a version.
             */
            virtual bool do_has_version(const CategoryNamePart &,
                    const PackageNamePart &, const VersionSpec &) const = 0;

            /**
             * Override in descendents: fetch version specs.
             */
            virtual VersionSpecCollection::ConstPointer do_version_specs(
                    const QualifiedPackageName &) const = 0;

            /**
             * Override in descendents: fetch package names.
             */
            virtual QualifiedPackageNameCollection::ConstPointer do_package_names(
                    const CategoryNamePart &) const = 0;

            /**
             * Override in descendents: fetch category names.
             */
            virtual CategoryNamePartCollection::ConstPointer do_category_names() const = 0;

            /**
             * Override in descendents: check for a package.
             */
            virtual bool do_has_package_named(const CategoryNamePart &,
                    const PackageNamePart &) const = 0;

            /**
             * Override in descendents: check for a category.
             */
            virtual bool do_has_category_named(const CategoryNamePart &) const = 0;

            /**
             * Override in descendents: check for a mask.
             */
            virtual bool do_query_repository_masks(const CategoryNamePart &,
                    const PackageNamePart &, const VersionSpec &) const = 0;

            /**
             * Override in descendents: check for a mask.
             */
            virtual bool do_query_profile_masks(const CategoryNamePart &,
                    const PackageNamePart &, const VersionSpec &) const = 0;

            /**
             * Override in descendents: get use.
             */
            virtual UseFlagState do_query_use(const UseFlagName &) const = 0;

            /**
             * Override in descendents: get use mask.
             */
            virtual bool do_query_use_mask(const UseFlagName &) const = 0;

            /**
             * Override in descendents: is this an arch flag?
             */
            virtual bool do_is_arch_flag(const UseFlagName &) const = 0;

            /**
             * Override in descendents: is this an expand flag?
             */
            virtual bool do_is_expand_flag(const UseFlagName &) const = 0;

            /**
             * Override in descendents: is this a licence?
             */
            virtual bool do_is_licence(const std::string &) const = 0;

            /**
             * Override in descendents: is this a mirror?
             */
            virtual bool do_is_mirror(const std::string &) const = 0;

            /**
             * Override in descendents: install.
             */
            virtual void do_install(const QualifiedPackageName &, const VersionSpec &) const = 0;

            /**
             * Override in descendents: system package list.
             */
            virtual DepAtom::Pointer do_system_packages() const = 0;

            /**
             * Override in descendents: sync, if needed (true) or do nothing (false).
             */
            virtual bool do_sync() const = 0;

        public:
            /**
             * Destructor.
             */
            virtual ~Repository();

            /**
             * Return our name.
             */
            const RepositoryName & name() const PALUDIS_ATTRIBUTE((nothrow));

            /**
             * Do we have a category with the given name?
             */
            bool has_category_named(const CategoryNamePart & c) const
            {
                return do_has_category_named(c);
            }

            /**
             * Do we have a package in the given category with the given name?
             */
            bool has_package_named(const CategoryNamePart & c,
                    const PackageNamePart & p) const
            {
                return do_has_package_named(c, p);
            }

            /**
             * Do we have a package in the given category with the given name?
             * (Override for QualifiedPackageName).
             */
            bool has_package_named(const QualifiedPackageName & q) const
            {
                return has_package_named(q.get<qpn_category>(), q.get<qpn_package>());
            }

            /**
             * Fetch our category names.
             */
            CategoryNamePartCollection::ConstPointer category_names() const
            {
                return do_category_names();
            }

            /**
             * Fetch our package names.
             */
            QualifiedPackageNameCollection::ConstPointer package_names(
                    const CategoryNamePart & c) const
            {
                return do_package_names(c);
            }

            /**
             * Fetch our versions.
             */
            VersionSpecCollection::ConstPointer version_specs(
                    const QualifiedPackageName & p) const
            {
                return do_version_specs(p);
            }

            /**
             * Fetch our versions (override for split name).
             */
            VersionSpecCollection::ConstPointer version_specs(
                    const CategoryNamePart & c, const PackageNamePart & p) const
            {
                return version_specs(QualifiedPackageName(c, p));
            }

            /**
             * Do we have a version spec?
             */
            bool has_version(const CategoryNamePart & c,
                    const PackageNamePart & p, const VersionSpec & v) const
            {
                return do_has_version(c, p, v);
            }

            /**
             * Do we have a version spec? (Override for QualifiedPackageName).
             */
            bool has_version(const QualifiedPackageName & q, const VersionSpec & v) const
            {
                return has_version(q.get<qpn_category>(), q.get<qpn_package>(), v);
            }

            /**
             * Fetch metadata.
             */
            VersionMetadata::ConstPointer version_metadata(
                    const CategoryNamePart & c, const PackageNamePart & p,
                    const VersionSpec & v) const
            {
                return do_version_metadata(c, p, v);
            }

            /**
             * Fetch metadata (override for QualifiedPackageName).
             */
            VersionMetadata::ConstPointer version_metadata(
                    const QualifiedPackageName & q,
                    const VersionSpec & v) const
            {
                return version_metadata(q.get<qpn_category>(), q.get<qpn_package>(), v);
            }

            /**
             * Query repository masks.
             */
            bool query_repository_masks(const CategoryNamePart & c, const PackageNamePart & p,
                    const VersionSpec & v) const
            {
                return do_query_repository_masks(c, p, v);
            }

            /**
             * Query repository masks (override for QualifiedPackageName).
             */
            bool query_repository_masks(const QualifiedPackageName & q, const VersionSpec & v) const
            {
                return do_query_repository_masks(q.get<qpn_category>(), q.get<qpn_package>(), v);
            }

            /**
             * Query profile masks.
             */
            bool query_profile_masks(const CategoryNamePart & c, const PackageNamePart & p,
                    const VersionSpec & v) const
            {
                return do_query_profile_masks(c, p, v);
            }

            /**
             * Query profile masks (override for QualifiedPackageName).
             */
            bool query_profile_masks(const QualifiedPackageName & q, const VersionSpec & v) const
            {
                return do_query_profile_masks(q.get<qpn_category>(), q.get<qpn_package>(), v);
            }

            /**
             * Iterator to information about our repository.
             */
            typedef std::map<std::string, std::string>::const_iterator InfoIterator;

            /**
             * Start of repository information.
             */
            InfoIterator begin_info() const
            {
                return _info.begin();
            }

            /**
             * Past the end of repository information.
             */
            InfoIterator end_info() const
            {
                return _info.end();
            }

            /**
             * Query the state of the specified use flag.
             */
            UseFlagState query_use(const UseFlagName & u) const
            {
                if (do_query_use_mask(u))
                    return use_disabled;
                else
                    return do_query_use(u);
            }

            /**
             * Query whether the specified use flag is masked.
             */
            bool query_use_mask(const UseFlagName & u) const
            {
                return do_query_use_mask(u);
            }

            /**
             * Query whether the specified use flag is an arch flag.
             */
            bool is_arch_flag(const UseFlagName & u) const
            {
                return do_is_arch_flag(u);
            }

            /**
             * Query whether the specified use flag is an expand flag.
             */
            bool is_expand_flag(const UseFlagName & u) const
            {
                return do_is_expand_flag(u);
            }

            /**
             * Query whether the specified item is a licence.
             */
            bool is_license(const std::string & u) const
            {
                return do_is_licence(u);
            }

            /**
             * Query whether the specified item is a mirror.
             */
            bool is_mirror(const std::string & u) const
            {
                return do_is_mirror(u);
            }

            /**
             * Install a package.
             */
            void install(const QualifiedPackageName & q, const VersionSpec & v) const
            {
                do_install(q, v);
            }

            /**
             * Return whether we are an 'installed' repo.
             *
             * No NVI indirection here, it's not worth it.
             */
            virtual bool installed() const = 0;

            /**
             * Sync, if necessary.
             *
             * \return True if we synced successfully, false if we skipped sync.
             */
            bool sync() const
            {
                return do_sync();
            }

            /**
             * Fetch our system packages list.
             */
            virtual DepAtom::Pointer system_packages() const
            {
                return do_system_packages();
            }
    };

    /**
     * Thrown if a repository of the specified type does not exist.
     *
     * \ingroup Exception
     */
    class NoSuchRepositoryTypeError : public ConfigurationError
    {
        public:
            /**
             * Constructor.
             */
            NoSuchRepositoryTypeError(const std::string & format) throw ();
    };

    class PackageDatabase;

    /**
     * Virtual constructor for repositories.
     */
    typedef VirtualConstructor<std::string,
            Repository::Pointer (*) (const Environment * const, const PackageDatabase * const,
                    const std::map<std::string, std::string> &),
            virtual_constructor_not_found::ThrowException<NoSuchRepositoryTypeError> > RepositoryMaker;
}

#endif