Disk ARchive  2.5.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-2052 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 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 "header.hpp"
35 #include "path.hpp"
36 #include "integers.hpp"
37 #include "entrepot.hpp"
38 #include "tools.hpp"
39 #include "slice_layout.hpp"
40 
41 namespace libdar
42 {
43  // contextual is defined in generic_file module
44 
47 
54 
55  class trivial_sar : public generic_file , public contextual, protected mem_ui
56  {
57  public:
59  trivial_sar(const user_interaction & dialog, //< how to interact with the user
60  gf_mode open_mode, //< read_write or write_only are the only acceptable values
61  const std::string & base_name, //< archive basename to create
62  const std::string & extension, //< archive extension
63  const entrepot & where, //< where to store the archive
64  const label & internal_nale, //< tag common to all slices of the archive
65  const label & data_name, //< tag that follows the data when archive is dar_xform'ed
66  const std::string & execute, //< command line to execute at end of slice creation
67  bool allow_over, //< whether to allow overwriting
68  bool warn_over, //< whether to warn before overwriting
69  bool force_permission, //< whether to enforce slice permission or not
70  U_I permission, //< value of permission to use if permission enforcement is used
71  hash_algo x_hash, //< whether to build a hash of the slice, and which algo to use for that
72  const infinint & min_digits, //< is the minimum number of digits the slices number is stored with in the filename
73  bool format_07_compatible); //< build a slice header backward compatible with 2.3.x
74 
75 
77  trivial_sar(const user_interaction & dialog, //< how to interact with the user
78  const std::string & pipename, //< if set to '-' the data are read from standard input, else the given file is expected to be named pipe to read data from
79  bool lax); //< whether to be laxist or follow the normal and strict controlled procedure
80 
81 
83  trivial_sar(const user_interaction & dialog,
84  generic_file * f, //< in case of exception the generic_file "f" is not released, this is the duty of the caller to do so, else (success), the object becomes owned by the trivial_sar and must not be released by the caller.
85  const label & internal_name,
86  const label & data_name,
87  bool format_07_compatible,
88  const std::string & execute);
89 
91  trivial_sar(const trivial_sar & ref) : generic_file(ref), mem_ui(ref) { throw SRC_BUG; };
92 
94  ~trivial_sar();
95 
96  const trivial_sar & operator = (const trivial_sar & ref) { throw SRC_BUG; };
97  bool skippable(skippability direction, const infinint & amount) { return reference->skippable(direction, amount); };
98  bool skip(const infinint & pos);
99  bool skip_to_eof() { if(is_terminated()) throw SRC_BUG; return reference->skip_to_eof(); };
100  bool skip_relative(S_I x);
101  infinint get_position() const { return cur_pos; };
102 
103  // contextual inherited method
104  bool is_an_old_start_end_archive() const { return old_sar; };
105  const label & get_data_name() const { return of_data_name; };
106 
108  const infinint & get_slice_header_size() const { return offset; };
109 
110  protected:
111  void inherited_read_ahead(const infinint & amount) { reference->read_ahead(amount); };
112  U_I inherited_read(char *a, U_I size);
113  void inherited_write(const char *a, U_I size);
116  void inherited_terminate();
117 
118  private:
119  generic_file *reference; //< points to the underlying data, owned by "this"
120  infinint offset; //< offset to apply to get the first byte of data out of SAR headers
121  infinint cur_pos; //< current position as returned by get_position()
122  infinint end_of_slice; //< when end of slice/archive is met, there is an offset by 1 compared to the offset of reference. end_of_slice is set to 1 in that situation, else it is always equal to zero
123  std::string hook; //< command to execute after slice writing (not used in read-only mode)
124  std::string base; //< basename of the archive (used for string susbstitution in hook)
125  std::string ext; //< extension of the archive (used for string substitution in hook)
126  label of_data_name; //< archive's data name
127  bool old_sar; //< true if the read sar has an old header (format <= "07") or the to be written is must keep a version 07 format.
128  infinint min_digits; //< minimum number of digits in slice name
129  std::string hook_where; //< what value to use for %p subsitution in hook
130 
131  void init(const label & internal_name); //< write the slice header and set the offset field (write mode), or (read-mode), reads the slice header an set offset field
132 
133  void where_am_i();
134  };
135 
136 
138 
139  extern std::string sar_make_filename(const std::string & base_name, const infinint & num, const infinint & min_digits, const std::string & ext);
140 
142 
143 } // end of namespace
144 
145 #endif
defines the entrepot interface. Entrepot interface defines a generic way to interact with files (slic...
void inherited_read_ahead(const infinint &amount)
void inherited_terminate()
destructor-like call, except that it is allowed to throw exceptions
void inherited_sync_write()
write down any pending data
are defined here basic integer types that tend to be portable
bool skip_to_eof()
skip to the end of file
Definition: trivial_sar.hpp:99
a set of general purpose routines
class generic_file is defined here as well as class fichierthe generic_file interface is widely used ...
infinint get_position() const
get the current read/write position
This is a pure virtual class that is used by libdar when interaction with the user is required...
void inherited_write(const char *a, U_I size)
implementation of the write() operation
virtual void read_ahead(const infinint &amount)
trivial_sar(const trivial_sar &ref)
copy constructor (disabled)
Definition: trivial_sar.hpp:91
gf_mode
generic_file openning modes
object describing the slicing of an archive
bool skip_relative(S_I x)
skip relatively to the current position
const infinint & get_slice_header_size() const
size of the slice header
trivial_sar(const 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
slice header structure is defined here
here is the definition of the path classthe path class handle path and provide several operation on t...
bool is_terminated() const
~trivial_sar()
destructor
switch module to limitint (32 ou 64 bits integers) or infinint
U_I inherited_read(char *a, U_I size)
implementation of read() operation
bool skippable(skippability direction, const infinint &amount)
Definition: trivial_sar.hpp:97
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
this is the interface class from which all other data transfer classes inherit
class mem_ui to keep a copy of a user_interaction object
Definition: mem_ui.hpp:53
the arbitrary large positive integer class
bool skip(const infinint &pos)
virtual bool skip_to_eof()=0
skip to the end of file
the Entrepot interface
Definition: entrepot.hpp:61
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47
virtual bool skippable(skippability direction, const infinint &amount)=0