paludis Version 3.0.2
The one true package mangler
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
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
48namespace 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
121 NamedValue<n::should_merge, std::function<bool(const FSPath &)>> should_merge;
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 */
131 class PALUDIS_VISIBLE FSMergerError :
132 public MergerError
133 {
134 public:
135 ///\name Basic operations
136 ///\{
137
138 FSMergerError(const std::string & msg) noexcept;
139 FSMergerError(int error, const std::string & msg) noexcept;
140
141 ///\}
142 };
143
144 /**
145 * Handles merging an image to a live filesystem.
146 *
147 * \ingroup g_exceptions
148 * \ingroup g_repository
149 * \nosubgrouping
150 * \since 0.51 called FSMerger instead of Merger
151 */
152 class PALUDIS_VISIBLE FSMerger :
153 public Merger
154 {
155 private:
156 void track_renamed_dir_recursive(const FSPath &);
157 void relabel_dir_recursive(const FSPath &, const FSPath &);
158 void try_to_copy_xattrs(const FSPath &, int, FSMergerStatusFlags &);
159
160 Pimp<FSMerger> _imp;
161
162 protected:
163 ///\name Basic operations
164 ///\{
165
166 FSMerger(const FSMergerParams &);
167
168 ///\}
169
170 Hook extend_hook(const Hook &) override;
171
172 ///\name Track and record merges
173 ///\{
174
175 void track_install_file(const FSPath &, const FSPath &, const std::string &, const FSMergerStatusFlags &);
176 void track_install_dir(const FSPath &, const FSPath &, const FSMergerStatusFlags &);
177 void track_install_under_dir(const FSPath &, const FSMergerStatusFlags &);
178 void track_install_sym(const FSPath &, const FSPath &, const FSMergerStatusFlags &);
179
180 ///\}
181
182 ///\name Handle filesystem entry things
183 ///\{
184
185 void on_file_main(bool is_check, const FSPath & src, const FSPath & dst) override;
186 virtual void on_file_over_nothing(bool is_check, const FSPath &, const FSPath &);
187 virtual void on_file_over_file(bool is_check, const FSPath &, const FSPath &);
188 virtual void on_file_over_dir(bool is_check, const FSPath &, const FSPath &);
189 virtual void on_file_over_sym(bool is_check, const FSPath &, const FSPath &);
190 virtual void on_file_over_misc(bool is_check, const FSPath &, const FSPath &);
191
192 virtual FSMergerStatusFlags install_file(const FSPath &, const FSPath &, const std::string &) PALUDIS_ATTRIBUTE((warn_unused_result));
193 virtual void unlink_file(FSPath);
194 virtual void record_install_file(const FSPath &, const FSPath &, const std::string &, const FSMergerStatusFlags &) = 0;
195
196 void on_enter_dir(bool is_check, const FSPath) override;
197
198 void on_dir_main(bool is_check, const FSPath & src, const FSPath & dst) override;
199 virtual void on_dir_over_nothing(bool is_check, const FSPath &, const FSPath &);
200 virtual void on_dir_over_file(bool is_check, const FSPath &, const FSPath &);
201 virtual void on_dir_over_dir(bool is_check, const FSPath &, const FSPath &);
202 virtual void on_dir_over_sym(bool is_check, const FSPath &, const FSPath &);
203 virtual void on_dir_over_misc(bool is_check, const FSPath &, const FSPath &);
204
205 virtual FSMergerStatusFlags install_dir(const FSPath &, const FSPath &) PALUDIS_ATTRIBUTE((warn_unused_result));
206 virtual void unlink_dir(FSPath);
207 virtual void record_install_dir(const FSPath &, const FSPath &, const FSMergerStatusFlags &) = 0;
208 virtual void record_install_under_dir(const FSPath &, const FSMergerStatusFlags &) = 0;
209
210 void on_sym_main(bool is_check, const FSPath & src, const FSPath & dst) override;
211 virtual void on_sym_over_nothing(bool is_check, const FSPath &, const FSPath &);
212 virtual void on_sym_over_file(bool is_check, const FSPath &, const FSPath &);
213 virtual void on_sym_over_dir(bool is_check, const FSPath &, const FSPath &);
214 virtual void on_sym_over_sym(bool is_check, const FSPath &, const FSPath &);
215 virtual void on_sym_over_misc(bool is_check, const FSPath &, const FSPath &);
216
217 virtual FSMergerStatusFlags install_sym(const FSPath &, const FSPath &) PALUDIS_ATTRIBUTE((warn_unused_result));
218 virtual void unlink_sym(FSPath);
219 virtual void record_install_sym(const FSPath &, const FSPath &, const FSMergerStatusFlags &) = 0;
220
221 virtual void unlink_misc(FSPath);
222
223 void prepare_install_under() override;
224
225 FSPath canonicalise_root_path(const FSPath & f) override;
226
227 void do_dir_recursive(bool is_check, const FSPath &, const FSPath &) override;
228
229 ///\}
230
231 ///\name Configuration protection
232 ///\{
233
234 virtual bool config_protected(const FSPath &, const FSPath &) = 0;
235 virtual std::string make_config_protect_name(const FSPath &, const FSPath &) = 0;
236
237 ///\}
238
239 virtual std::string make_arrows(const FSMergerStatusFlags & flags) const;
240 virtual void display_merge(const EntryType &, const FSPath &,
241 const FSMergerStatusFlags &,
242 const std::string & = "") const;
243
244 public:
245 ///\name Basic operations
246 ///\{
247
248 virtual ~FSMerger();
249
250 FSMerger(const FSMerger &) = delete;
251 FSMerger & operator= (const FSMerger &) = delete;
252
253 ///\}
254
255 void merge() override;
256 };
257
258}
259
260#endif
void merge() override
void on_enter_dir(bool is_check, const FSPath) override
Hook extend_hook(const Hook &) override
void do_dir_recursive(bool is_check, const FSPath &, const FSPath &) override
Definition fs_path.hh:34
Definition hook.hh:75
Definition named_value.hh:51
Definition pimp.hh:52
Options< FSMergerStatusFlag > FSMergerStatusFlags
Definition fs_merger-fwd.hh:45
#define PALUDIS_ATTRIBUTE(x)
Definition attributes.hh:53
#define PALUDIS_VISIBLE
Definition attributes.hh:59
Definition about_metadata-fwd.hh:24
Definition fs_merger.hh:78
NamedValue< n::merged_entries, std::shared_ptr< FSPathSet > > merged_entries
Definition fs_merger.hh:107
NamedValue< n::should_merge, std::function< bool(const FSPath &)> > should_merge
Definition fs_merger.hh:121
NamedValue< n::fix_mtimes_before, Timestamp > fix_mtimes_before
Definition fs_merger.hh:87
NamedValue< n::parts, std::shared_ptr< const Partitioning > > parts
Definition fs_merger.hh:113
NamedValue< n::fs_merger_options, FSMergerOptions > fs_merger_options
Definition fs_merger.hh:94
NamedValue< n::permit_destination, PermitDestinationFn > permit_destination
Definition fs_merger.hh:116