00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00025
00026
00027 #ifndef DATA_TREE_HPP
00028 #define DATA_TREE_HPP
00029
00030 #include "../my_config.h"
00031
00032 #include <map>
00033 #include <string>
00034 #include <list>
00035 #include "infinint.hpp"
00036 #include "generic_file.hpp"
00037 #include "infinint.hpp"
00038 #include "catalogue.hpp"
00039 #include "special_alloc.hpp"
00040 #include "user_interaction.hpp"
00041 #include "path.hpp"
00042
00043 namespace libdar
00044 {
00045
00048
00049 typedef U_16 archive_num;
00050 #define ARCHIVE_NUM_MAX 65534
00051
00053
00057 class data_tree
00058 {
00059 public:
00060 enum lookup { found_present, found_removed, not_found, not_restorable };
00061 enum etat
00062 {
00063 et_saved,
00064 et_present,
00065 et_removed,
00066 et_absent
00067 };
00068
00069 data_tree(const std::string &name);
00070 data_tree(generic_file &f, unsigned char db_version);
00071 virtual ~data_tree() {};
00072
00073 virtual void dump(generic_file & f) const;
00074 std::string get_name() const { return filename; };
00075 void set_name(const std::string & name) { filename = name; };
00076
00078 lookup get_data(archive_num & archive, const infinint & date, bool even_when_removed) const;
00079
00081 lookup get_EA(archive_num & archive, const infinint & date, bool even_when_removed) const;
00082
00084 bool read_data(archive_num num, infinint & val, etat & present) const;
00085
00087 bool read_EA(archive_num num, infinint & val, etat & present) const;
00088
00089 void set_data(const archive_num & archive, const infinint & date, etat present) { status sta = { date, present }; last_mod[archive] = sta; };
00090 void set_EA(const archive_num & archive, const infinint & date, etat present) { status sta = { date, present }; last_change[archive] = sta; };
00091
00093 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); };
00094
00096
00104 virtual void finalize(const archive_num & archive,
00105 const infinint & deleted_date,
00106 const archive_num & ignore_archive_greater_or_equal);
00107
00109 virtual bool remove_all_from(const archive_num & archive_to_remove, const archive_num & last_archive);
00110
00112 void listing(user_interaction & dialog) const;
00113 virtual void apply_permutation(archive_num src, archive_num dst);
00114
00116 virtual void skip_out(archive_num num);
00117 virtual void compute_most_recent_stats(std::vector<infinint> & data,
00118 std::vector<infinint> & ea,
00119 std::vector<infinint> & total_data,
00120 std::vector<infinint> & total_ea) const;
00121
00122 virtual char obj_signature() const { return signature(); };
00123 static char signature() { return 't'; };
00124
00125 #ifdef LIBDAR_SPECIAL_ALLOC
00126 USE_SPECIAL_ALLOC(data_tree);
00127 #endif
00128
00129 virtual bool fix_corruption();
00130
00131 private:
00132 struct status
00133 {
00134 infinint date;
00135 etat present;
00136 void dump(generic_file & f) const;
00137 void read(generic_file &f);
00138 };
00139
00140
00141 std::string filename;
00142 std::map<archive_num, status> last_mod;
00143 std::map<archive_num, status> last_change;
00144
00145
00146
00147
00148
00149 bool check_map_order(user_interaction & dialog,
00150 const std::map<archive_num, status> the_map,
00151 const path & current_path,
00152 const std::string & field_nature,
00153 bool & initial_warn) const;
00154 };
00155
00157
00159 class data_dir : public data_tree
00160 {
00161 public:
00162 data_dir(const std::string &name);
00163 data_dir(generic_file &f, unsigned char db_version);
00164 data_dir(const data_dir & ref);
00165 data_dir(const data_tree & ref);
00166 ~data_dir();
00167
00168 void dump(generic_file & f) const;
00169
00170 void add(const inode *entry, const archive_num & archive);
00171 void add(const detruit *entry, const archive_num & archive);
00172 const data_tree *read_child(const std::string & name) const;
00173 void read_all_children(std::vector<std::string> & fils) const;
00174 virtual void finalize_except_self(const archive_num & archive,
00175 const infinint & deleted_date,
00176 const archive_num & ignore_archives_greater_or_equal);
00177
00178
00179 bool check_order(user_interaction & dialog, const path & current_path, bool & initial_warn) const;
00180 void finalize(const archive_num & archive, const infinint & deleted_date, const archive_num & ignore_archives_greater_or_equal);
00181 bool remove_all_from(const archive_num & archive_to_remove, const archive_num & last_archive);
00182
00184 void show(user_interaction & dialog, archive_num num, std::string marge = "") const;
00185 void apply_permutation(archive_num src, archive_num dst);
00186 void skip_out(archive_num num);
00187 void compute_most_recent_stats(std::vector<infinint> & data, std::vector<infinint> & ea,
00188 std::vector<infinint> & total_data, std::vector<infinint> & total_ea) const;
00189
00190 char obj_signature() const { return signature(); };
00191 static char signature() { return 'd'; };
00192
00193 #ifdef LIBDAR_SPECIAL_ALLOC
00194 USE_SPECIAL_ALLOC(data_dir);
00195 #endif
00196
00197 virtual bool fix_corruption();
00198
00199
00200 private:
00201 std::list<data_tree *> rejetons;
00202
00203 void add_child(data_tree *fils);
00204 void remove_child(const std::string & name);
00205 data_tree *find_or_addition(const std::string & name, bool is_dir, const archive_num & archive);
00206 };
00207
00208 extern data_dir *data_tree_read(generic_file & f, unsigned char db_version);
00209
00211
00216 extern bool data_tree_find(path chemin, const data_dir & racine, const data_tree *& ptr);
00217 extern void data_tree_update_with(const directory *dir, archive_num archive, data_dir *racine);
00218 extern archive_num data_tree_permutation(archive_num src, archive_num dst, archive_num x);
00219
00221
00222 }
00223
00224 #endif