paludis  Version 2.6.0
merger.hh
1 /* vim: set sw=4 sts=4 et foldmethod=syntax : */
2 
3 /*
4  * Copyright (c) 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_MERGER_HH
21 #define PALUDIS_GUARD_PALUDIS_MERGER_HH 1
22 
23 #include <paludis/merger-fwd.hh>
24 #include <paludis/util/named_value.hh>
25 #include <paludis/util/options.hh>
26 #include <paludis/util/timestamp.hh>
27 #include <paludis/util/fs_path.hh>
28 #include <paludis/hook-fwd.hh>
31 #include <paludis/output_manager-fwd.hh>
32 
33 namespace paludis
34 {
35  namespace n
36  {
37  typedef Name<struct name_environment> environment;
38  typedef Name<struct name_fix_mtimes_before> fix_mtimes_before;
39  typedef Name<struct name_get_new_ids_or_minus_one> get_new_ids_or_minus_one;
40  typedef Name<struct name_image> image;
41  typedef Name<struct name_install_under> install_under;
42  typedef Name<struct name_maybe_output_manager> maybe_output_manager;
43  typedef Name<struct name_merged_entries> merged_entries;
44  typedef Name<struct name_no_chown> no_chown;
45  typedef Name<struct name_options> options;
46  typedef Name<struct name_permit_destination> permit_destination;
47  typedef Name<struct name_root> root;
48  }
49 
50  /**
51  * Parameters for a basic Merger.
52  *
53  * \see Merger
54  * \ingroup g_repository
55  * \nosubgrouping
56  * \since 0.30
57  */
58  struct MergerParams
59  {
69 
70  ///\since 0.66
72 
74  };
75 
77  public Exception
78  {
79  public:
80  MergerError(const std::string &) noexcept;
81  };
82 
84  {
85  private:
86  Pimp<Merger> _imp;
87 
88  protected:
89  bool symlink_needs_rewriting(const FSPath &);
90  void rewrite_symlink_as_needed(const FSPath &, const FSPath &);
91  void set_skipped_dir(const bool);
92  void do_ownership_fixes_recursive(const FSPath &);
93  bool fixed_ownership_for(const FSPath &);
94 
95  /**
96  * Allows subclasses to extend hook calls.
97  */
98  virtual Hook extend_hook(const Hook &);
99 
100  /**
101  * When called, makes check()'s result a failure.
102  */
103  void make_check_fail();
104 
105  /**
106  * Handle a directory, recursively.
107  */
108  virtual void do_dir_recursive(bool is_check, const FSPath &, const FSPath &);
109 
110  /**
111  * Determine the entry type of a filesystem entry.
112  */
113  virtual EntryType entry_type(const FSPath &);
114 
115  /**
116  * Allows subclasses to perform behaviour when entering a directory.
117  */
118  virtual void on_enter_dir(bool is_check, const FSPath);
119 
120  /**
121  * Allows subclasses to perform behaviour when leaving a directory.
122  */
123  virtual void on_leave_dir(bool is_check, const FSPath);
124 
125  /**
126  * Allows subclasses to perform behaviour when everything has been
127  * merged, before any cleanup.
128  */
129  virtual void on_done_merge();
130 
131  /**
132  * What to do when an error occurs.
133  */
134  virtual void on_error(bool is_check, const std::string &) = 0;
135 
136  /**
137  * What to do when a warning occurs.
138  */
139  virtual void on_warn(bool is_check, const std::string &) = 0;
140 
141  virtual void display_override(const std::string &) const = 0;
142 
143  virtual void on_misc(bool is_check, const FSPath &, const FSPath &);
144  virtual void on_file(bool is_check, const FSPath &, const FSPath &);
145  virtual void on_dir(bool is_check, const FSPath &, const FSPath &);
146  virtual void on_sym(bool is_check, const FSPath &, const FSPath &);
147 
148  virtual void on_file_main(bool is_check, const FSPath &, const FSPath &) = 0;
149  virtual void on_dir_main(bool is_check, const FSPath &, const FSPath &) = 0;
150  virtual void on_sym_main(bool is_check, const FSPath &, const FSPath &) = 0;
151 
152  virtual void prepare_install_under() = 0;
153 
154  virtual FSPath canonicalise_root_path(const FSPath &) = 0;
155 
156  public:
157  explicit Merger(const MergerParams &);
158  ~Merger();
159 
160  Merger(const Merger &) = delete;
161  Merger & operator= (const Merger &) = delete;
162 
163  /**
164  * Check a merge, return whether no errors were encountered.
165  */
166  virtual bool check() PALUDIS_ATTRIBUTE((warn_unused_result));
167 
168  /**
169  * Perform the merge.
170  */
171  virtual void merge();
172  };
173 }
174 
175 #endif
Definition: pimp.hh:51
Definition: about_metadata-fwd.hh:23
NamedValue< n::permit_destination, PermitDestinationFn > permit_destination
Definition: merger.hh:71
Definition: exception.hh:74
Definition: merger.hh:83
Definition: merger.hh:58
Definition: hook.hh:74
Definition: named_value-fwd.hh:26
EntryType
Definition: merger_entry_type.hh:14
Definition: fs_path.hh:33
Definition: merger.hh:76
#define PALUDIS_ATTRIBUTE(x)
Definition: attributes.hh:53
#define PALUDIS_VISIBLE
Definition: attributes.hh:59