Disk ARchive  2.5.1
Full featured and portable backup and archiving tool
fichier_local.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 
26 
27 #ifndef FICHIER_LOCAL_HPP
28 #define FICHIER_LOCAL_HPP
29 
30 
31 #include "../my_config.h"
32 
33 extern "C"
34 {
35 #if HAVE_UNISTD_H
36 #include <unistd.h>
37 #endif
38 } // end extern "C"
39 
40 #include "integers.hpp"
41 #include "thread_cancellation.hpp"
42 #include "label.hpp"
43 #include "crc.hpp"
44 #include "user_interaction.hpp"
45 #include "mem_ui.hpp"
46 #include "fichier_global.hpp"
47 
48 #include <string>
49 
50 namespace libdar
51 {
52 
55 
56 
57  class fichier_local : public fichier_global
58  {
59  public :
60 
61  // constructors
62 
63  fichier_local(user_interaction & dialog,
64  const std::string & chemin,
65  gf_mode m,
66  U_I permission,
67  bool fail_if_exists,
68  bool erase,
69  bool furtive_mode);
70  fichier_local(const std::string & chemin, bool furtive_mode = false); // builds a read-only object
71  fichier_local(const fichier_local & ref) : fichier_global(ref) { copy_from(ref); };
72 
73  // assignment operator
74  const fichier_local & operator = (const fichier_local & ref) { detruit(); copy_parent_from(ref); copy_from(ref); return *this; };
75 
76  // destructor
77  ~fichier_local() { detruit(); };
78 
79 
81  virtual void change_ownership(const std::string & user, const std::string & group);
82 
84  virtual void change_permission(U_I perm);
85 
87  infinint get_size() const;
88 
90  void fadvise(advise adv) const;
91 
92  // inherited from generic_file
93  bool skippable(skippability direction, const infinint & amount) { return true; };
94  bool skip(const infinint & pos);
95  bool skip_to_eof();
96  bool skip_relative(S_I x);
97  infinint get_position() const;
98 
102  S_I give_fd_and_terminate() { int ret = filedesc; filedesc = -1; terminate(); return ret; };
103 
104  protected :
105  // inherited from generic_file grand-parent class
106  void inherited_read_ahead(const infinint & amount) { fadvise(fichier_global::advise_sequential); };
107  void inherited_sync_write() { fsync(); };
108  void inherited_flush_read() {}; // nothing stored in transit in this object
109  void inherited_terminate() { if(adv == advise_dontneed) fadvise(adv); };
110 
111  // inherited from fichier_global parent class
112  U_I fichier_global_inherited_write(const char *a, U_I size);
113  bool fichier_global_inherited_read(char *a, U_I size, U_I & read, std::string & message);
114 
115  private :
116  S_I filedesc;
117  advise adv;
118 
119  void open(const std::string & chemin,
120  gf_mode m,
121  U_I permission,
122  bool fail_if_exists,
123  bool erase,
124  bool furtive_mode);
125 
126  void copy_from(const fichier_local & ref);
127  void copy_parent_from(const fichier_local & ref);
128  void detruit() { if(filedesc >= 0) close(filedesc); filedesc = -1; };
129  int advise_to_int(advise arg) const;
130 
132 
136  void fsync() const;
137 
138  };
139 
141 
142 } // end of namespace
143 
144 #endif
class mem_ui definition. This class is to be used as parent class to handle user_interaction object m...
are defined here basic integer types that tend to be portable
class crc definition, used to handle Cyclic Redundancy Checks
define the datastructure "label" used to identify slice membership to an archive
gf_mode
generic_file openning modes
void terminate() const
destructor-like call, except that it is allowed to throw exceptions
defines the interaction between libdar and the user.Three classes are defined
class fichier_global definition. This class is a pure virtual class class fichier_global is an abstra...
to be able to cancel libdar operation while running in a given thread.the class thread_cancellation i...
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47