Disk ARchive  2.4.2
 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 // $Id: data_tree.hpp,v 1.5.2.2 2011/06/20 14:02:03 edrusb Rel $
22 //
23 /*********************************************************************/
24 
28 
29 
30 #ifndef DATA_TREE_HPP
31 #define DATA_TREE_HPP
32 
33 #include "../my_config.h"
34 
35 #include <map>
36 #include <string>
37 #include <list>
38 #include "infinint.hpp"
39 #include "generic_file.hpp"
40 #include "infinint.hpp"
41 #include "catalogue.hpp"
42 #include "special_alloc.hpp"
43 #include "user_interaction.hpp"
44 #include "path.hpp"
45 
46 namespace libdar
47 {
48 
51 
52  typedef U_16 archive_num;
53 #define ARCHIVE_NUM_MAX 65534
54 
56 
60  class data_tree
61  {
62  public:
63  enum lookup { found_present, found_removed, not_found, not_restorable };
64  enum etat
65  {
66  et_saved, //< data/EA present in the archive
67  et_present, //< file/EA present in the archive but data not saved (differential backup)
68  et_removed //< file/EA stored as deleted since archive of reference of file/EA not present in the archive
69  };
70 
71  data_tree(const std::string &name);
72  data_tree(generic_file &f, unsigned char db_version);
73  virtual ~data_tree() {};
74 
75  virtual void dump(generic_file & f) const;
76  std::string get_name() const { return filename; };
77  void set_name(const std::string & name) { filename = name; };
78 
80  lookup get_data(archive_num & archive, const infinint & date, bool even_when_removed) const;
81 
83  lookup get_EA(archive_num & archive, const infinint & date, bool even_when_removed) const;
84 
86  bool read_data(archive_num num, infinint & val, etat & present) const;
87 
89  bool read_EA(archive_num num, infinint & val, etat & present) const;
90 
91  void set_data(const archive_num & archive, const infinint & date, etat present) { status sta = { date, present }; last_mod[archive] = sta; };
92  void set_EA(const archive_num & archive, const infinint & date, etat present) { status sta = { date, present }; last_change[archive] = sta; };
93 
95  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); };
96 
98  virtual void finalize(const archive_num & archive, const infinint & deleted_date);
99 
101  virtual bool remove_all_from(const archive_num & archive_to_remove, const archive_num & last_archive);
102 
104  void listing(user_interaction & dialog) const;
105  virtual void apply_permutation(archive_num src, archive_num dst);
106 
108  virtual void skip_out(archive_num num);
109  virtual void compute_most_recent_stats(std::vector<infinint> & data,
110  std::vector<infinint> & ea,
111  std::vector<infinint> & total_data,
112  std::vector<infinint> & total_ea) const;
113 
114  virtual char obj_signature() const { return signature(); };
115  static char signature() { return 't'; };
116 
117 #ifdef LIBDAR_SPECIAL_ALLOC
118  void *operator new(size_t taille) { return special_alloc_new(taille); };
119  void operator delete(void *ptr) { special_alloc_delete(ptr); };
120 #endif
121  private:
122  struct status
123  {
124  infinint date; //< date of the event
125  etat present; //< file's status in the archive
126  void dump(generic_file & f) const; //< write the struct to file
127  void read(generic_file &f); //< set the struct from file
128  };
129 
130 
131  std::string filename;
132  std::map<archive_num, status> last_mod; //< key is archive number ; value is last_mod time
133  std::map<archive_num, status> last_change; //< key is archive number ; value is last_change time
134 
135 
136  // when false is returned, this means that the user wants to ignore subsequent error of the same type
137  // else either no error yet met or user want to continue receiving the same type of error for other files
138  // in that later case initial_warn is set to false (first warning has been shown).
139  bool check_map_order(user_interaction & dialog,
140  const std::map<archive_num, status> the_map,
141  const path & current_path,
142  const std::string & field_nature,
143  bool & initial_warn) const;
144  };
145 
147 
149  class data_dir : public data_tree
150  {
151  public:
152  data_dir(const std::string &name);
153  data_dir(generic_file &f, unsigned char db_version);
154  data_dir(const data_dir & ref);
155  data_dir(const data_tree & ref);
156  ~data_dir();
157 
158  void dump(generic_file & f) const;
159 
160  void add(const inode *entry, const archive_num & archive);
161  void add(const detruit *entry, const archive_num & archive);
162  const data_tree *read_child(const std::string & name) const;
163  void read_all_children(std::vector<std::string> & fils) const;
164  virtual void finalize_except_self(const archive_num & archive, const infinint & deleted_date);
165 
166  // inherited methods
167  bool check_order(user_interaction & dialog, const path & current_path, bool & initial_warn) const;
168  void finalize(const archive_num & archive, const infinint & deleted_date);
169  bool remove_all_from(const archive_num & archive_to_remove, const archive_num & last_archive);
170 
172  void show(user_interaction & dialog, archive_num num, std::string marge = "") const;
173  void apply_permutation(archive_num src, archive_num dst);
174  void skip_out(archive_num num);
175  void compute_most_recent_stats(std::vector<infinint> & data, std::vector<infinint> & ea,
176  std::vector<infinint> & total_data, std::vector<infinint> & total_ea) const;
177 
178  char obj_signature() const { return signature(); };
179  static char signature() { return 'd'; };
180 
181 #ifdef LIBDAR_SPECIAL_ALLOC
182  void *operator new(size_t taille) { return special_alloc_new(taille); };
183  void operator delete(void *ptr) { special_alloc_delete(ptr); };
184 #endif
185 
186  private:
187  std::list<data_tree *> rejetons; //< subdir and subfiles of the current dir
188 
189  void add_child(data_tree *fils); //< "this" is now responsible of "fils" disalocation
190  void remove_child(const std::string & name);
191  data_tree *find_or_addition(const std::string & name, bool is_dir, const archive_num & archive);
192  };
193 
194  extern data_dir *data_tree_read(generic_file & f, unsigned char db_version);
195 
197 
202  extern bool data_tree_find(path chemin, const data_dir & racine, const data_tree *& ptr);
203  extern void data_tree_update_with(const directory *dir, archive_num archive, data_dir *racine);
204  extern archive_num data_tree_permutation(archive_num src, archive_num dst, archive_num x);
205 
207 
208 } // end of namespace
209 
210 #endif