| Disk ARchive 2.6.12 Full featured and portable backup and archiving tool

trivial_sar.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 TRIVIAL_SAR_HPP
27 #define TRIVIAL_SAR_HPP
28
29 #include "../my_config.h"
30
31 #include <string>
32 #include "infinint.hpp"
33 #include "generic_file.hpp"
34 #include "integers.hpp"
35 #include "entrepot.hpp"
36 #include "contextual.hpp"
37 #include "mem_ui.hpp"
38
39 namespace libdar
40 {
41 // contextual is defined in generic_file module
42
45
52
53 class trivial_sar : public generic_file, public contextual, protected mem_ui
54 {
55 public:
57 trivial_sar(const std::shared_ptr<user_interaction> & dialog,
58 gf_mode open_mode,
59 const std::string & base_name,
60 const std::string & extension,
61 const entrepot & where,
62 const label & internal_nale,
63 const label & data_name,
64 const std::string & execute,
65 bool allow_over,
66 bool warn_over,
67 bool force_permission,
68 U_I permission,
69 hash_algo x_hash,
70 const infinint & min_digits,
71 bool format_07_compatible
72 );
73
74
76 trivial_sar(const std::shared_ptr<user_interaction> & dialog,
77 const std::string & pipename,
78 bool lax
79 );
80
81 trivial_sar(const std::shared_ptr<user_interaction> & dialog,
82 int filedescriptor,
83 bool lax
84 );
85
87 trivial_sar(const std::shared_ptr<user_interaction> & dialog,
88 generic_file * f,
89 const label & internal_name,
90 const label & data_name,
91 bool format_07_compatible,
92 const std::string & execute
93 );
94
96 trivial_sar(const trivial_sar & ref) = delete;
97
99 trivial_sar(trivial_sar && ref) noexcept = delete;
100
102 trivial_sar & operator = (const trivial_sar & ref) = delete;
103
105 trivial_sar & operator = (trivial_sar && ref) noexcept = delete;
106
108 ~trivial_sar();
109
110 virtual bool skippable(skippability direction, const infinint & amount) override { return reference->skippable(direction, amount); };
111 virtual bool skip(const infinint & pos) override;
112 virtual bool skip_to_eof() override { if(is_terminated()) throw SRC_BUG; return reference->skip_to_eof(); };
113 virtual bool skip_relative(S_I x) override;
114 virtual infinint get_position() const override { return cur_pos; };
115
116 // contextual inherited method
117 virtual bool is_an_old_start_end_archive() const override { return old_sar; };
118 virtual const label & get_data_name() const override { return of_data_name; };
119
121 const infinint & get_slice_header_size() const { return offset; };
122
124 void disable_natural_destruction() { natural_destruction = false; };
125
127 void enable_natural_destruction() { natural_destruction = true; };
128
129 protected:
130 virtual void inherited_read_ahead(const infinint & amount) override { reference->read_ahead(amount); };
131 virtual U_I inherited_read(char *a, U_I size) override;
132 virtual void inherited_write(const char *a, U_I size) override;
133 virtual void inherited_sync_write() override { if(reference != nullptr) reference->sync_write(); };
134 virtual void inherited_flush_read() override { if(reference != nullptr) reference->flush_read(); };
135 virtual void inherited_terminate() override;
136
137 private:
138 generic_file *reference;
139 infinint offset;
140 infinint cur_pos;
141 infinint end_of_slice;
142 std::string hook;
143 std::string base;
144 std::string ext;
145 label of_data_name;
146 bool old_sar;
147 infinint min_digits;
148 std::string hook_where;
149 std::string base_url;
150 bool natural_destruction;
151
152 void init(const label & internal_name);
153
154 void where_am_i();
155 };
156
157
159 extern std::string sar_make_filename(const std::string & base_name, const infinint & num, const infinint & min_digits, const std::string & ext);
160
162
163 } // end of namespace
164
165 #endif
libdar::hash_algo
hash_algo
hashing algorithm available
Definition: archive_aux.hpp:63
libdar::trivial_sar::skip_relative
virtual bool skip_relative(S_I x) override
skip relatively to the current position
libdar::trivial_sar::trivial_sar
trivial_sar(const std::shared_ptr< user_interaction > &dialog, gf_mode open_mode, const std::string &base_name, const std::string &extension, const entrepot &where, const label &internal_nale, const label &data_name, const std::string &execute, bool allow_over, bool warn_over, bool force_permission, U_I permission, hash_algo x_hash, const infinint &min_digits, bool format_07_compatible)
constructor to build a new single sliced archive
libdar::generic_file::skip_to_eof
virtual bool skip_to_eof()=0
skip to the end of file
libdar::trivial_sar::inherited_flush_read
virtual void inherited_flush_read() override
reset internal engine, flush caches in order to read the data at current position
Definition: trivial_sar.hpp:134
libdar::label
manage label data structure used in archive slice headers
Definition: label.hpp:43
libdar::trivial_sar::ext
std::string ext
extension of the archive (used for string substitution in hook)
Definition: trivial_sar.hpp:144
libdar::trivial_sar::init
void init(const label &internal_name)
write the slice header and set the offset field (write mode), or (read-mode), reads the slice header ...
contextual.hpp
class contextual adds the information of phases in the generic_file
libdar::trivial_sar::skip
virtual bool skip(const infinint &pos) override
skip at the absolute position
libdar::trivial_sar::base
std::string base
basename of the archive (used for string susbstitution in hook)
Definition: trivial_sar.hpp:143
libdar::trivial_sar::end_of_slice
infinint end_of_slice
when end of slice/archive is met, there is an offset by 1 compared to the offset of reference....
Definition: trivial_sar.hpp:141
integers.hpp
are defined here basic integer types that tend to be portable
libdar::gf_mode
gf_mode
generic_file openning modes
Definition: gf_mode.hpp:44
infinint.hpp
switch module to limitint (32 ou 64 bits integers) or infinint
libdar::trivial_sar::~trivial_sar
~trivial_sar()
destructor
libdar::infinint
the arbitrary large positive integer class
Definition: real_infinint.hpp:62
libdar::trivial_sar::trivial_sar
trivial_sar(const std::shared_ptr< user_interaction > &dialog, int filedescriptor, bool lax)
libdar::trivial_sar::get_slice_header_size
const infinint & get_slice_header_size() const
size of the slice header
Definition: trivial_sar.hpp:121
libdar::generic_file::flush_read
void flush_read()
be ready to read at current position, reseting all pending data for reading, cached and in compressio...
libdar::trivial_sar::inherited_read
virtual U_I inherited_read(char *a, U_I size) override
implementation of read() operation
libdar::trivial_sar::hook_where
std::string hook_where
what value to use for p substitution in hook
Definition: trivial_sar.hpp:148
libdar::generic_file::sync_write
void sync_write()
write any pending data
libdar::trivial_sar::enable_natural_destruction
void enable_natural_destruction()
enable back execution of user command when destroying the current object
Definition: trivial_sar.hpp:127
libdar::trivial_sar::operator=
trivial_sar & operator=(const trivial_sar &ref)=delete
assignment operator (disabled)
libdar::trivial_sar::inherited_write
virtual void inherited_write(const char *a, U_I size) override
implementation of the write() operation
libdar::trivial_sar
Definition: trivial_sar.hpp:54
libdar::trivial_sar::min_digits
infinint min_digits
minimum number of digits in slice name
Definition: trivial_sar.hpp:147
libdar::trivial_sar::trivial_sar
trivial_sar(const std::shared_ptr< user_interaction > &dialog, const std::string &pipename, bool lax)
constructor to read a (single sliced) archive from a pipe
libdar::generic_file::is_terminated
bool is_terminated() const
Definition: generic_file.hpp:300
libdar::trivial_sar::base_url
std::string base_url
what value to use for u substitution in hook
Definition: trivial_sar.hpp:149
libdar::trivial_sar::get_position
virtual infinint get_position() const override
get the current read/write position
Definition: trivial_sar.hpp:114
libdar::mem_ui
class mem_ui to keep a copy of a user_interaction object
Definition: mem_ui.hpp:55
entrepot.hpp
defines the entrepot interface. Entrepot interface defines a generic way to interact with files (slic...
libdar::trivial_sar::inherited_terminate
virtual void inherited_terminate() override
destructor-like call, except that it is allowed to throw exceptions
generic_file.hpp
class generic_file is defined here as well as class fichier
libdar::trivial_sar::hook
std::string hook
command to execute after slice writing (not used in read-only mode)
Definition: trivial_sar.hpp:142
libdar::generic_file::skippable
virtual bool skippable(skippability direction, const infinint &amount)=0
whether the implementation is able to skip
libdar::sar_make_filename
std::string sar_make_filename(const std::string &base_name, const infinint &num, const infinint &min_digits, const std::string &ext)
return the name of a slice given the base_name, slice number and extension
libdar::trivial_sar::trivial_sar
trivial_sar(const std::shared_ptr< user_interaction > &dialog, generic_file *f, const label &internal_name, const label &data_name, bool format_07_compatible, const std::string &execute)
constructor to write a (single sliced) archive to a anonymous pipe
libdar::trivial_sar::cur_pos
infinint cur_pos
current position as returned by get_position()
Definition: trivial_sar.hpp:140
libdar::trivial_sar::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: trivial_sar.hpp:130
libdar::trivial_sar::of_data_name
label of_data_name
archive's data name
Definition: trivial_sar.hpp:145
libdar::trivial_sar::disable_natural_destruction
void disable_natural_destruction()
disable execution of user command when destroying the current object
Definition: trivial_sar.hpp:124
libdar::generic_file::read_ahead
void read_ahead(const infinint &amount)
libdar::generic_file
this is the interface class from which all other data transfer classes inherit
Definition: generic_file.hpp:77
libdar::entrepot
the Entrepot interface
Definition: entrepot.hpp:57
libdar::contextual
the contextual class adds the information of phases in the generic_file
Definition: contextual.hpp:74
libdar::trivial_sar::natural_destruction
bool natural_destruction
whether user command is executed once the single sliced archive is completed (disable upon user inter...
Definition: trivial_sar.hpp:150
libdar::trivial_sar::skip_to_eof
virtual bool skip_to_eof() override
skip to the end of file
Definition: trivial_sar.hpp:112
libdar::trivial_sar::skippable
virtual bool skippable(skippability direction, const infinint &amount) override
whether the implementation is able to skip
Definition: trivial_sar.hpp:110
libdar::trivial_sar::trivial_sar
trivial_sar(trivial_sar &&ref) noexcept=delete
move constructor
libdar::trivial_sar::trivial_sar
trivial_sar(const trivial_sar &ref)=delete
copy constructor (disabled)
libdar::trivial_sar::is_an_old_start_end_archive
virtual bool is_an_old_start_end_archive() const override
returns whether the archive is a old archive (format < 8)
Definition: trivial_sar.hpp:117
libdar::trivial_sar::old_sar
bool old_sar
true if the read sar has an old header (format <= "07") or the to be written is must keep a version 0...
Definition: trivial_sar.hpp:146
libdar::trivial_sar::inherited_sync_write
virtual void inherited_sync_write() override
write down any pending data
Definition: trivial_sar.hpp:133
libdar::trivial_sar::get_data_name
virtual const label & get_data_name() const override
obtain the data_name of the archive (label associated with the archive's data)
Definition: trivial_sar.hpp:118
libdar::trivial_sar::offset
infinint offset
offset to apply to get the first byte of data out of SAR headers
Definition: trivial_sar.hpp:139
libdar::trivial_sar::reference
generic_file * reference
points to the underlying data, owned by "this"
Definition: trivial_sar.hpp:138
mem_ui.hpp
class mem_ui definition. This class is to be used as parent class to handle user_interaction object m...
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47