1 /*********************************************************************/ 2 // dar - disk archive - a backup/restoration program 3 // Copyright (C) 2002-2052 Denis Corbin 4 // 5 // This program is free software; you can redistribute it and/or 6 // modify it under the terms of the GNU General Public License 7 // as published by the Free Software Foundation; either version 2 8 // of the License, or (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with this program; if not, write to the Free Software 17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 // 19 // to contact the author : http://dar.linux.free.fr/email.html 20 /*********************************************************************/ 21 22 /// \file escape_catalogue.hpp 23 /// \brief class escape_catalogue definition. Used for sequential writing to archives, as well as several other inherited classes from catalogue.hpp 24 /// \ingroup Private 25 /// 26 /// This class inherits from the class catalogue and implements 27 /// the pre_add(...) method, which role is to add an escape sequence followed 28 /// by an entry dump (usually used at the end of archive is the so called catalogue part 29 /// of the archive). This sequence followed by entry dump is added 30 /// before each file's data all along the archive. 31 /// Other inherited classes, implement the escape specific part, used when performing 32 /// sequential reading of the catalogue 33 34 #ifndef ESCAPE_CATALOGUE_HPP 35 #define ESCAPE_CATALOGUE_HPP 36 37 #include "../my_config.h" 38 39 #include "catalogue.hpp" 40 #include "escape.hpp" 41 #include "pile.hpp" 42 #include "smart_pointer.hpp" 43 44 namespace libdar 45 { 46 47 /// \addtogroup Private 48 /// @{ 49 50 class escape_catalogue : public catalogue 51 { 52 public: 53 54 /// constructor to setup a escape_catalogue that will drop marks all along the archive and drop its content at end of archive 55 escape_catalogue(user_interaction & dialog, 56 const pile_descriptor & x_pdesc, 57 const datetime & root_last_modif, 58 const label & data_name); 59 60 /// constructor to setup a escape_catalogue that will be fed by sequentially reading the archive 61 escape_catalogue(user_interaction & dialog, //< user interaction 62 const pile_descriptor & x_pdesc, //< stack descriptor where to write to 63 const header_version & ver, //< archive header version read 64 const std::list<signator> & known_signatories, //< signatories that signed the archive header, to be compared with internal catalogue when reaching the end of the archive 65 bool lax = false); //< whether to use lax mode escape_catalogue(const escape_catalogue & ref)66 escape_catalogue(const escape_catalogue & ref) : catalogue(ref) { copy_from(ref); }; 67 const escape_catalogue & operator = (const escape_catalogue &ref); ~escape_catalogue()68 ~escape_catalogue() { destroy(); }; 69 70 // inherited from catalogue 71 void pre_add(const cat_entree *ref) const; 72 void pre_add_ea(const cat_entree *ref) const; 73 void pre_add_crc(const cat_entree *ref) const; 74 void pre_add_dirty() const; 75 void pre_add_ea_crc(const cat_entree *ref) const; 76 void pre_add_waste_mark() const; 77 void pre_add_failed_mark() const; 78 void pre_add_fsa(const cat_entree *ref) const; 79 void pre_add_fsa_crc(const cat_entree *ref) const; get_escape_layer() const80 escape *get_escape_layer() const { return pdesc->esc; }; 81 82 void reset_read() const; 83 void end_read() const; 84 void skip_read_to_parent_dir() const; 85 bool read(const cat_entree * & ref) const; 86 bool read_if_present(std::string *name, const cat_nomme * & ref) const; 87 void tail_catalogue_to_current_read(); read_second_time_dir() const88 bool read_second_time_dir() const { return status == ec_detruits; }; 89 90 private: 91 enum state 92 { 93 ec_init, //< state in which no one file has yet been searched in the archive 94 ec_marks, //< state in which we find the next file using escape sequence marks 95 ec_eod, //< state in which the archive is missing trailing EOD entries, due to user interruption, thus returning EOD in enough number to get back to the root directory 96 ec_signature, //< state in which we compare inline and internal catalogues 97 ec_detruits, //< state in which which detruits objects are returned from the catalogue 98 ec_completed //< state in which the escape_catalogue object is completed and has all information in memory as a normal catalogue 99 }; 100 101 smart_pointer<pile_descriptor> pdesc; 102 header_version x_ver; 103 std::list<signator> known_sig; 104 bool x_lax; 105 std::map <infinint, cat_etoile *> corres; 106 state status; 107 catalogue *cat_det; //< holds the final catalogue's detruit objects when no more file can be read from the archive 108 infinint min_read_offset; //< next offset in archive should be greater than that to identify a mark 109 infinint depth; //< directory depth of archive being read sequentially 110 infinint wait_parent_depth; //< ignore any further entry while depth is less than wait_parent_depth. disabled is set to zero 111 112 void set_esc_and_stack(const pile_descriptor & x_pdesc); 113 void copy_from(const escape_catalogue & ref); 114 void destroy(); 115 void merge_cat_det(); 116 void reset_reading_process(); 117 }; 118 119 /// @} 120 121 } // end of namespace 122 123 #endif 124