Disk ARchive  2.5.1
Full featured and portable backup and archiving tool
cat_directory.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2052 Denis Corbin
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21 
25 
26 #ifndef CAT_DIRECTORY_HPP
27 #define CAT_DIRECTORY_HPP
28 
29 #include "../my_config.h"
30 
31 extern "C"
32 {
33 } // end extern "C"
34 
35 #ifdef LIBDAR_FAST_DIR
36 #include <map>
37 #endif
38 
39 #include <list>
40 #include "cat_inode.hpp"
41 
42 namespace libdar
43 {
44  class cat_eod;
45 
48 
50  class cat_directory : public cat_inode
51  {
52  public :
53  cat_directory(const infinint & xuid,
54  const infinint & xgid,
55  U_16 xperm,
56  const datetime & last_access,
57  const datetime & last_modif,
58  const datetime & last_change,
59  const std::string & xname,
60  const infinint & device);
61  cat_directory(const cat_directory &ref); // only the inode part is build, no children is duplicated (empty dir)
62  const cat_directory & operator = (const cat_directory & ref); // set the inode part *only* no subdirectories/subfiles are copies or removed.
64  const pile_descriptor & pdesc,
65  const archive_version & reading_ver,
66  saved_status saved,
67  entree_stats & stats,
68  std::map <infinint, cat_etoile *> & corres,
69  compression default_algo,
70  bool lax,
71  bool only_detruit, // objects of other class than detruit and cat_directory are not built in memory
72  bool small);
73  ~cat_directory() throw(Ebug); // detruit aussi tous les fils et se supprime de son 'parent'
74 
76  bool operator == (const cat_entree & ref) const;
77 
78  void add_children(cat_nomme *r); // when r is a cat_directory, 'parent' is set to 'this'
79  bool has_children() const { return !ordered_fils.empty(); };
80  void reset_read_children() const;
81  void end_read() const;
82  bool read_children(const cat_nomme * &r) const; // read the direct children of the cat_directory, returns false if no more is available
83  // remove all entry not yet read by read_children
84  void tail_to_read_children();
85 
86 
93  void remove(const std::string & name);
94 
95  cat_directory * get_parent() const { return parent; };
96  bool search_children(const std::string &name, const cat_nomme *&ref) const;
97  bool callback_for_children_of(user_interaction & dialog, const std::string & sdir, bool isolated = false) const;
98 
99  // using is_more_recent_than() from cat_inode class
100  // using method has_changed_since() from cat_inode class
101  unsigned char signature() const { return mk_signature('d', get_saved_status()); };
102 
104  bool get_recursive_has_changed() const { return recursive_has_changed; };
105 
107  void recursive_has_changed_update() const;
108 
110  infinint get_tree_size() const;
111 
113  infinint get_tree_ea_num() const;
114 
117 
118  // for each mirage found (hard link implementation) in the cat_directory tree, add its etiquette to the returned
119  // list with the number of reference that has been found in the tree. (map[etiquette] = number of occurence)
120  // from outside of class cat_directory, the given argument is expected to be an empty map.
121  void get_etiquettes_found_in_tree(std::map<infinint, infinint> & already_found) const;
122 
124  bool is_empty() const { return ordered_fils.empty(); };
125 
128 
131 
132  cat_entree *clone() const { return new (get_pool()) cat_directory(*this); };
133 
134  const infinint & get_size() const { recursive_update_sizes(); return x_size; };
135  const infinint & get_storage_size() const { recursive_update_sizes(); return x_storage_size; };
136 
137  void recursively_set_to_unsaved_data_and_FSA();
138 
140  void change_location(const pile_descriptor & pdesc);
141 
142  protected:
143  void inherited_dump(const pile_descriptor & pdesc, bool small) const;
144 
145  private:
146  static const cat_eod fin;
147 
148  infinint x_size;
149  infinint x_storage_size;
150  bool updated_sizes;
151  cat_directory *parent;
152 #ifdef LIBDAR_FAST_DIR
153  std::map<std::string, cat_nomme *> fils; // used for fast lookup
154 #endif
155  std::list<cat_nomme *> ordered_fils;
156  std::list<cat_nomme *>::iterator it; //< next to entry to be returned by read_children
157  bool recursive_has_changed;
158 
159  void clear();
160  void recursive_update_sizes() const;
161  void recursive_flag_size_to_update() const;
162  };
163 
165 
166 } // end of namespace
167 
168 #endif
holds the statistics contents of a catalogue
Definition: cat_entree.hpp:60
void change_location(const pile_descriptor &pdesc)
overwrite virtual method of cat_entree to propagate the action to all entries of the directory tree ...
This is a pure virtual class that is used by libdar when interaction with the user is required...
infinint get_tree_mirage_num() const
get the number of entry that are hard linked inode (aka mirage in dar implementation) (recursive call...
void recursive_has_changed_update() const
ask recursive update for the recursive_has_changed field
infinint get_tree_ea_num() const
get the number of entry having some EA set in the cat_directory tree (recursive call) ...
bool operator==(const cat_entree &ref) const
attention this compares only the directories themselves, not the list of their children ...
the cat_directory inode class
bool is_empty() const
whether this cat_directory is empty or not
memory_pool * get_pool() const
Definition: on_pool.hpp:144
infinint get_tree_size() const
get then number of "cat_nomme" entry contained in this cat_directory and subdirectories (recursive ca...
the base class for all entry that have a name
Definition: cat_nomme.hpp:44
void remove_all_mirages_and_reduce_dirs()
recursively remove all mirage entries
exception used to signal a bug. A bug is triggered when reaching some code that should never be reach...
Definition: erreurs.hpp:137
compression
the different compression algorithm available
Definition: compressor.hpp:43
unsigned char signature() const
inherited class signature
bool get_recursive_has_changed() const
detemine whether some data has changed since archive of reference in this cat_directory or subdirecto...
the root class for all cat_inode
Definition: cat_inode.hpp:54
base object for all inode types, managed EA and FSA, dates, permissions, ownership, ...
the arbitrary large positive integer class
void inherited_dump(const pile_descriptor &pdesc, bool small) const
inherited class may overload this method but shall first call the parent's inherited_dump() in the ov...
void set_all_mirage_s_inode_dumped_field_to(bool val)
set the value of inode_dumped for all mirage (recusively)
class archive_version manages the version of the archive format
the root class from all other inherite for any entry in the catalogue
Definition: cat_entree.hpp:84
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47
cat_entree * clone() const
a way to copy the exact type of an object even if pointed to by a parent class pointer ...