Disk ARchive  2.4.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
data_tree.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 
27 #ifndef DATA_TREE_HPP
28 #define DATA_TREE_HPP
29 
30 #include "../my_config.h"
31 
32 #include <map>
33 #include <string>
34 #include <list>
35 #include "infinint.hpp"
36 #include "generic_file.hpp"
37 #include "infinint.hpp"
38 #include "catalogue.hpp"
39 #include "special_alloc.hpp"
40 #include "user_interaction.hpp"
41 #include "path.hpp"
42 
43 namespace libdar
44 {
45 
48 
49  typedef U_16 archive_num;
50 #define ARCHIVE_NUM_MAX 65534
51 
53 
57  class data_tree
58  {
59  public:
60  enum lookup { found_present, found_removed, not_found, not_restorable };
61  enum etat
62  {
63  et_saved, //< data/EA present in the archive
64  et_present, //< file/EA present in the archive but data not saved (differential backup)
65  et_removed, //< file/EA stored as deleted since archive of reference of file/EA not present in the archive
66  et_absent //< file not even mentionned in the archive, This entry is equivalent to et_removed, but is required to be able to properly re-order the archive when user asks to do so. The dates associated to this state are computed from neighbor archives in the database
67  };
68 
69  data_tree(const std::string &name);
70  data_tree(generic_file &f, unsigned char db_version);
71  virtual ~data_tree() {};
72 
73  virtual void dump(generic_file & f) const;
74  std::string get_name() const { return filename; };
75  void set_name(const std::string & name) { filename = name; };
76 
78  lookup get_data(archive_num & archive, const infinint & date, bool even_when_removed) const;
79 
81  lookup get_EA(archive_num & archive, const infinint & date, bool even_when_removed) const;
82 
84  bool read_data(archive_num num, infinint & val, etat & present) const;
85 
87  bool read_EA(archive_num num, infinint & val, etat & present) const;
88 
89  void set_data(const archive_num & archive, const infinint & date, etat present) { status sta = { date, present }; last_mod[archive] = sta; };
90  void set_EA(const archive_num & archive, const infinint & date, etat present) { status sta = { date, present }; last_change[archive] = sta; };
91 
93  virtual bool check_order(user_interaction & dialog, const path & current_path, bool & initial_warn) const { return check_map_order(dialog, last_mod, current_path, "data", initial_warn) && check_map_order(dialog, last_change, current_path, "EA", initial_warn); };
94 
96 
104  virtual void finalize(const archive_num & archive,
105  const infinint & deleted_date,
106  const archive_num & ignore_archive_greater_or_equal);
107 
109  virtual bool remove_all_from(const archive_num & archive_to_remove, const archive_num & last_archive);
110 
112  void listing(user_interaction & dialog) const;
113  virtual void apply_permutation(archive_num src, archive_num dst);
114 
116  virtual void skip_out(archive_num num);
117  virtual void compute_most_recent_stats(std::vector<infinint> & data,
118  std::vector<infinint> & ea,
119  std::vector<infinint> & total_data,
120  std::vector<infinint> & total_ea) const;
121 
122  virtual char obj_signature() const { return signature(); };
123  static char signature() { return 't'; };
124 
125 #ifdef LIBDAR_SPECIAL_ALLOC
126  USE_SPECIAL_ALLOC(data_tree);
127 #endif
128  private:
129  struct status
130  {
131  infinint date; //< date of the event
132  etat present; //< file's status in the archive
133  void dump(generic_file & f) const; //< write the struct to file
134  void read(generic_file &f); //< set the struct from file
135  };
136 
137 
138  std::string filename;
139  std::map<archive_num, status> last_mod; //< key is archive number ; value is last_mod time
140  std::map<archive_num, status> last_change; //< key is archive number ; value is last_change time
141 
142 
143  // when false is returned, this means that the user wants to ignore subsequent error of the same type
144  // else either no error yet met or user want to continue receiving the same type of error for other files
145  // in that later case initial_warn is set to false (first warning has been shown).
146  bool check_map_order(user_interaction & dialog,
147  const std::map<archive_num, status> the_map,
148  const path & current_path,
149  const std::string & field_nature,
150  bool & initial_warn) const;
151  };
152 
154 
156  class data_dir : public data_tree
157  {
158  public:
159  data_dir(const std::string &name);
160  data_dir(generic_file &f, unsigned char db_version);
161  data_dir(const data_dir & ref);
162  data_dir(const data_tree & ref);
163  ~data_dir();
164 
165  void dump(generic_file & f) const;
166 
167  void add(const inode *entry, const archive_num & archive);
168  void add(const detruit *entry, const archive_num & archive);
169  const data_tree *read_child(const std::string & name) const;
170  void read_all_children(std::vector<std::string> & fils) const;
171  virtual void finalize_except_self(const archive_num & archive,
172  const infinint & deleted_date,
173  const archive_num & ignore_archives_greater_or_equal);
174 
175  // inherited methods
176  bool check_order(user_interaction & dialog, const path & current_path, bool & initial_warn) const;
177  void finalize(const archive_num & archive, const infinint & deleted_date, const archive_num & ignore_archives_greater_or_equal);
178  bool remove_all_from(const archive_num & archive_to_remove, const archive_num & last_archive);
179 
181  void show(user_interaction & dialog, archive_num num, std::string marge = "") const;
182  void apply_permutation(archive_num src, archive_num dst);
183  void skip_out(archive_num num);
184  void compute_most_recent_stats(std::vector<infinint> & data, std::vector<infinint> & ea,
185  std::vector<infinint> & total_data, std::vector<infinint> & total_ea) const;
186 
187  char obj_signature() const { return signature(); };
188  static char signature() { return 'd'; };
189 
190 #ifdef LIBDAR_SPECIAL_ALLOC
191  USE_SPECIAL_ALLOC(data_dir);
192 #endif
193  private:
194  std::list<data_tree *> rejetons; //< subdir and subfiles of the current dir
195 
196  void add_child(data_tree *fils); //< "this" is now responsible of "fils" disalocation
197  void remove_child(const std::string & name);
198  data_tree *find_or_addition(const std::string & name, bool is_dir, const archive_num & archive);
199  };
200 
201  extern data_dir *data_tree_read(generic_file & f, unsigned char db_version);
202 
204 
209  extern bool data_tree_find(path chemin, const data_dir & racine, const data_tree *& ptr);
210  extern void data_tree_update_with(const directory *dir, archive_num archive, data_dir *racine);
211  extern archive_num data_tree_permutation(archive_num src, archive_num dst, archive_num x);
212 
214 
215 } // end of namespace
216 
217 #endif
virtual bool check_order(user_interaction &dialog, const path &current_path, bool &initial_warn) const
check date order between archives withing the database ; throw Erange if problem found with date orde...
Definition: data_tree.hpp:93
lookup get_data(archive_num &archive, const infinint &date, bool even_when_removed) const
return the archive where to find the data that was defined just before or at the given date ...
lookup get_EA(archive_num &archive, const infinint &date, bool even_when_removed) const
if EA has been saved alone later, returns in which version for the state of the file at the given dat...
the data_dir class inherits from data_tree and holds the directory tree's parent relationship ...
Definition: data_tree.hpp:156
class generic_file is defined here as well as class fichierthe generic_file interface is widely used ...
the deleted file entry
Definition: catalogue.hpp:905
bool check_order(user_interaction &dialog, const path &current_path, bool &initial_warn) const
check date order between archives withing the database ; throw Erange if problem found with date orde...
bool ea()
returns whether EA support has been activated at compilation time
the data_tree class stores presence of a given file in a set of archives
Definition: data_tree.hpp:57
void finalize(const archive_num &archive, const infinint &deleted_date, const archive_num &ignore_archives_greater_or_equal)
add deleted entry if no object of the current archive exist and the entry of the previous archive is ...
This is a pure virtual class that is used by libdar when interaction with the user is required...
void skip_out(archive_num num)
decrement archive numbers above num
re-definition of new and delete class operatorthis is a set of macro that makes the new and delete op...
the directory inode class
Definition: catalogue.hpp:652
void listing(user_interaction &dialog) const
list where is saved this file
bool data_tree_find(path chemin, const data_dir &racine, const data_tree *&ptr)
lookup routine to find a pointer to the dat_dir object corresponding to the given path ...
the archive class realizes the most general operations on archives
Definition: archive.hpp:49
defines the interaction between libdar and the user.Three classes are defined
here is the definition of the path classthe path class handle path and provide several operation on t...
the root class for all inode
Definition: catalogue.hpp:202
virtual void skip_out(archive_num num)
decrement archive numbers above num
virtual void finalize(const archive_num &archive, const infinint &deleted_date, const archive_num &ignore_archive_greater_or_equal)
add deleted entry if no object of the current archive exist and the entry of the previous archive is ...
switch module to limitint (32 ou 64 bits integers) or infinint
void show(user_interaction &dialog, archive_num num, std::string marge="") const
list the most recent files owned by that archive (or by any archive if num == 0)
bool remove_all_from(const archive_num &archive_to_remove, const archive_num &last_archive)
return true if the corresponding file is no more located in any archive (thus, the object is no more ...
this is the interface class from which all other data transfer classes inherit
the arbitrary large positive integer class
bool read_data(archive_num num, infinint &val, etat &present) const
return the date of file's last modification date within the give archive and whether the file has bee...
U_16 archive_num
Definition: data_tree.hpp:49
bool read_EA(archive_num num, infinint &val, etat &present) const
return the date of last inode change and whether the EA has been saved or deleted ...
virtual bool remove_all_from(const archive_num &archive_to_remove, const archive_num &last_archive)
return true if the corresponding file is no more located in any archive (thus, the object is no more ...
here is defined the many classed which is build of the catalogue
the class path is here to manipulate paths in the Unix notation: using'/'
Definition: path.hpp:50