Disk ARchive  2.5.2
Full featured and portable backup and archiving tool
trivial_sar.hpp
Go to the documentation of this file.
00001 /*********************************************************************/
00002 // dar - disk archive - a backup/restoration program
00003 // Copyright (C) 2002-2052 Denis Corbin
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 //
00019 // to contact the author : http://dar.linux.free.fr/email.html
00020 /*********************************************************************/
00021 
00025 
00026 #ifndef TRIVIAL_SAR_HPP
00027 #define TRIVIAL_SAR_HPP
00028 
00029 #include "../my_config.h"
00030 
00031 #include <string>
00032 #include "infinint.hpp"
00033 #include "generic_file.hpp"
00034 #include "header.hpp"
00035 #include "path.hpp"
00036 #include "integers.hpp"
00037 #include "entrepot.hpp"
00038 #include "tools.hpp"
00039 #include "slice_layout.hpp"
00040 
00041 namespace libdar
00042 {
00043     // contextual is defined in generic_file module
00044 
00047 
00054 
00055     class trivial_sar : public generic_file , public contextual, protected mem_ui
00056     {
00057     public:
00059     trivial_sar(const user_interaction & dialog,   //< how to interact with the user
00060             gf_mode open_mode,                 //< read_write or write_only are the only acceptable values
00061             const std::string & base_name,     //< archive basename to create
00062             const std::string & extension,     //< archive extension
00063             const entrepot & where,            //< where to store the archive
00064             const label & internal_nale,       //< tag common to all slices of the archive
00065             const label & data_name,           //< tag that follows the data when archive is dar_xform'ed
00066             const std::string & execute,       //< command line to execute at end of slice creation
00067             bool allow_over,                   //< whether to allow overwriting
00068             bool warn_over,                    //< whether to warn before overwriting
00069             bool force_permission,             //< whether to enforce slice permission or not
00070             U_I permission,                    //< value of permission to use if permission enforcement is used
00071             hash_algo x_hash,                  //< whether to build a hash of the slice, and which algo to use for that
00072                 const infinint & min_digits,       //< is the minimum number of digits the slices number is stored with in the filename
00073             bool format_07_compatible);        //< build a slice header backward compatible with 2.3.x
00074 
00075 
00077     trivial_sar(const user_interaction & dialog,   //< how to interact with the user
00078             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
00079             bool lax);                         //< whether to be laxist or follow the normal and strict controlled procedure
00080 
00081 
00083     trivial_sar(const user_interaction & dialog,
00084             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.
00085             const label & internal_name,
00086             const label & data_name,
00087             bool format_07_compatible,
00088             const std::string & execute);
00089 
00091     trivial_sar(const trivial_sar & ref) : generic_file(ref), mem_ui(ref) { throw SRC_BUG; };
00092 
00094     ~trivial_sar();
00095 
00096     const trivial_sar & operator = (const trivial_sar & ref) { throw SRC_BUG; };
00097     bool skippable(skippability direction, const infinint & amount) { return reference->skippable(direction, amount); };
00098         bool skip(const infinint & pos);
00099         bool skip_to_eof() { if(is_terminated()) throw SRC_BUG; return reference->skip_to_eof(); };
00100         bool skip_relative(S_I x);
00101         infinint get_position() const { return cur_pos; };
00102 
00103         // contextual inherited method
00104     bool is_an_old_start_end_archive() const { return old_sar; };
00105     const label & get_data_name() const { return of_data_name; };
00106 
00107     protected:
00108     void inherited_read_ahead(const infinint & amount) { reference->read_ahead(amount); };
00109         U_I inherited_read(char *a, U_I size);
00110         void inherited_write(const char *a, U_I size);
00111     void inherited_sync_write() {};
00112     void inherited_flush_read() {};
00113     void inherited_terminate();
00114 
00115     private:
00116         generic_file *reference;  //< points to the underlying data, owned by "this"
00117         infinint offset;          //< offset to apply to get the first byte of data out of SAR headers
00118     infinint cur_pos;         //< current position as returned by get_position()
00119     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
00120     std::string hook;         //< command to execute after slice writing (not used in read-only mode)
00121     std::string base;         //< basename of the archive (used for string susbstitution in hook)
00122     std::string ext;          //< extension of the archive (used for string substitution in hook)
00123     label of_data_name;       //< archive's data name
00124     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.
00125     infinint min_digits;      //< minimum number of digits in slice name
00126     std::string hook_where;   //< what value to use for %p subsitution in hook
00127 
00128     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
00129 
00130     void where_am_i();
00131     };
00132 
00133 
00135 
00136     extern std::string sar_make_filename(const std::string & base_name, const infinint & num, const infinint & min_digits, const std::string & ext);
00137 
00139 
00140 } // end of namespace
00141 
00142 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines