Disk ARchive
2.4.2
|
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 // $Id: data_tree.hpp,v 1.5.2.2 2011/06/20 14:02:03 edrusb Rel $ 00022 // 00023 /*********************************************************************/ 00024 00028 00029 00030 #ifndef DATA_TREE_HPP 00031 #define DATA_TREE_HPP 00032 00033 #include "../my_config.h" 00034 00035 #include <map> 00036 #include <string> 00037 #include <list> 00038 #include "infinint.hpp" 00039 #include "generic_file.hpp" 00040 #include "infinint.hpp" 00041 #include "catalogue.hpp" 00042 #include "special_alloc.hpp" 00043 #include "user_interaction.hpp" 00044 #include "path.hpp" 00045 00046 namespace libdar 00047 { 00048 00051 00052 typedef U_16 archive_num; 00053 #define ARCHIVE_NUM_MAX 65534 00054 00056 00060 class data_tree 00061 { 00062 public: 00063 enum lookup { found_present, found_removed, not_found, not_restorable }; 00064 enum etat 00065 { 00066 et_saved, //< data/EA present in the archive 00067 et_present, //< file/EA present in the archive but data not saved (differential backup) 00068 et_removed //< file/EA stored as deleted since archive of reference of file/EA not present in the archive 00069 }; 00070 00071 data_tree(const std::string &name); 00072 data_tree(generic_file &f, unsigned char db_version); 00073 virtual ~data_tree() {}; 00074 00075 virtual void dump(generic_file & f) const; 00076 std::string get_name() const { return filename; }; 00077 void set_name(const std::string & name) { filename = name; }; 00078 00080 lookup get_data(archive_num & archive, const infinint & date, bool even_when_removed) const; 00081 00083 lookup get_EA(archive_num & archive, const infinint & date, bool even_when_removed) const; 00084 00086 bool read_data(archive_num num, infinint & val, etat & present) const; 00087 00089 bool read_EA(archive_num num, infinint & val, etat & present) const; 00090 00091 void set_data(const archive_num & archive, const infinint & date, etat present) { status sta = { date, present }; last_mod[archive] = sta; }; 00092 void set_EA(const archive_num & archive, const infinint & date, etat present) { status sta = { date, present }; last_change[archive] = sta; }; 00093 00095 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); }; 00096 00098 virtual void finalize(const archive_num & archive, const infinint & deleted_date); 00099 00101 virtual bool remove_all_from(const archive_num & archive_to_remove, const archive_num & last_archive); 00102 00104 void listing(user_interaction & dialog) const; 00105 virtual void apply_permutation(archive_num src, archive_num dst); 00106 00108 virtual void skip_out(archive_num num); 00109 virtual void compute_most_recent_stats(std::vector<infinint> & data, 00110 std::vector<infinint> & ea, 00111 std::vector<infinint> & total_data, 00112 std::vector<infinint> & total_ea) const; 00113 00114 virtual char obj_signature() const { return signature(); }; 00115 static char signature() { return 't'; }; 00116 00117 #ifdef LIBDAR_SPECIAL_ALLOC 00118 void *operator new(size_t taille) { return special_alloc_new(taille); }; 00119 void operator delete(void *ptr) { special_alloc_delete(ptr); }; 00120 #endif 00121 private: 00122 struct status 00123 { 00124 infinint date; //< date of the event 00125 etat present; //< file's status in the archive 00126 void dump(generic_file & f) const; //< write the struct to file 00127 void read(generic_file &f); //< set the struct from file 00128 }; 00129 00130 00131 std::string filename; 00132 std::map<archive_num, status> last_mod; //< key is archive number ; value is last_mod time 00133 std::map<archive_num, status> last_change; //< key is archive number ; value is last_change time 00134 00135 00136 // when false is returned, this means that the user wants to ignore subsequent error of the same type 00137 // else either no error yet met or user want to continue receiving the same type of error for other files 00138 // in that later case initial_warn is set to false (first warning has been shown). 00139 bool check_map_order(user_interaction & dialog, 00140 const std::map<archive_num, status> the_map, 00141 const path & current_path, 00142 const std::string & field_nature, 00143 bool & initial_warn) const; 00144 }; 00145 00147 00149 class data_dir : public data_tree 00150 { 00151 public: 00152 data_dir(const std::string &name); 00153 data_dir(generic_file &f, unsigned char db_version); 00154 data_dir(const data_dir & ref); 00155 data_dir(const data_tree & ref); 00156 ~data_dir(); 00157 00158 void dump(generic_file & f) const; 00159 00160 void add(const inode *entry, const archive_num & archive); 00161 void add(const detruit *entry, const archive_num & archive); 00162 const data_tree *read_child(const std::string & name) const; 00163 void read_all_children(std::vector<std::string> & fils) const; 00164 virtual void finalize_except_self(const archive_num & archive, const infinint & deleted_date); 00165 00166 // inherited methods 00167 bool check_order(user_interaction & dialog, const path & current_path, bool & initial_warn) const; 00168 void finalize(const archive_num & archive, const infinint & deleted_date); 00169 bool remove_all_from(const archive_num & archive_to_remove, const archive_num & last_archive); 00170 00172 void show(user_interaction & dialog, archive_num num, std::string marge = "") const; 00173 void apply_permutation(archive_num src, archive_num dst); 00174 void skip_out(archive_num num); 00175 void compute_most_recent_stats(std::vector<infinint> & data, std::vector<infinint> & ea, 00176 std::vector<infinint> & total_data, std::vector<infinint> & total_ea) const; 00177 00178 char obj_signature() const { return signature(); }; 00179 static char signature() { return 'd'; }; 00180 00181 #ifdef LIBDAR_SPECIAL_ALLOC 00182 void *operator new(size_t taille) { return special_alloc_new(taille); }; 00183 void operator delete(void *ptr) { special_alloc_delete(ptr); }; 00184 #endif 00185 00186 private: 00187 std::list<data_tree *> rejetons; //< subdir and subfiles of the current dir 00188 00189 void add_child(data_tree *fils); //< "this" is now responsible of "fils" disalocation 00190 void remove_child(const std::string & name); 00191 data_tree *find_or_addition(const std::string & name, bool is_dir, const archive_num & archive); 00192 }; 00193 00194 extern data_dir *data_tree_read(generic_file & f, unsigned char db_version); 00195 00197 00202 extern bool data_tree_find(path chemin, const data_dir & racine, const data_tree *& ptr); 00203 extern void data_tree_update_with(const directory *dir, archive_num archive, data_dir *racine); 00204 extern archive_num data_tree_permutation(archive_num src, archive_num dst, archive_num x); 00205 00207 00208 } // end of namespace 00209 00210 #endif