merger.hh

Go to the documentation of this file.
00001 /* vim: set sw=4 sts=4 et foldmethod=syntax : */
00002 
00003 /*
00004  * Copyright (c) 2007, 2008 Ciaran McCreesh
00005  *
00006  * This file is part of the Paludis package manager. Paludis is free software;
00007  * you can redistribute it and/or modify it under the terms of the GNU General
00008  * Public License version 2, as published by the Free Software Foundation.
00009  *
00010  * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
00011  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00012  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00013  * details.
00014  *
00015  * You should have received a copy of the GNU General Public License along with
00016  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00017  * Place, Suite 330, Boston, MA  02111-1307  USA
00018  */
00019 
00020 #ifndef PALUDIS_GUARD_PALUDIS_MERGER_HH
00021 #define PALUDIS_GUARD_PALUDIS_MERGER_HH 1
00022 
00023 #include <paludis/merger-fwd.hh>
00024 #include <paludis/util/fs_entry.hh>
00025 #include <paludis/util/exception.hh>
00026 #include <paludis/util/options.hh>
00027 #include <paludis/util/named_value.hh>
00028 #include <paludis/merger_entry_type.hh>
00029 #include <iosfwd>
00030 #include <sys/stat.h>
00031 #include <sys/types.h>
00032 
00033 /** \file
00034  * Declarations for the Merger class, which can be used by Repository
00035  * implementations to perform to-filesystem merging.
00036  *
00037  * \ingroup g_repository
00038  *
00039  * \section Examples
00040  *
00041  * - None at this time.
00042  */
00043 
00044 namespace paludis
00045 {
00046     class Environment;
00047     class Hook;
00048 
00049     namespace n
00050     {
00051         struct environment;
00052         struct get_new_ids_or_minus_one;
00053         struct image;
00054         struct install_under;
00055         struct no_chown;
00056         struct options;
00057         struct root;
00058     }
00059 
00060     /**
00061      * Parameters for a basic Merger.
00062      *
00063      * \see Merger
00064      * \ingroup g_repository
00065      * \nosubgrouping
00066      * \since 0.30
00067      */
00068     struct MergerParams
00069     {
00070         NamedValue<n::environment, Environment *> environment;
00071         NamedValue<n::get_new_ids_or_minus_one, std::tr1::function<std::pair<uid_t, gid_t> (const FSEntry &)> > get_new_ids_or_minus_one;
00072         NamedValue<n::image, FSEntry> image;
00073         NamedValue<n::install_under, FSEntry> install_under;
00074         NamedValue<n::no_chown, bool> no_chown;
00075         NamedValue<n::options, MergerOptions> options;
00076         NamedValue<n::root, FSEntry> root;
00077     };
00078 
00079     /**
00080      * Thrown if an error occurs during a Merger operation.
00081      *
00082      * \ingroup g_repository
00083      * \ingroup g_exceptions
00084      * \nosubgrouping
00085      */
00086     class PALUDIS_VISIBLE MergerError :
00087         public Exception
00088     {
00089         public:
00090             ///\name Basic operations
00091             ///\{
00092 
00093             MergerError(const std::string & msg) throw ();
00094 
00095             ///\}
00096     };
00097 
00098     /**
00099      * Handles merging an image to a live filesystem.
00100      *
00101      * \ingroup g_exceptions
00102      * \ingroup g_repository
00103      * \nosubgrouping
00104      */
00105     class PALUDIS_VISIBLE Merger :
00106         private PrivateImplementationPattern<Merger>
00107     {
00108         private:
00109             void record_renamed_dir_recursive(const FSEntry &);
00110             void relabel_dir_recursive(const FSEntry &, const FSEntry &);
00111             void rewrite_symlink_as_needed(const FSEntry &, const FSEntry &);
00112             void try_to_copy_xattrs(const FSEntry &, int, MergeStatusFlags &);
00113             bool symlink_needs_rewriting(const FSEntry &);
00114             void do_ownership_fixes_recursive(const FSEntry &);
00115 
00116         protected:
00117             ///\name Basic operations
00118             ///\{
00119 
00120             Merger(const MergerParams &);
00121 
00122             ///\}
00123 
00124             /**
00125              * When called, makes check()'s result a failure.
00126              */
00127             void make_check_fail();
00128 
00129             /**
00130              * Allows subclasses to extend hook calls.
00131              */
00132             virtual Hook extend_hook(const Hook &);
00133 
00134             /**
00135              * Determine the entry type of a filesystem entry.
00136              */
00137             virtual EntryType entry_type(const FSEntry &);
00138 
00139             /**
00140              * Handle a directory, recursively.
00141              */
00142             virtual void do_dir_recursive(bool is_check, const FSEntry &, const FSEntry &);
00143 
00144             /**
00145              * Allows subclasses to perform behaviour when entering a directory.
00146              */
00147             virtual void on_enter_dir(bool is_check, const FSEntry);
00148 
00149             /**
00150              * Allows subclasses to perform behaviour when leaving a directory.
00151              */
00152             virtual void on_leave_dir(bool is_check, const FSEntry);
00153 
00154             ///\name Handle filesystem entry things
00155             ///\{
00156 
00157             virtual void on_file(bool is_check, const FSEntry &, const FSEntry &);
00158             virtual void on_file_over_nothing(bool is_check, const FSEntry &, const FSEntry &);
00159             virtual void on_file_over_file(bool is_check, const FSEntry &, const FSEntry &);
00160             virtual void on_file_over_dir(bool is_check, const FSEntry &, const FSEntry &);
00161             virtual void on_file_over_sym(bool is_check, const FSEntry &, const FSEntry &);
00162             virtual void on_file_over_misc(bool is_check, const FSEntry &, const FSEntry &);
00163 
00164             virtual MergeStatusFlags install_file(const FSEntry &, const FSEntry &, const std::string &) PALUDIS_ATTRIBUTE((warn_unused_result));
00165             virtual void unlink_file(FSEntry);
00166             virtual void record_install_file(const FSEntry &, const FSEntry &, const std::string &, const MergeStatusFlags &) = 0;
00167 
00168             virtual void on_dir(bool is_check, const FSEntry &, const FSEntry &);
00169             virtual void on_dir_over_nothing(bool is_check, const FSEntry &, const FSEntry &);
00170             virtual void on_dir_over_file(bool is_check, const FSEntry &, const FSEntry &);
00171             virtual void on_dir_over_dir(bool is_check, const FSEntry &, const FSEntry &);
00172             virtual void on_dir_over_sym(bool is_check, const FSEntry &, const FSEntry &);
00173             virtual void on_dir_over_misc(bool is_check, const FSEntry &, const FSEntry &);
00174 
00175             virtual MergeStatusFlags install_dir(const FSEntry &, const FSEntry &) PALUDIS_ATTRIBUTE((warn_unused_result));
00176             virtual void unlink_dir(FSEntry);
00177             virtual void record_install_dir(const FSEntry &, const FSEntry &, const MergeStatusFlags &) = 0;
00178             virtual void record_install_under_dir(const FSEntry &, const MergeStatusFlags &) = 0;
00179 
00180             virtual void on_sym(bool is_check, const FSEntry &, const FSEntry &);
00181             virtual void on_sym_over_nothing(bool is_check, const FSEntry &, const FSEntry &);
00182             virtual void on_sym_over_file(bool is_check, const FSEntry &, const FSEntry &);
00183             virtual void on_sym_over_dir(bool is_check, const FSEntry &, const FSEntry &);
00184             virtual void on_sym_over_sym(bool is_check, const FSEntry &, const FSEntry &);
00185             virtual void on_sym_over_misc(bool is_check, const FSEntry &, const FSEntry &);
00186 
00187             virtual MergeStatusFlags install_sym(const FSEntry &, const FSEntry &) PALUDIS_ATTRIBUTE((warn_unused_result));
00188             virtual void unlink_sym(FSEntry);
00189             virtual void record_install_sym(const FSEntry &, const FSEntry &, const MergeStatusFlags &) = 0;
00190 
00191             virtual void unlink_misc(FSEntry);
00192             virtual void on_misc(bool is_check, const FSEntry &, const FSEntry &);
00193 
00194             ///\}
00195 
00196             /**
00197              * What to do when an error occurs.
00198              */
00199             virtual void on_error(bool is_check, const std::string &) = 0;
00200 
00201             /**
00202              * What to do when a warning occurs.
00203              */
00204             virtual void on_warn(bool is_check, const std::string &) = 0;
00205 
00206             virtual void display_override(const std::string &) const = 0;
00207 
00208             ///\name Configuration protection
00209             ///\{
00210 
00211             virtual bool config_protected(const FSEntry &, const FSEntry &) = 0;
00212             virtual std::string make_config_protect_name(const FSEntry &, const FSEntry &) = 0;
00213 
00214             ///\}
00215 
00216         public:
00217             ///\name Basic operations
00218             ///\{
00219 
00220             virtual ~Merger();
00221 
00222             ///\}
00223 
00224             /**
00225              * Check a merge, return whether no errors were encountered.
00226              */
00227             virtual bool check() PALUDIS_ATTRIBUTE((warn_unused_result));
00228 
00229             /**
00230              * Perform the merge.
00231              */
00232             virtual void merge();
00233     };
00234 
00235 }
00236 
00237 #endif

Generated on Mon Sep 21 10:36:08 2009 for paludis by  doxygen 1.5.4