Disk ARchive  2.5.2
Full featured and portable backup and archiving tool
data_tree.hpp
Go to the documentation of this file.
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 
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 "user_interaction.hpp"
00039 #include "path.hpp"
00040 #include "on_pool.hpp"
00041 #include "cat_directory.hpp"
00042 #include "cat_inode.hpp"
00043 #include "cat_detruit.hpp"
00044 
00045 namespace libdar
00046 {
00047 
00050 
00051     typedef U_16 archive_num;
00052 #define ARCHIVE_NUM_MAX  65534
00053 
00055 
00059     class data_tree : public on_pool
00060     {
00061     public:
00062     enum lookup { found_present, found_removed, not_found, not_restorable };
00063     enum etat
00064     {
00065         et_saved,    //< data/EA present in the archive
00066         et_present,  //< file/EA present in the archive but data not saved (differential backup)
00067         et_removed,  //< file/EA stored as deleted since archive of reference of file/EA not present in the archive
00068         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
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 datetime & date, bool even_when_removed) const;
00081 
00083     lookup get_EA(archive_num & archive, const datetime & date, bool even_when_removed) const;
00084 
00086     bool read_data(archive_num num, datetime & val, etat & present) const;
00087 
00089     bool read_EA(archive_num num, datetime & val, etat & present) const;
00090 
00091     void set_data(const archive_num & archive, const datetime & date, etat present) { status sta = { date, present }; last_mod[archive] = sta; };
00092     void set_EA(const archive_num & archive, const datetime & 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 
00106     virtual void finalize(const archive_num & archive,
00107                   const datetime & deleted_date,
00108                   const archive_num & ignore_archive_greater_or_equal);
00109 
00111     virtual bool remove_all_from(const archive_num & archive_to_remove, const archive_num & last_archive);
00112 
00114     void listing(user_interaction & dialog) const;
00115     virtual void apply_permutation(archive_num src, archive_num dst);
00116 
00118     virtual void skip_out(archive_num num);
00119     virtual void compute_most_recent_stats(std::vector<infinint> & data,
00120                            std::vector<infinint> & ea,
00121                            std::vector<infinint> & total_data,
00122                            std::vector<infinint> & total_ea) const;
00123 
00124     virtual char obj_signature() const { return signature(); };
00125     static char signature() { return 't'; };
00126 
00127         // fix corruption case that was brought by bug in release 2.4.0 to 2.4.9
00128     virtual bool fix_corruption(); // return true whether corruption could be fixed (meaning this entry can be safely removed from base)
00129 
00130     private:
00131     struct status
00132     {
00133         datetime date;                     //< date of the event
00134         etat present;                      //< file's status in the archive
00135         void dump(generic_file & f) const; //< write the struct to file
00136         void read(generic_file &f,         //< set the struct from file
00137               unsigned char db_version);
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 cat_inode *entry, const archive_num & archive);
00171     void add(const cat_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 datetime & 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 datetime & 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     virtual bool fix_corruption(); // inherited from data_tree
00194 
00195 
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, memory_pool *pool);
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 cat_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
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines