Disk ARchive  2.5.2
Full featured and portable backup and archiving tool
cat_directory.hpp
Go to the documentation of this file.
00001 /*********************************************************************/
00002 // dar - disk archive - a backup/restoration program
00003 // Copyright (C) 2002-2052 Denis Corbin
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 //
00019 // to contact the author : http://dar.linux.free.fr/email.html
00020 /*********************************************************************/
00021 
00025 
00026 #ifndef CAT_DIRECTORY_HPP
00027 #define CAT_DIRECTORY_HPP
00028 
00029 #include "../my_config.h"
00030 
00031 extern "C"
00032 {
00033 } // end extern "C"
00034 
00035 #ifdef LIBDAR_FAST_DIR
00036 #include <map>
00037 #endif
00038 
00039 #include <list>
00040 #include "cat_inode.hpp"
00041 
00042 namespace libdar
00043 {
00044     class cat_eod;
00045 
00048 
00050     class cat_directory : public cat_inode
00051     {
00052     public :
00053         cat_directory(const infinint & xuid,
00054               const infinint & xgid,
00055               U_16 xperm,
00056               const datetime & last_access,
00057               const datetime & last_modif,
00058               const datetime & last_change,
00059               const std::string & xname,
00060               const infinint & device);
00061         cat_directory(const cat_directory &ref); // only the inode part is build, no children is duplicated (empty dir)
00062     const cat_directory & operator = (const cat_directory & ref); // set the inode part *only* no subdirectories/subfiles are copies or removed.
00063         cat_directory(user_interaction & dialog,
00064               const pile_descriptor & pdesc,
00065               const archive_version & reading_ver,
00066               saved_status saved,
00067               entree_stats & stats,
00068               std::map <infinint, cat_etoile *> & corres,
00069               compression default_algo,
00070               bool lax,
00071               bool only_detruit, // objects of other class than detruit and cat_directory are not built in memory
00072               bool small);
00073         ~cat_directory() throw(Ebug); // detruit aussi tous les fils et se supprime de son 'parent'
00074 
00076     bool operator == (const cat_entree & ref) const;
00077 
00078         void add_children(cat_nomme *r); // when r is a cat_directory, 'parent' is set to 'this'
00079     bool has_children() const { return !ordered_fils.empty(); };
00080         void reset_read_children() const;
00081     void end_read() const;
00082         bool read_children(const cat_nomme * &r) const; // read the direct children of the cat_directory, returns false if no more is available
00083         // remove all entry not yet read by read_children
00084     void tail_to_read_children();
00085 
00086 
00093     void remove(const std::string & name);
00094 
00095         cat_directory * get_parent() const { return parent; };
00096         bool search_children(const std::string &name, const cat_nomme *&ref) const;
00097     bool callback_for_children_of(user_interaction & dialog, const std::string & sdir, bool isolated = false) const;
00098 
00099             // using is_more_recent_than() from cat_inode class
00100             // using method has_changed_since() from cat_inode class
00101         unsigned char signature() const { return mk_signature('d', get_saved_status()); };
00102 
00104     bool get_recursive_has_changed() const { return recursive_has_changed; };
00105 
00107     void recursive_has_changed_update() const;
00108 
00110     infinint get_tree_size() const;
00111 
00113     infinint get_tree_ea_num() const;
00114 
00116     infinint get_tree_mirage_num() const;
00117 
00118         // for each mirage found (hard link implementation) in the cat_directory tree, add its etiquette to the returned
00119         // list with the number of reference that has been found in the tree. (map[etiquette] = number of occurence)
00120         // from outside of class cat_directory, the given argument is expected to be an empty map.
00121     void get_etiquettes_found_in_tree(std::map<infinint, infinint> & already_found) const;
00122 
00124     bool is_empty() const { return ordered_fils.empty(); };
00125 
00127     void remove_all_mirages_and_reduce_dirs();
00128 
00130     void set_all_mirage_s_inode_dumped_field_to(bool val);
00131 
00132         cat_entree *clone() const { return new (get_pool()) cat_directory(*this); };
00133 
00134     const infinint & get_size() const { recursive_update_sizes(); return x_size; };
00135     const infinint & get_storage_size() const { recursive_update_sizes(); return x_storage_size; };
00136 
00137     void recursively_set_to_unsaved_data_and_FSA();
00138 
00140     void change_location(const pile_descriptor & pdesc);
00141 
00142     protected:
00143         void inherited_dump(const pile_descriptor & pdesc, bool small) const;
00144 
00145     private:
00146     static const cat_eod fin;
00147 
00148     infinint x_size;
00149     infinint x_storage_size;
00150     bool updated_sizes;
00151         cat_directory *parent;
00152 #ifdef LIBDAR_FAST_DIR
00153         std::map<std::string, cat_nomme *> fils; // used for fast lookup
00154 #endif
00155     std::list<cat_nomme *> ordered_fils;
00156         std::list<cat_nomme *>::iterator it; //< next to entry to be returned by read_children
00157     bool recursive_has_changed;
00158 
00159     void clear();
00160     void recursive_update_sizes() const;
00161     void recursive_flag_size_to_update() const;
00162     };
00163 
00165 
00166 } // end of namespace
00167 
00168 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines