| Disk ARchive 2.6.12 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-2020 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 #include "archive_version.hpp"
39
40 #include <memory>
41
42 namespace libdar
43 {
44
47
48 // Datastructure in archive (DATA+METADATA)
49 //
50 // SEQUENTIAL MODE - in the core of the archive
51 // +------+------+-----------+--------------+----------+--------+
52 // | base | sig | sig block |sig data | data CRC | result |
53 // | CRC | size | len (if |(if size > 0) | if | CRC |
54 // | | | size > 0) | | size > 0 | |
55 // +------+------+-----------+--------------+----------+--------+
56 //
57 // DIRECT MODE - in catalogue at end of archive (METADATA)
58 // +------+------+---------------+--------+
59 // | base | sig | sig offset | result |
60 // | CRC | size | (if size > 0) | CRC |
61 // | | | | |
62 // +------+------+---------------+--------+
63 //
64 // DIRECT MODE - in the core of the archive (DATA)
65 // +-----------+---------------+----------+
66 // | sig block | sig data | data CRC |
67 // | len (if | (if size > 0) | if |
68 // | size > 0) | | size > 0 |
69 // +-----------+---------------+----------+
70 //
71 //
72 // this structure is used for all cat_file inode that have
73 // either a delta signature or contain a delta patch (s_delta status)
74 // base_crc is used to check we apply the patch on the good file before proceeding
75 // result_crc is used to store the crc of the file the signature has been computed on
76 // result_crc is also used once a patch has been applied to verify the correctness of the patch result
77
78
80
91 class cat_delta_signature
92 {
93 public:
95
101 cat_delta_signature(generic_file *f, compressor* c);
102
104 cat_delta_signature() { init(); };
105
107 cat_delta_signature(const cat_delta_signature & ref) { init(); copy_from(ref); };
108
110 cat_delta_signature(cat_delta_signature && ref) noexcept { init(); move_from(std::move(ref)); };
111
113 cat_delta_signature & operator = (const cat_delta_signature & ref) { clear(); copy_from(ref); return *this; };
114
116 cat_delta_signature & operator = (cat_delta_signature && ref) noexcept { move_from(std::move(ref)); return *this; };
117
119 ~cat_delta_signature() { destroy(); };
120
122
126 void read(bool sequential_read, const archive_version & ver);
127
129 bool can_obtain_sig() const { return !delta_sig_size.is_zero(); };
130
132
136 std::shared_ptr<memory_file> obtain_sig(const archive_version & ver) const;
137
139 U_I obtain_sig_block_size() const { return sig_block_len; };
140
142
145 void drop_sig() const { sig.reset(); };
146
148
150
152
154 void will_have_signature() { delta_sig_size = 1; };
155
157
160 void set_sig(const std::shared_ptr<memory_file> & ptr, U_I sig_block_size);
161
163 void set_sig() { delta_sig_size = 0; delta_sig_offset = 0; sig_block_len = 0; sig.reset(); };
164
166
169 void dump_data(generic_file & f, bool sequential_mode, const archive_version & ver) const;
170
172 void dump_metadata(generic_file & f) const;
173
174
176
178 bool has_patch_base_crc() const { return patch_base_check != nullptr; };
179
181 bool get_patch_base_crc(const crc * & c) const;
182
184 void set_patch_base_crc(const crc & c);
185
187 bool has_patch_result_crc() const { return patch_result_check != nullptr; };
188
190 bool get_patch_result_crc(const crc * & c) const;
191
193 void set_patch_result_crc(const crc & c);
194
196 void clear() { destroy(); init(); };
197
198 private:
199 crc *patch_base_check;
200 infinint delta_sig_size;
201 infinint delta_sig_offset;
202 mutable std::shared_ptr<memory_file>sig;
204 crc *patch_result_check;
205 generic_file *src;
206 compressor *zip;
207 mutable U_I sig_block_len;
208
209 void init() noexcept;
210 void copy_from(const cat_delta_signature & ref);
211 void move_from(cat_delta_signature && ref) noexcept;
212 void destroy() noexcept;
213 void fetch_data(const archive_version & ver) const;
214 };
215
217
218 } // end of namespace
219
220 #endif
libdar::infinint::is_zero
bool is_zero() const
libdar::cat_delta_signature::cat_delta_signature
cat_delta_signature()
constructor to write an object to filesytem (using dump_* methods later on)
Definition: cat_delta_signature.hpp:104
libdar::cat_delta_signature::drop_sig
void drop_sig() const
drop signature but keep metadata available
Definition: cat_delta_signature.hpp:145
crc.hpp
class crc definition, used to handle Cyclic Redundancy Checks
libdar::cat_delta_signature::delta_sig_offset
infinint delta_sig_offset
Definition: cat_delta_signature.hpp:201
libdar::compressor
compression class for gzip and bzip2 algorithms
Definition: compressor.hpp:46
libdar::infinint
the arbitrary large positive integer class
Definition: real_infinint.hpp:62
archive_version.hpp
class archive_version that rules which archive format to follow
libdar::cat_delta_signature::patch_result_check
crc * patch_result_check
associated CRC
Definition: cat_delta_signature.hpp:204
libdar::cat_delta_signature::patch_base_check
crc * patch_base_check
associated CRC for the file this signature has been computed on
Definition: cat_delta_signature.hpp:196
libdar::cat_delta_signature::has_patch_base_crc
bool has_patch_base_crc() const
returns whether the object has a base patch CRC (s_delta status objects)
Definition: cat_delta_signature.hpp:178
libdar::cat_delta_signature::get_patch_result_crc
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,...
libdar::cat_delta_signature::src
generic_file * src
where to read data from
Definition: cat_delta_signature.hpp:205
libdar::cat_delta_signature::sig_block_len
U_I sig_block_len
block lenght used within delta signature
Definition: cat_delta_signature.hpp:207
libdar::archive_version
class archive_version manages the version of the archive format
Definition: archive_version.hpp:47
libdar::cat_delta_signature::obtain_sig_block_size
U_I obtain_sig_block_size() const
provide the block size used for delta signature
Definition: cat_delta_signature.hpp:139
libdar::cat_delta_signature::delta_sig_size
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...
Definition: cat_delta_signature.hpp:200
libdar::crc
pure virtual class defining interface of a CRC object
Definition: crc.hpp:47
libdar::cat_delta_signature::set_patch_result_crc
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...
libdar::cat_delta_signature::can_obtain_sig
bool can_obtain_sig() const
the cat_delta_signature structure can only hold CRC without delta_signature, this call gives the situ...
Definition: cat_delta_signature.hpp:129
libdar::cat_delta_signature::cat_delta_signature
cat_delta_signature(cat_delta_signature &&ref) noexcept
move constructor
Definition: cat_delta_signature.hpp:110
libdar::cat_delta_signature::set_patch_base_crc
void set_patch_base_crc(const crc &c)
set the reference CRC of the file to base the patch on, for s_detla objects
libdar::cat_delta_signature::sig
std::shared_ptr< memory_file > sig
the signature data, if set nullptr it will be fetched from f in direct access mode only
Definition: cat_delta_signature.hpp:203
libdar::cat_delta_signature::zip
compressor * zip
needed to disable compression when reading delta signature data from an archive
Definition: cat_delta_signature.hpp:206
libdar::cat_delta_signature::read
void read(bool sequential_read, const archive_version &ver)
libdar::cat_delta_signature::obtain_sig
std::shared_ptr< memory_file > obtain_sig(const archive_version &ver) const
provide a memory_file object which the caller has the duty to destroy after use
libdar::cat_delta_signature::dump_data
void dump_data(generic_file &f, bool sequential_mode, const archive_version &ver) const
write down the data eventually with sequential read mark followed by delta sig metadata
libdar::cat_delta_signature::clear
void clear()
reset the object
Definition: cat_delta_signature.hpp:196
memory_file.hpp
Memory_file is a generic_file class that only uses virtual memory.
libdar::generic_file
this is the interface class from which all other data transfer classes inherit
Definition: generic_file.hpp:77
libdar::cat_delta_signature::has_patch_result_crc
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...
Definition: cat_delta_signature.hpp:187
libdar::cat_delta_signature::dump_metadata
void dump_metadata(generic_file &f) const
write down the delta_signature metadata for catalogue
libdar::cat_delta_signature::~cat_delta_signature
~cat_delta_signature()
destructor
Definition: cat_delta_signature.hpp:119
libdar::cat_delta_signature::cat_delta_signature
cat_delta_signature(generic_file *f, compressor *c)
constructor to read an object (using read() later on) from filesystem
libdar::cat_delta_signature::cat_delta_signature
cat_delta_signature(const cat_delta_signature &ref)
copy constructor
Definition: cat_delta_signature.hpp:107
libdar::cat_delta_signature
the cat_delta_signature file class
Definition: cat_delta_signature.hpp:92
libdar::cat_delta_signature::set_sig
void set_sig()
variante used when the delta_signature object will only contain CRCs (no delta signature)
Definition: cat_delta_signature.hpp:163
libdar::cat_delta_signature::operator=
cat_delta_signature & operator=(const cat_delta_signature &ref)
assignement operator
Definition: cat_delta_signature.hpp:113
libdar::cat_delta_signature::will_have_signature
void will_have_signature()
give the object where to fetch from the delta signature, object must exist up to the next call to dum...
Definition: cat_delta_signature.hpp:154
libdar::cat_delta_signature::get_patch_base_crc
bool get_patch_base_crc(const crc *&c) const
returns the CRC of the file to base the patch on, for s_delta objects
compressor.hpp
compression engine implementation
libdar::cat_delta_signature::set_sig
void set_sig(const std::shared_ptr< memory_file > &ptr, U_I sig_block_size)
the object pointed to by ptr must stay available when calling dump_data()/dump_metadata() later on
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47