Disk ARchive  2.4.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
.pc/delete2/data_tree.hpp
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 : dar.linux@free.fr
00020 /*********************************************************************/
00021 // $Id$
00022 //
00023 /*********************************************************************/
00024 
00025 #ifndef DATA_TREE_HPP
00026 #define DATA_TREE_HPP
00027 
00028 #include <map>
00029 #include <string>
00030 #include <list>
00031 #include "generic_file.hpp"
00032 #include "infinint.hpp"
00033 #include "catalogue.hpp"
00034 
00035 typedef U_16 archive_num;
00036 #define ARCHIVE_NUM_MAX  65534
00037 
00038 class data_tree
00039 {
00040 public:
00041 
00042     data_tree(const string &name);
00043     data_tree(generic_file &f);
00044     virtual ~data_tree() {};
00045 
00046     virtual void dump(generic_file & f) const;
00047     string get_name() const { return filename; };
00048     bool get_data(archive_num & archive) const; // return the archive where to find the most recent version
00049     bool get_EA(archive_num & archive) const; // if EA has been saved alone later, returns in which version
00050     bool read_data(archive_num num, infinint & val) const; // return the date of last modification within this archive
00051     bool read_EA(archive_num num, infinint & val) const; // return the date of last inode change
00052 
00053     void set_data(const archive_num & archive, const infinint & date) { last_mod[archive] = date; };
00054     void set_EA(const archive_num & archive, const infinint & date) { last_change[archive] = date; };
00055     virtual bool remove_all_from(archive_num archive); // return true if the corresponding file 
00056         // is no more located by any archive (this the object is no more usefull)
00057     void listing() const; // list where is saved this file
00058     virtual void apply_permutation(archive_num src, archive_num dst);
00059     virtual void skip_out(archive_num num); // decrement archive numbers above num
00060     virtual void compute_most_recent_stats(vector<infinint> & data, vector<infinint> & ea, 
00061                                            vector<infinint> & total_data, vector<infinint> & total_ea) const;
00062     
00063     virtual char obj_signature() const { return signature(); };
00064     static char signature() { return 't'; };
00065     
00066 private:
00067     string filename;
00068     map<archive_num, infinint> last_mod; // key is archive number ; value is last_mod time
00069     map<archive_num, infinint> last_change; // key is archive number ; value is last_change time
00070 };
00071 
00072 class data_dir : public data_tree
00073 {
00074 public:
00075     data_dir(const string &name);
00076     data_dir(generic_file &f);
00077     data_dir(const data_dir & ref);
00078     data_dir(const data_tree & ref);
00079     ~data_dir();
00080 
00081     void dump(generic_file & f) const;
00082 
00083     void add(const inode *entry, const archive_num & archive);
00084     const data_tree *read_child(const string & name) const;
00085 
00086     bool remove_all_from(const archive_num & archive); 
00087     void show(archive_num num, string marge = "") const; 
00088         // list the most recent files owned by that archive 
00089         // (or by any archive if num == 0)
00090     void apply_permutation(archive_num src, archive_num dst);
00091     void skip_out(archive_num num);
00092     void compute_most_recent_stats(vector<infinint> & data, vector<infinint> & ea, 
00093                                    vector<infinint> & total_data, vector<infinint> & total_ea) const;
00094 
00095     char obj_signature() const { return signature(); };
00096     static char signature() { return 'd'; };
00097     
00098 private:
00099     list<data_tree *> rejetons;
00100 
00101     void add_child(data_tree *fils); // "this" is now responsible of "fils" disalocation
00102     void remove_child(const string & name);
00103 };
00104 
00105 extern data_dir *data_tree_read(generic_file & f);
00106 extern bool data_tree_find(path chemin, const data_dir & racine, const data_tree *& ptr);
00107 extern void data_tree_update_with(const directory *dir, archive_num archive, data_dir *racine);
00108 extern archive_num data_tree_permutation(archive_num src, archive_num dst, archive_num x);
00109 
00110 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines