Disk ARchive  2.6.2
Full featured and portable backup and archiving tool
cat_delta_signature.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2019 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 
25 
26 #ifndef CAT_DELTA_SIGNATURE_HPP
27 #define CAT_DELTA_SIGNATURE_HPP
28 
29 #include "../my_config.h"
30 
31 extern "C"
32 {
33 } // end extern "C"
34 
35 #include "memory_file.hpp"
36 #include "crc.hpp"
37 #include "compressor.hpp"
38 
39 #include <memory>
40 
41 namespace libdar
42 {
43 
46 
47  // Datastructure in archive (DATA+METADATA)
48  //
49  // SEQUENTIAL MODE - in the core of the archive
50  // +------+------+---------------+----------+--------+
51  // | base | sig | sig data | data CRC | result |
52  // | CRC | size | (if size > 0) | if | CRC |
53  // | | | | size > 0 | |
54  // +------+------+---------------+----------+--------+
55  //
56  // DIRECT MODE - in catalogue at end of archive (METADATA)
57  // +------+------+---------------+--------+
58  // | base | sig | sig offset | result |
59  // | CRC | size | (if size > 0) | CRC |
60  // | | | | |
61  // +------+------+---------------+--------+
62  //
63  // DIRECT MODE - in the core of the archive (DATA)
64  // +---------------+----------+
65  // | sig data | data CRC |
66  // | (if size > 0) | if |
67  // | | size > 0 |
68  // +---------------+----------+
69  //
70  //
71  // this structure is used for all cat_file inode that have
72  // either a delta signature or contain a delta patch (s_delta status)
73  // base_crc is used to check we apply the patch on the good file before proceeding
74  // result_crc is used to store the crc of the file the signature has been computed on
75  // result_crc is also used once a patch has been applied to verify the correctness of the patch result
76 
77 
79 
91  {
92  public:
94 
101 
103  cat_delta_signature() { init(); };
104 
106  cat_delta_signature(const cat_delta_signature & ref) { init(); copy_from(ref); };
107 
109  cat_delta_signature(cat_delta_signature && ref) noexcept { init(); move_from(std::move(ref)); };
110 
112  cat_delta_signature & operator = (const cat_delta_signature & ref) { clear(); copy_from(ref); return *this; };
113 
115  cat_delta_signature & operator = (cat_delta_signature && ref) noexcept { move_from(std::move(ref)); return *this; };
116 
118  ~cat_delta_signature() { destroy(); };
119 
121 
125  void read(bool sequential_read);
126 
128  bool can_obtain_sig() const { return !delta_sig_size.is_zero(); };
129 
131 
135  std::shared_ptr<memory_file> obtain_sig() const;
136 
138 
141  void drop_sig() const { sig.reset(); };
142 
144 
146 
148 
151 
153  void set_sig(const std::shared_ptr<memory_file> & ptr);
154 
156  void set_sig() { delta_sig_size = 0; delta_sig_offset = 0; sig.reset(); };
157 
159  void dump_data(generic_file & f, bool sequential_mode) const;
160 
162  void dump_metadata(generic_file & f) const;
163 
164 
166 
168  bool has_patch_base_crc() const { return patch_base_check != nullptr; };
169 
171  bool get_patch_base_crc(const crc * & c) const;
172 
174  void set_patch_base_crc(const crc & c);
175 
177  bool has_patch_result_crc() const { return patch_result_check != nullptr; };
178 
180  bool get_patch_result_crc(const crc * & c) const;
181 
183  void set_patch_result_crc(const crc & c);
184 
186  void clear() { destroy(); init(); };
187 
188  private:
192  mutable std::shared_ptr<memory_file>sig;
196 
197  void init() noexcept;
198  void copy_from(const cat_delta_signature & ref);
199  void move_from(cat_delta_signature && ref) noexcept;
200  void destroy() noexcept;
201  void fetch_data() const;
202  };
203 
205 
206 } // end of namespace
207 
208 #endif
crc * patch_base_check
associated CRC for the file this signature has been computed on
cat_delta_signature & operator=(const cat_delta_signature &ref)
assignement operator
std::shared_ptr< memory_file > sig
the signature data, if set nullptr it will be fetched from f in direct access mode only ...
bool has_patch_base_crc() const
returns whether the object has a base patch CRC (s_delta status objects)
class crc definition, used to handle Cyclic Redundancy Checks
bool has_patch_result_crc() const
returns whether the object has a CRC corresponding to data (for s_saved, s_delta, and when delta sign...
bool get_patch_base_crc(const crc *&c) const
returns the CRC of the file to base the patch on, for s_delta objects
bool get_patch_result_crc(const crc *&c) const
returns the CRC the file will have once restored or patched (for s_saved, s_delta, and when delta signature is present)
void read(bool sequential_read)
void drop_sig() const
drop signature but keep metadata available
compressor * zip
needed to disable compression when reading delta signature data from an archive
generic_file * src
where to read data from
void set_patch_result_crc(const crc &c)
set the CRC the file will have once restored or patched (for s_saved, s_delta, and when delta signatu...
bool can_obtain_sig() const
the cat_delta_signature structure can only hold CRC without delta_signature, this call gives the situ...
crc * patch_result_check
associated CRC
infinint delta_sig_offset
where to read data from to setup "sig" (set to zero when read in sequential mode, sig is setup on-fly...
Memory_file is a generic_file class that only uses virtual memory.
the cat_delta_signature file class
void dump_metadata(generic_file &f) const
write down the delta_signature metadata for catalogue
std::shared_ptr< memory_file > obtain_sig() const
provide a memory_file object which the caller has the duty to destroy after use
compression class for gzip and bzip2 algorithms
Definition: compressor.hpp:45
void set_patch_base_crc(const crc &c)
set the reference CRC of the file to base the patch on, for s_detla objects
void will_have_signature()
give the object where to fetch from the delta signature, object must exist up to the next call to dum...
infinint delta_sig_size
size of the data to setup "sig" (set to zero when reading in sequential mode, sig is then setup on-fl...
cat_delta_signature(const cat_delta_signature &ref)
copy constructor
this is the interface class from which all other data transfer classes inherit
void set_sig()
variante used when the delta_signature object will only contain CRCs (no delta signature) ...
cat_delta_signature()
constructor to write an object to filesytem (using dump_* methods later on)
compression engine implementation
void dump_data(generic_file &f, bool sequential_mode) const
write down the data eventually with sequential read mark followed by delta sig metadata ...
bool is_zero() const
the arbitrary large positive integer class
pure virtual class defining interface of a CRC object
Definition: crc.hpp:46
void clear()
reset the object
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:46
cat_delta_signature(cat_delta_signature &&ref) noexcept
move constructor