Disk ARchive
2.4.5
|
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$ 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 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 00070 }; 00071 00072 data_tree(const std::string &name); 00073 data_tree(generic_file &f, unsigned char db_version); 00074 virtual ~data_tree() {}; 00075 00076 virtual void dump(generic_file & f) const; 00077 std::string get_name() const { return filename; }; 00078 void set_name(const std::string & name) { filename = name; }; 00079 00081 lookup get_data(archive_num & archive, const infinint & date, bool even_when_removed) const; 00082 00084 lookup get_EA(archive_num & archive, const infinint & date, bool even_when_removed) const; 00085 00087 bool read_data(archive_num num, infinint & val, etat & present) const; 00088 00090 bool read_EA(archive_num num, infinint & val, etat & present) const; 00091 00092 void set_data(const archive_num & archive, const infinint & date, etat present) { status sta = { date, present }; last_mod[archive] = sta; }; 00093 void set_EA(const archive_num & archive, const infinint & date, etat present) { status sta = { date, present }; last_change[archive] = sta; }; 00094 00096 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); }; 00097 00099 00107 virtual void finalize(const archive_num & archive, 00108 const infinint & deleted_date, 00109 const archive_num & ignore_archive_greater_or_equal); 00110 00112 virtual bool remove_all_from(const archive_num & archive_to_remove, const archive_num & last_archive); 00113 00115 void listing(user_interaction & dialog) const; 00116 virtual void apply_permutation(archive_num src, archive_num dst); 00117 00119 virtual void skip_out(archive_num num); 00120 virtual void compute_most_recent_stats(std::vector<infinint> & data, 00121 std::vector<infinint> & ea, 00122 std::vector<infinint> & total_data, 00123 std::vector<infinint> & total_ea) const; 00124 00125 virtual char obj_signature() const { return signature(); }; 00126 static char signature() { return 't'; }; 00127 00128 #ifdef LIBDAR_SPECIAL_ALLOC 00129 USE_SPECIAL_ALLOC(data_tree); 00130 #endif 00131 private: 00132 struct status 00133 { 00134 infinint date; //< date of the event 00135 etat present; //< file's status in the archive 00136 void dump(generic_file & f) const; //< write the struct to file 00137 void read(generic_file &f); //< set the struct from file 00138 }; 00139 00140 00141 std::string filename; 00142 std::map<archive_num, status> last_mod; //< key is archive number ; value is last_mod time 00143 std::map<archive_num, status> last_change; //< key is archive number ; value is last_change time 00144 00145 00146 // when false is returned, this means that the user wants to ignore subsequent error of the same type 00147 // else either no error yet met or user want to continue receiving the same type of error for other files 00148 // in that later case initial_warn is set to false (first warning has been shown). 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 // inherited methods 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 private: 00197 std::list<data_tree *> rejetons; //< subdir and subfiles of the current dir 00198 00199 void add_child(data_tree *fils); //< "this" is now responsible of "fils" disalocation 00200 void remove_child(const std::string & name); 00201 data_tree *find_or_addition(const std::string & name, bool is_dir, const archive_num & archive); 00202 }; 00203 00204 extern data_dir *data_tree_read(generic_file & f, unsigned char db_version); 00205 00207 00212 extern bool data_tree_find(path chemin, const data_dir & racine, const data_tree *& ptr); 00213 extern void data_tree_update_with(const directory *dir, archive_num archive, data_dir *racine); 00214 extern archive_num data_tree_permutation(archive_num src, archive_num dst, archive_num x); 00215 00217 00218 } // end of namespace 00219 00220 #endif