paludis  Version 2.6.0
fs_merger.hh
Go to the documentation of this file.
1 /* vim: set sw=4 sts=4 et foldmethod=syntax : */
2 
3 /*
4  * Copyright (c) 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_FS_MERGER_HH
21 #define PALUDIS_GUARD_PALUDIS_FS_MERGER_HH 1
22 
23 #include <paludis/fs_merger-fwd.hh>
25 #include <paludis/util/options.hh>
26 #include <paludis/util/named_value.hh>
27 #include <paludis/util/timestamp.hh>
29 #include <paludis/merger.hh>
31 #include <paludis/hook-fwd.hh>
32 #include <paludis/partitioning-fwd.hh>
33 #include <iosfwd>
34 #include <sys/stat.h>
35 #include <sys/types.h>
36 
37 /** \file
38  * Declarations for the FSMerger class, which can be used by Repository
39  * implementations to perform to-filesystem merging.
40  *
41  * \ingroup g_repository
42  *
43  * \section Examples
44  *
45  * - None at this time.
46  */
47 
48 namespace paludis
49 {
50  namespace n
51  {
52  typedef Name<struct name_environment> environment;
53  typedef Name<struct name_fix_mtimes_before> fix_mtimes_before;
54  typedef Name<struct name_fs_merger_options> fs_merger_options;
55  typedef Name<struct name_get_new_ids_or_minus_one> get_new_ids_or_minus_one;
56  typedef Name<struct name_image> image;
57  typedef Name<struct name_install_under> install_under;
58  typedef Name<struct name_maybe_output_manager> maybe_output_manager;
59  typedef Name<struct name_merged_entries> merged_entries;
60  typedef Name<struct name_no_chown> no_chown;
61  typedef Name<struct name_options> options;
62  typedef Name<struct name_parts> parts;
63  typedef Name<struct name_permit_destination> permit_destination;
64  typedef Name<struct name_root> root;
65  typedef Name<struct name_should_merge> should_merge;
66  }
67 
68  /**
69  * Parameters for a basic FSMerger.
70  *
71  * \see Merger
72  * \ingroup g_repository
73  * \nosubgrouping
74  * \since 0.30
75  * \since 0.51 called FSMergerParams instead of MergerParams
76  */
78  {
80 
81  /**
82  * Rewrite any mtimes that are before this time to this time, even if
83  * preserving mtimes.
84  *
85  * \since 0.44
86  */
88 
89  /**
90  * Additional options not in MergerOptions.
91  *
92  * \since 0.71
93  */
95 
99 
101 
102  /**
103  * We record things we merged here.
104  *
105  * \since 0.41
106  */
108 
111 
112  ///\since 1.1.0
114 
115  ///\since 0.66
117 
119 
120  ///\since 1.99.0
122  };
123 
124  /**
125  * Thrown if an error occurs during an FSMerger operation.
126  *
127  * \ingroup g_repository
128  * \ingroup g_exceptions
129  * \nosubgrouping
130  */
132  public MergerError
133  {
134  public:
135  ///\name Basic operations
136  ///\{
137 
138  FSMergerError(const std::string & msg) noexcept;
139 
140  ///\}
141  };
142 
143  /**
144  * Handles merging an image to a live filesystem.
145  *
146  * \ingroup g_exceptions
147  * \ingroup g_repository
148  * \nosubgrouping
149  * \since 0.51 called FSMerger instead of Merger
150  */
152  public Merger
153  {
154  private:
155  void track_renamed_dir_recursive(const FSPath &);
156  void relabel_dir_recursive(const FSPath &, const FSPath &);
157  void try_to_copy_xattrs(const FSPath &, int, FSMergerStatusFlags &);
158 
159  Pimp<FSMerger> _imp;
160 
161  protected:
162  ///\name Basic operations
163  ///\{
164 
165  FSMerger(const FSMergerParams &);
166 
167  ///\}
168 
169  virtual Hook extend_hook(const Hook &);
170 
171  ///\name Track and record merges
172  ///\{
173 
174  void track_install_file(const FSPath &, const FSPath &, const std::string &, const FSMergerStatusFlags &);
175  void track_install_dir(const FSPath &, const FSPath &, const FSMergerStatusFlags &);
176  void track_install_under_dir(const FSPath &, const FSMergerStatusFlags &);
177  void track_install_sym(const FSPath &, const FSPath &, const FSMergerStatusFlags &);
178 
179  ///\}
180 
181  ///\name Handle filesystem entry things
182  ///\{
183 
184  virtual void on_file_main(bool is_check, const FSPath & src, const FSPath & dst);
185  virtual void on_file_over_nothing(bool is_check, const FSPath &, const FSPath &);
186  virtual void on_file_over_file(bool is_check, const FSPath &, const FSPath &);
187  virtual void on_file_over_dir(bool is_check, const FSPath &, const FSPath &);
188  virtual void on_file_over_sym(bool is_check, const FSPath &, const FSPath &);
189  virtual void on_file_over_misc(bool is_check, const FSPath &, const FSPath &);
190 
191  virtual FSMergerStatusFlags install_file(const FSPath &, const FSPath &, const std::string &) PALUDIS_ATTRIBUTE((warn_unused_result));
192  virtual void unlink_file(FSPath);
193  virtual void record_install_file(const FSPath &, const FSPath &, const std::string &, const FSMergerStatusFlags &) = 0;
194 
195  virtual void on_enter_dir(bool is_check, const FSPath);
196 
197  virtual void on_dir_main(bool is_check, const FSPath & src, const FSPath & dst);
198  virtual void on_dir_over_nothing(bool is_check, const FSPath &, const FSPath &);
199  virtual void on_dir_over_file(bool is_check, const FSPath &, const FSPath &);
200  virtual void on_dir_over_dir(bool is_check, const FSPath &, const FSPath &);
201  virtual void on_dir_over_sym(bool is_check, const FSPath &, const FSPath &);
202  virtual void on_dir_over_misc(bool is_check, const FSPath &, const FSPath &);
203 
204  virtual FSMergerStatusFlags install_dir(const FSPath &, const FSPath &) PALUDIS_ATTRIBUTE((warn_unused_result));
205  virtual void unlink_dir(FSPath);
206  virtual void record_install_dir(const FSPath &, const FSPath &, const FSMergerStatusFlags &) = 0;
207  virtual void record_install_under_dir(const FSPath &, const FSMergerStatusFlags &) = 0;
208 
209  virtual void on_sym_main(bool is_check, const FSPath & src, const FSPath & dst);
210  virtual void on_sym_over_nothing(bool is_check, const FSPath &, const FSPath &);
211  virtual void on_sym_over_file(bool is_check, const FSPath &, const FSPath &);
212  virtual void on_sym_over_dir(bool is_check, const FSPath &, const FSPath &);
213  virtual void on_sym_over_sym(bool is_check, const FSPath &, const FSPath &);
214  virtual void on_sym_over_misc(bool is_check, const FSPath &, const FSPath &);
215 
216  virtual FSMergerStatusFlags install_sym(const FSPath &, const FSPath &) PALUDIS_ATTRIBUTE((warn_unused_result));
217  virtual void unlink_sym(FSPath);
218  virtual void record_install_sym(const FSPath &, const FSPath &, const FSMergerStatusFlags &) = 0;
219 
220  virtual void unlink_misc(FSPath);
221 
222  virtual void prepare_install_under();
223 
224  virtual FSPath canonicalise_root_path(const FSPath & f);
225 
226  virtual void do_dir_recursive(bool is_check, const FSPath &, const FSPath &);
227 
228  ///\}
229 
230  ///\name Configuration protection
231  ///\{
232 
233  virtual bool config_protected(const FSPath &, const FSPath &) = 0;
234  virtual std::string make_config_protect_name(const FSPath &, const FSPath &) = 0;
235 
236  ///\}
237 
238  virtual std::string make_arrows(const FSMergerStatusFlags & flags) const;
239  virtual void display_merge(const EntryType &, const FSPath &,
240  const FSMergerStatusFlags &,
241  const std::string & = "") const;
242 
243  public:
244  ///\name Basic operations
245  ///\{
246 
247  virtual ~FSMerger();
248 
249  FSMerger(const FSMerger &) = delete;
250  FSMerger & operator= (const FSMerger &) = delete;
251 
252  ///\}
253 
254  virtual void merge();
255  };
256 
257 }
258 
259 #endif
Definition: pimp.hh:51
Definition: about_metadata-fwd.hh:23
NamedValue< n::fs_merger_options, FSMergerOptions > fs_merger_options
Definition: fs_merger.hh:94
NamedValue< n::should_merge, std::function< bool(const FSPath &)> > should_merge
Definition: fs_merger.hh:121
NamedValue< n::merged_entries, std::shared_ptr< FSPathSet > > merged_entries
Definition: fs_merger.hh:107
Definition: fs_merger.hh:151
NamedValue< n::permit_destination, PermitDestinationFn > permit_destination
Definition: fs_merger.hh:116
Definition: fs_merger.hh:77
NamedValue< n::parts, std::shared_ptr< const Partitioning > > parts
Definition: fs_merger.hh:113
Definition: merger.hh:83
Definition: fs_merger.hh:131
Definition: hook.hh:74
Definition: named_value-fwd.hh:26
EntryType
Definition: merger_entry_type.hh:14
Definition: options-fwd.hh:34
Definition: fs_path.hh:33
Definition: merger.hh:76
NamedValue< n::fix_mtimes_before, Timestamp > fix_mtimes_before
Definition: fs_merger.hh:87
#define PALUDIS_ATTRIBUTE(x)
Definition: attributes.hh:53
#define PALUDIS_VISIBLE
Definition: attributes.hh:59