Disk ARchive  2.5.2
Full featured and portable backup and archiving tool
fichier_local.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 
00026 
00027 #ifndef FICHIER_LOCAL_HPP
00028 #define FICHIER_LOCAL_HPP
00029 
00030 
00031 #include "../my_config.h"
00032 
00033 extern "C"
00034 {
00035 #if HAVE_UNISTD_H
00036 #include <unistd.h>
00037 #endif
00038 } // end extern "C"
00039 
00040 #include "integers.hpp"
00041 #include "thread_cancellation.hpp"
00042 #include "label.hpp"
00043 #include "crc.hpp"
00044 #include "user_interaction.hpp"
00045 #include "mem_ui.hpp"
00046 #include "fichier_global.hpp"
00047 
00048 #include <string>
00049 
00050 namespace libdar
00051 {
00052 
00055 
00056 
00057     class fichier_local : public fichier_global
00058     {
00059     public :
00060 
00061         // constructors
00062 
00063         fichier_local(user_interaction & dialog,
00064               const std::string & chemin,
00065               gf_mode m,
00066               U_I permission,
00067               bool fail_if_exists,
00068               bool erase,
00069               bool furtive_mode);
00070     fichier_local(const std::string & chemin, bool furtive_mode = false); // builds a read-only object
00071     fichier_local(const fichier_local & ref) : fichier_global(ref) { copy_from(ref); };
00072 
00073         // assignment operator
00074     const fichier_local & operator = (const fichier_local & ref) { detruit(); copy_parent_from(ref); copy_from(ref); return *this; };
00075 
00076         // destructor
00077     ~fichier_local() { detruit(); };
00078 
00079 
00081     virtual void change_ownership(const std::string & user, const std::string & group);
00082 
00084     virtual void change_permission(U_I perm);
00085 
00087         infinint get_size() const;
00088 
00090     void fadvise(advise adv) const;
00091 
00092             // inherited from generic_file
00093     bool skippable(skippability direction, const infinint & amount) { return true; };
00094         bool skip(const infinint & pos);
00095         bool skip_to_eof();
00096         bool skip_relative(S_I x);
00097         infinint get_position() const;
00098 
00102     S_I give_fd_and_terminate() { int ret = filedesc; filedesc = -1; terminate(); return ret; };
00103 
00104     protected :
00105         // inherited from generic_file grand-parent class
00106     void inherited_read_ahead(const infinint & amount) { fadvise(fichier_global::advise_sequential); };
00107     void inherited_sync_write() { fsync(); };
00108     void inherited_flush_read() {}; // nothing stored in transit in this object
00109     void inherited_terminate() { if(adv == advise_dontneed) fadvise(adv); };
00110 
00111         // inherited from fichier_global parent class
00112     U_I fichier_global_inherited_write(const char *a, U_I size);
00113         bool fichier_global_inherited_read(char *a, U_I size, U_I & read, std::string & message);
00114 
00115     private :
00116         S_I filedesc;
00117     advise adv;
00118 
00119     void open(const std::string & chemin,
00120           gf_mode m,
00121           U_I permission,
00122           bool fail_if_exists,
00123           bool erase,
00124           bool furtive_mode);
00125 
00126     void copy_from(const fichier_local & ref);
00127     void copy_parent_from(const fichier_local & ref);
00128     void detruit() { if(filedesc >= 0) close(filedesc); filedesc = -1; };
00129     int advise_to_int(advise arg) const;
00130 
00132 
00136     void fsync() const;
00137 
00138     };
00139 
00141 
00142 } // end of namespace
00143 
00144 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines