Disk ARchive 2.7.14
Full featured and portable backup and archiving tool
Loading...
Searching...
No Matches
generic_rsync.hpp
Go to the documentation of this file.
1/*********************************************************************/
2// dar - disk archive - a backup/restoration program
3// Copyright (C) 2002-2024 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, see the AUTHOR file
20/*********************************************************************/
21
25
26
27#ifndef GENERIC_RSYNC_HPP
28#define GENERIC_RSYNC_HPP
29
30#include "../my_config.h"
31
32extern "C"
33{
34#if HAVE_LIBRSYNC_H
35#include <librsync.h>
36#endif
37}
38
39#include "generic_file.hpp"
40#include "erreurs.hpp"
41
42namespace libdar
43{
44
47
49
51 {
52 public:
54
64
66
80 const infinint & crc_size,
81 const crc **checksum);
82
84
91 generic_file *delta);
92
93
94 generic_rsync(const generic_rsync & ref) = delete;
95 generic_rsync(generic_rsync && ref) noexcept = delete;
96 generic_rsync & operator = (const generic_rsync & ref) = delete;
97 generic_rsync & operator = (generic_rsync && ref) noexcept = delete;
98
100
101 // inherited from generic_file
102
103 virtual bool skippable(skippability direction, const infinint & amount) override { return false; };
104 virtual bool skip(const infinint & pos) override {if(pos != 0 || !initial) throw SRC_BUG; else return true; };
105 virtual bool skip_to_eof() override { throw SRC_BUG; };
106 virtual bool skip_relative(S_I x) override { if(x != 0) throw SRC_BUG; else return true; };
107 virtual bool truncatable(const infinint & pos) const override { return pos == get_position(); };
108 virtual infinint get_position() const override { return x_below->get_position(); };
109
110 protected:
111 virtual void inherited_read_ahead(const infinint & amount) override {};
112 virtual U_I inherited_read(char *a, U_I size) override;
113 virtual void inherited_write(const char *a, U_I size) override;
114 virtual void inherited_truncate(const infinint & pos) override { if(pos != get_position()) throw SRC_BUG; };
115 virtual void inherited_sync_write() override {};
116 virtual void inherited_flush_read() override {};
117 virtual void inherited_terminate() override;
118
119 private:
120 enum { sign, delta, patch } status;
121
123 generic_file *x_input;
124 generic_file *x_output;
125 bool initial;
126 char *working_buffer;
127 U_I working_size;
128 bool patching_completed;
129 crc *data_crc;
130
131#if LIBRSYNC_AVAILABLE
132 rs_job_t *job;
134
136 static rs_result patch_callback(void *opaque,
137 rs_long_t pos,
138 size_t *len,
139 void **buf);
140#endif
141
143
153 bool step_forward(const char *buffer_in,
154 U_I & avail_in,
155 bool shift_input,
156 char *buffer_out,
157 U_I & avail_out);
158 void free_job();
159 void send_eof();
160 };
161
163
164} // end of namespace
165
166#endif
pure virtual class defining interface of a CRC object
this is the interface class from which all other data transfer classes inherit
virtual infinint get_position() const =0
get the current read/write position
generic_file interface to librsync
virtual void inherited_flush_read() override
reset internal engine, flush caches in order to read the data at current position
virtual void inherited_truncate(const infinint &pos) override
truncate file at the give offset
virtual void inherited_terminate() override
destructor-like call, except that it is allowed to throw exceptions
virtual bool skippable(skippability direction, const infinint &amount) override
whether the implementation is able to skip
virtual infinint get_position() const override
get the current read/write position
generic_rsync(generic_file *signature_storage, U_I signature_block_size, generic_file *below)
constructor for "signature" operation
virtual bool skip(const infinint &pos) override
skip at the absolute position
virtual void inherited_sync_write() override
write down any pending data
virtual void inherited_read_ahead(const infinint &amount) override
tells the object that several calls to read() will follow to probably obtain at least the given amoun...
generic_rsync(generic_file *current_data, generic_file *delta)
constructor for "patch" operation
generic_rsync(generic_file *base_signature, generic_file *below, const infinint &crc_size, const crc **checksum)
constructor for "delta" operation
bool step_forward(const char *buffer_in, U_I &avail_in, bool shift_input, char *buffer_out, U_I &avail_out)
feed librsync using rs_job_iter
virtual U_I inherited_read(char *a, U_I size) override
implementation of read() operation
virtual bool skip_to_eof() override
skip to the end of file
virtual void inherited_write(const char *a, U_I size) override
implementation of the write() operation
virtual bool skip_relative(S_I x) override
skip relatively to the current position
generic_file * x_below
underlying layer to read from / write to
virtual bool truncatable(const infinint &pos) const override
whether the implementation is able to truncate to the given position
the arbitrary large positive integer class
include macro defined by the configure script and some specific additional ones
libdar namespace encapsulate all libdar symbols
contains all the excetion class thrown by libdar
class generic_file is defined here as well as class fichier