Loading...
Searching...
No Matches
generic_rsync.hpp
Go to the documentation of this file.
/*********************************************************************/
// dar - disk archive - a backup/restoration program
// Copyright (C) 2002-2025 Denis Corbin
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// to contact the author, see the AUTHOR file
/*********************************************************************/
#ifndef GENERIC_RSYNC_HPP
#define GENERIC_RSYNC_HPP
#include "../my_config.h"
extern "C"
{
#if HAVE_LIBRSYNC_H
#include <librsync.h>
#endif
}
#include "generic_file.hpp"
#include "erreurs.hpp"
namespace libdar
{
class generic_rsync : public generic_file
{
public:
generic_rsync(generic_file *signature_storage,
U_I signature_block_size,
generic_file *below);
generic_rsync(generic_file *base_signature,
generic_file *below,
const infinint & crc_size,
const crc **checksum);
generic_rsync(generic_file *current_data,
generic_file *delta);
generic_rsync(const generic_rsync & ref) = delete;
generic_rsync(generic_rsync && ref) noexcept = delete;
generic_rsync & operator = (const generic_rsync & ref) = delete;
generic_rsync & operator = (generic_rsync && ref) noexcept = delete;
~generic_rsync() noexcept(false);
// inherited from generic_file
virtual bool skippable(skippability direction, const infinint & amount) override { return false; };
virtual bool skip(const infinint & pos) override {if(pos != 0 || !initial) throw SRC_BUG; else return true; };
virtual bool skip_to_eof() override { throw SRC_BUG; };
virtual bool skip_relative(S_I x) override { if(x != 0) throw SRC_BUG; else return true; };
virtual bool truncatable(const infinint & pos) const override { return pos == get_position(); };
virtual infinint get_position() const override { return x_below->get_position(); };
protected:
virtual void inherited_read_ahead(const infinint & amount) override {};
virtual U_I inherited_read(char *a, U_I size) override;
virtual void inherited_write(const char *a, U_I size) override;
virtual void inherited_truncate(const infinint & pos) override { if(pos != get_position()) throw SRC_BUG; };
virtual void inherited_sync_write() override {};
virtual void inherited_flush_read() override {};
virtual void inherited_terminate() override;
private:
enum { sign, delta, patch } status;
generic_file *x_below;
generic_file *x_input;
generic_file *x_output;
bool initial;
char *working_buffer;
U_I working_size;
bool patching_completed;
crc *data_crc;
#if LIBRSYNC_AVAILABLE
rs_job_t *job;
rs_signature_t *sumset;
static rs_result patch_callback(void *opaque,
rs_long_t pos,
size_t *len,
void **buf);
#endif
bool step_forward(const char *buffer_in,
U_I & avail_in,
bool shift_input,
char *buffer_out,
U_I & avail_out);
void free_job();
void send_eof();
};
} // end of namespace
#endif
libdar::crc
pure virtual class defining interface of a CRC object
Definition crc.hpp:47
libdar::generic_file::generic_file
generic_file(gf_mode m)
main constructor
Definition generic_file.hpp:80
libdar::generic_rsync::inherited_flush_read
virtual void inherited_flush_read() override
reset internal engine, flush caches in order to read the data at current position
Definition generic_rsync.hpp:116
libdar::generic_rsync::inherited_truncate
virtual void inherited_truncate(const infinint &pos) override
truncate file at the give offset
Definition generic_rsync.hpp:114
libdar::generic_rsync::inherited_terminate
virtual void inherited_terminate() override
destructor-like call, except that it is allowed to throw exceptions
libdar::generic_rsync::skippable
virtual bool skippable(skippability direction, const infinint &amount) override
whether the implementation is able to skip
Definition generic_rsync.hpp:103
libdar::generic_rsync::get_position
virtual infinint get_position() const override
get the current read/write position
Definition generic_rsync.hpp:108
libdar::generic_rsync::generic_rsync
generic_rsync(generic_file *signature_storage, U_I signature_block_size, generic_file *below)
constructor for "signature" operation
libdar::generic_rsync::skip
virtual bool skip(const infinint &pos) override
skip at the absolute position
Definition generic_rsync.hpp:104
libdar::generic_rsync::inherited_sync_write
virtual void inherited_sync_write() override
write down any pending data
Definition generic_rsync.hpp:115
libdar::generic_rsync::inherited_read_ahead
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...
Definition generic_rsync.hpp:111
libdar::generic_rsync::generic_rsync
generic_rsync(generic_file *current_data, generic_file *delta)
constructor for "patch" operation (applies a patch to a file)
libdar::generic_rsync::generic_rsync
generic_rsync(generic_file *base_signature, generic_file *below, const infinint &crc_size, const crc **checksum)
constructor for "delta" operation (builds a patch data)
libdar::generic_rsync::step_forward
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
libdar::generic_rsync::inherited_read
virtual U_I inherited_read(char *a, U_I size) override
implementation of read() operation
libdar::generic_rsync::skip_to_eof
virtual bool skip_to_eof() override
skip to the end of file
Definition generic_rsync.hpp:105
libdar::generic_rsync::inherited_write
virtual void inherited_write(const char *a, U_I size) override
implementation of the write() operation
libdar::generic_rsync::skip_relative
virtual bool skip_relative(S_I x) override
skip relatively to the current position
Definition generic_rsync.hpp:106
libdar::generic_rsync::x_below
generic_file * x_below
underlying layer to read from / write to
Definition generic_rsync.hpp:122
libdar::generic_rsync::truncatable
virtual bool truncatable(const infinint &pos) const override
whether the implementation is able to truncate to the given position
Definition generic_rsync.hpp:107
libdar::infinint
the arbitrary large positive integer class
Definition real_infinint.hpp:62
erreurs.hpp
contains all the excetion class thrown by libdar
generic_file.hpp
class generic_file is defined here as well as class fichier
my_config.h
include macro defined by the configure script and some specific additional ones
libdar
libdar namespace encapsulate all libdar symbols
Definition archive.hpp:47