paludis  Version 1.4.0
repository.hh
Go to the documentation of this file.
1 /* vim: set sw=4 sts=4 et foldmethod=syntax : */
2 
3 /*
4  * Copyright (c) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Ciaran McCreesh
5  *
6  * This file is part of the Paludis package manager. Paludis is free software;
7  * you can redistribute it and/or modify it under the terms of the GNU General
8  * Public License version 2, as published by the Free Software Foundation.
9  *
10  * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17  * Place, Suite 330, Boston, MA 02111-1307 USA
18  */
19 
20 #ifndef PALUDIS_GUARD_PALUDIS_REPOSITORY_HH
21 #define PALUDIS_GUARD_PALUDIS_REPOSITORY_HH 1
22 
23 #include <paludis/action-fwd.hh>
25 #include <paludis/dep_spec-fwd.hh>
26 #include <paludis/spec_tree-fwd.hh>
27 #include <paludis/name.hh>
29 #include <paludis/partitioning-fwd.hh>
32 #include <paludis/util/fs_path.hh>
33 #include <paludis/util/wrapped_forward_iterator-fwd.hh>
34 #include <paludis/util/options.hh>
35 #include <paludis/util/named_value.hh>
36 #include <paludis/util/timestamp.hh>
38 #include <paludis/util/map-fwd.hh>
39 #include <paludis/output_manager-fwd.hh>
40 #include <paludis/version_spec.hh>
42 #include <paludis/metadata_key_holder.hh>
43 #include <paludis/merger-fwd.hh>
44 #include <paludis/hook-fwd.hh>
45 #include <string>
46 #include <functional>
47 
48 /** \file
49  * Declarations for Repository classes.
50  *
51  * \ingroup g_repository
52  *
53  * \section Examples
54  *
55  * - \ref example_repository.cc "example_repository.cc"
56  */
57 
58 namespace paludis
59 {
60  namespace n
61  {
62  typedef Name<struct name_arch> arch;
63  typedef Name<struct name_build_start_time> build_start_time;
64  typedef Name<struct name_check> check;
65  typedef Name<struct name_destination_interface> destination_interface;
66  typedef Name<struct name_environment_file> environment_file;
67  typedef Name<struct name_environment_variable_interface> environment_variable_interface;
68  typedef Name<struct name_image_dir> image_dir;
69  typedef Name<struct name_manifest_interface> manifest_interface;
70  typedef Name<struct name_merged_entries> merged_entries;
71  typedef Name<struct name_options> options;
72  typedef Name<struct name_output_manager> output_manager;
73  typedef Name<struct name_package_id> package_id;
74  typedef Name<struct name_parts> parts;
75  typedef Name<struct name_path> path;
76  typedef Name<struct name_perform_uninstall> perform_uninstall;
77  typedef Name<struct name_permit_destination> permit_destination;
78  typedef Name<struct name_profile> profile;
79  typedef Name<struct name_replacing> replacing;
80  typedef Name<struct name_status> status;
81  typedef Name<struct name_used_this_for_config_protect> used_this_for_config_protect;
82  typedef Name<struct name_want_phase> want_phase;
83  }
84 
85  /**
86  * Optional interfaces that may be provided by a Repository.
87  *
88  * \see Repository
89  * \ingroup g_repository
90  * \since 0.30
91  */
93  {
97  };
98 
99  /**
100  * Parameters for RepositoryDestinationInterface::merge.
101  *
102  * \see RepositoryDestinationInterface
103  * \ingroup g_repository
104  * \since 0.30
105  */
106  struct MergeParams
107  {
108  /**
109  * The start of the build time (for binaries, should really be when the
110  * binary was originally built).
111  *
112  * \since 0.44
113  */
115 
116  /**
117  * Whether to check or perform the merge.
118  *
119  * A check must be performed before a merge.
120  *
121  * \since 0.59
122  */
124 
127 
128  /**
129  * We record things we merged here.
130  * \since 0.41
131  */
133 
137 
138  /**
139  * Package partioning.
140  * \since 1.1.0
141  */
143 
144  /**
145  * Some merges need to do an uninstall mid-way through the merge process.
146  *
147  * \see InstallActionOptions::perform_uninstall
148  * \since 0.36
149  */
150  NamedValue<n::perform_uninstall, std::function<void (
151  const std::shared_ptr<const PackageID> &,
153 
154  ///\since 0.66
156 
157  /**
158  * Someone needs to replace these (either the merge or the install).
159  *
160  * \since 0.57
161  */
163 
165 
166  /**
167  * Sometimes merging runs phase functions, possibly via perform_uninstall.
168  *
169  * \since 0.77
170  */
172  };
173 
174  /**
175  * Thrown if a Set does not exist
176  *
177  * \ingroup g_exceptions
178  * \ingroup g_repository
179  * \nosubgrouping
180  */
182  public Exception
183  {
184  private:
185  std::string _name;
186 
187  public:
188  ///\name Basic operations
189  ///\{
190 
191  NoSuchSetError(const std::string & name) throw ();
192 
193  virtual ~NoSuchSetError() throw ();
194 
195  ///\}
196 
197  /**
198  * Name of the set.
199  */
200  const std::string name() const;
201  };
202 
203  /**
204  * Thrown if a Set is recursively defined
205  *
206  * \ingroup g_exceptions
207  * \ingroup g_repository
208  * \nosubgrouping
209  */
211  public Exception
212  {
213  private:
214  std::string _name;
215 
216  public:
217  ///\name Basic operations
218  ///\{
219 
220  RecursivelyDefinedSetError(const std::string & name) throw ();
221 
222  virtual ~RecursivelyDefinedSetError() throw ();
223 
224  ///\}
225 
226  /**
227  * Name of the set.
228  */
229  const std::string name() const;
230  };
231 
232  /**
233  * A Repository provides a representation of a physical repository to an
234  * Environment.
235  *
236  * \ingroup g_repository
237  * \nosubgrouping
238  */
240  public RepositoryCapabilities,
241  public MetadataKeyHolder
242  {
243  private:
244  Pimp<Repository> _imp;
245 
246  protected:
247  ///\name Basic operations
248  ///\{
249 
250  Repository(const Environment * const, const RepositoryName &, const RepositoryCapabilities &);
251 
252  ///\}
253 
254  public:
255  ///\name Basic operations
256  ///\{
257 
258  virtual ~Repository();
259 
260  Repository(const Repository &) = delete;
261  Repository & operator= (const Repository &) = delete;
262 
263  ///\}
264 
265  ///\name Repository information
266  ///\{
267 
268  /**
269  * Return our name.
270  */
271  const RepositoryName name() const PALUDIS_ATTRIBUTE((nothrow))
272  PALUDIS_ATTRIBUTE((warn_unused_result));
273 
274  ///\}
275 
276  ///\name Specific metadata keys
277  ///\{
278 
279  /**
280  * The format_key, if non-zero, holds our repository's format. Repository
281  * implementations should not return zero here, but clients should still
282  * check.
283  */
284  virtual const std::shared_ptr<const MetadataValueKey<std::string> > format_key() const = 0;
285 
286  /**
287  * The location_key, if non-zero, holds the file or directory containing
288  * our repository's data, the format of which depends on the value of
289  * format_key.
290  */
291  virtual const std::shared_ptr<const MetadataValueKey<FSPath> > location_key() const = 0;
292 
293  /**
294  * The installed_root_key, if non-zero, specifies that we contain installed
295  * packages at the specified root.
296  *
297  * This key is currently used in various places to determine whether a repository is
298  * an 'installed' repository or not.
299  */
300  virtual const std::shared_ptr<const MetadataValueKey<FSPath> > installed_root_key() const = 0;
301 
302  /**
303  * The sync_host_key, if present, should have value containing
304  * the host against which a sync will be performed for each suffix.
305  *
306  * This is used to avoid starting multiple parallel syncs against
307  * the same host.
308  *
309  * \since 0.44
310  * \since 0.55 is a Map<std::string, std::string>.
311  */
312  virtual const std::shared_ptr<const MetadataCollectionKey<Map<std::string, std::string> > > sync_host_key() const = 0;
313 
314  ///\}
315 
316  ///\name Repository content queries
317  ///\{
318 
319  /**
320  * Do we have a category with the given name?
321  *
322  * \since 0.59 takes repository_content_may_excludes
323  */
324  virtual bool has_category_named(const CategoryNamePart & c,
325  const RepositoryContentMayExcludes & repository_content_may_excludes) const = 0;
326 
327  /**
328  * Do we have a package in the given category with the given name?
329  */
330  virtual bool has_package_named(const QualifiedPackageName & q,
331  const RepositoryContentMayExcludes & repository_content_may_excludes) const = 0;
332 
333  /**
334  * Fetch our category names.
335  */
336  virtual std::shared_ptr<const CategoryNamePartSet> category_names(
337  const RepositoryContentMayExcludes & repository_content_may_excludes) const = 0;
338 
339  /**
340  * Fetch unimportant categories.
341  */
342  virtual std::shared_ptr<const CategoryNamePartSet> unimportant_category_names(
343  const RepositoryContentMayExcludes & repository_content_may_excludes) const;
344 
345  /**
346  * Are we unimportant?
347  *
348  * In disambiguation, anything gets preferred over packages from unimportant repositories.
349  *
350  * \since 0.46
351  */
352  virtual const bool is_unimportant() const = 0;
353 
354  /**
355  * Fetch categories that contain a named package.
356  */
357  virtual std::shared_ptr<const CategoryNamePartSet> category_names_containing_package(
358  const PackageNamePart & p,
359  const RepositoryContentMayExcludes & repository_content_may_excludes) const;
360 
361  /**
362  * Fetch our package names.
363  */
364  virtual std::shared_ptr<const QualifiedPackageNameSet> package_names(
365  const CategoryNamePart & c,
366  const RepositoryContentMayExcludes & repository_content_may_excludes) const = 0;
367 
368  /**
369  * Fetch our IDs.
370  */
371  virtual std::shared_ptr<const PackageIDSequence> package_ids(const QualifiedPackageName & p,
372  const RepositoryContentMayExcludes & repository_content_may_excludes) const = 0;
373 
374  /**
375  * Might some of our IDs support a particular action?
376  *
377  * Used to optimise various Generator and Filter queries. If a
378  * repository doesn't support, say, InstallAction, a query can skip
379  * searching it entirely when looking for installable packages.
380  */
381  virtual bool some_ids_might_support_action(const SupportsActionTestBase &) const = 0;
382 
383  /**
384  * Might some of our IDs be not masked?
385  *
386  * Used to optimise various Generator and Filter queries.
387  *
388  * \since 0.49
389  */
390  virtual bool some_ids_might_not_be_masked() const = 0;
391 
392  /**
393  * Possibly expand a licence.
394  *
395  * May return a null pointer, if we don't define any licence
396  * groups, or if the thing being passed in doesn't look like a
397  * licence group.
398  *
399  * This should not be recursive.
400  *
401  * Callers should Environment::expand_licence, not this method.
402  *
403  * \since 0.66
404  */
405  virtual const std::shared_ptr<const Set<std::string> > maybe_expand_licence_nonrecursively(
406  const std::string &) const = 0;
407 
408  ///\}
409 
410  ///\name Repository behaviour methods
411  ///\{
412 
413  /**
414  * Invalidate any in memory cache.
415  */
416  virtual void invalidate() = 0;
417 
418  /**
419  * Regenerate any on disk cache.
420  */
421  virtual void regenerate_cache() const;
422 
423  /**
424  * Purge any invalid on-disk cache entries.
425  */
426  virtual void purge_invalid_cache() const;
427 
428  /**
429  * Perform a hook.
430  *
431  * \since 0.40 (previously in an interface)
432  * \since 0.53 takes optional_output_manager
433  */
434  virtual HookResult perform_hook(
435  const Hook & hook,
436  const std::shared_ptr<OutputManager> & optional_output_manager)
437  PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
438 
439  /**
440  * Sync, if necessary.
441  *
442  * \return True if we synced successfully, false if we skipped sync.
443  * \since 0.42 (previously in an interface)
444  * \since 0.55 takes a source (may be empty)
445  * \since 0.61 takes a revision (may be empty)
446  */
447  virtual bool sync(
448  const std::string & source,
449  const std::string & revision,
450  const std::shared_ptr<OutputManager> &) const = 0;
451 
452  /**
453  * Allow the Repository to drop any memory-cached metadata and
454  * PackageIDs it holds.
455  *
456  * \since 0.42
457  */
458  virtual void can_drop_in_memory_cache() const;
459 
460  ///\}
461 
462  ///\name Set methods
463  ///\{
464 
465  /**
466  * Call Environment::add_set for every set we define.
467  *
468  * Environment will call this method at most once, so no cache or check for
469  * repeats is required. Nothing else should call this method.
470  *
471  * \since 0.40
472  */
473  virtual void populate_sets() const = 0;
474 
475  ///\}
476  };
477 
478  /**
479  * Interface for environment variable querying for repositories.
480  *
481  * \see Repository
482  * \ingroup g_repository
483  * \nosubgrouping
484  */
486  {
487  public:
488  ///\name Environment query functionality
489  ///\{
490 
491  /**
492  * Query an environment variable
493  */
494  virtual std::string get_environment_variable(
495  const std::shared_ptr<const PackageID> & for_package,
496  const std::string & var) const
497  PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
498 
499  ///\}
500 
502  };
503 
504  /**
505  * Interface for repositories that can be used as an install destination.
506  *
507  * \see Repository
508  * \ingroup g_repository
509  * \nosubgrouping
510  */
512  {
513  public:
514  ///\name Destination functions
515  ///\{
516 
517  /**
518  * Are we a suitable destination for the specified package?
519  *
520  * \since 0.58 takes id by shared_ptr
521  */
522  virtual bool is_suitable_destination_for(const std::shared_ptr<const PackageID> &) const
523  PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
524 
525  /**
526  * If true, pre and post install phases will be used when writing to this
527  * destination.
528  *
529  * This should return true for 'real' filesystem destinations (whether or
530  * not root is /, if root merges are supported), and false for intermediate
531  * destinations such as binary repositories.
532  */
533  virtual bool want_pre_post_phases() const
534  PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
535 
536  /**
537  * Merge a package.
538  */
539  virtual void merge(const MergeParams &) = 0;
540 
541  ///\}
542 
544  };
545 
546  /**
547  * Interface for making and verifying Manifest2-style manifests
548  *
549  * \see Repository
550  * \ingroup g_repository
551  * \nosubgrouping
552  */
554  {
555  public:
556  /**
557  * Makes the Manifest for a given package. Requires that all
558  * the needed DIST files, etc, have already been fetched.
559  */
560  virtual void make_manifest(const QualifiedPackageName &) = 0;
561 
562  ///\name Basic operations
563  ///\{
564 
565  virtual ~RepositoryManifestInterface();
566 
567  ///\}
568  };
569 }
570 
571 #endif