Disk ARchive  2.7.15
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-2024 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, see the AUTHOR file
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 "user_interaction.hpp"
42 #include "fichier_global.hpp"
43 
44 #include <string>
45 
46 namespace libdar
47 {
48 
51 
52 
54 
56  {
57  public :
58 
60  fichier_local(const std::shared_ptr<user_interaction> & dialog,
61  const std::string & chemin,
62  gf_mode m,
63  U_I permission,
64  bool fail_if_exists,
65  bool erase,
66  bool furtive_mode);
67 
69 
71  fichier_local(const std::string & chemin, bool furtive_mode = false);
72 
74  fichier_local(const fichier_local & ref) : fichier_global(ref) { copy_from(ref); };
75 
77  fichier_local(fichier_local && ref) noexcept: fichier_global(std::move(ref)) { move_from(std::move(ref)); };
78 
80  fichier_local & operator = (const fichier_local & ref) { detruit(); copy_from(ref); return *this; };
81 
83  fichier_local & operator = (fichier_local && ref) noexcept { fichier_global::operator = (std::move(ref)); move_from(std::move(ref)); return *this; };
84 
86  ~fichier_local() { detruit(); };
87 
88 
90  virtual void change_ownership(const std::string & user, const std::string & group) override;
91 
93  virtual void change_permission(U_I perm) override;
94 
96  virtual infinint get_size() const override;
97 
99  virtual void fadvise(advise adv) const override;
100 
101  // inherited from generic_file
102  virtual bool skippable(skippability direction, const infinint & amount) override { return true; };
103  virtual bool skip(const infinint & pos) override;
104  virtual bool skip_to_eof() override;
105  virtual bool skip_relative(S_I x) override;
106  virtual bool truncatable(const infinint & pos) const override { return true; };
107  virtual infinint get_position() const override;
108 
110 
112  S_I give_fd_and_terminate() { int ret = filedesc; filedesc = -1; terminate(); return ret; };
113 
114  protected :
115  // inherited from generic_file grand-parent class
116  virtual void inherited_truncate(const infinint & pos) override;
117  virtual void inherited_read_ahead(const infinint & amount) override {}; // nothing done, calling readahead(2) could be added in the future
118  virtual void inherited_sync_write() override { fsync(); };
119  virtual void inherited_flush_read() override {}; // nothing stored in transit in this object
120  virtual void inherited_terminate() override { if(adv == advise_dontneed) fadvise(adv); };
121 
122  // inherited from fichier_global parent class
123  virtual U_I fichier_global_inherited_write(const char *a, U_I size) override;
124  virtual bool fichier_global_inherited_read(char *a, U_I size, U_I & read, std::string & message) override;
125 
126  private :
127  S_I filedesc;
128  advise adv;
129 
130  void open(const std::string & chemin,
131  gf_mode m,
132  U_I permission,
133  bool fail_if_exists,
134  bool erase,
135  bool furtive_mode);
136 
137  void copy_from(const fichier_local & ref);
138  void move_from(fichier_local && ref) noexcept;
139  void detruit() { if(filedesc >= 0) close(filedesc); filedesc = -1; };
140  int advise_to_int(advise arg) const;
141 
143 
147  void fsync() const;
148 
149  off_t get_eof_offset() const;
150 
151  };
152 
154 
155 } // end of namespace
156 
157 #endif
abstraction of filesystem files for entrepot
@ advise_dontneed
application will not read the data in near future
fichier_global & operator=(const fichier_global &ref)=default
assignment operator
fichier_global(const std::shared_ptr< user_interaction > &dialog, gf_mode mode)
constructor
filesystem local files
virtual bool fichier_global_inherited_read(char *a, U_I size, U_I &read, std::string &message) override
replaces generic_file::inherited_read() method, to allow the return of partial reading
virtual void change_permission(U_I perm) override
change the permission of the file
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...
fichier_local(const fichier_local &ref)
copy constructor
virtual void inherited_terminate() override
destructor-like call, except that it is allowed to throw exceptions
fichier_local(const std::shared_ptr< user_interaction > &dialog, const std::string &chemin, gf_mode m, U_I permission, bool fail_if_exists, bool erase, bool furtive_mode)
full featured constructors
virtual bool truncatable(const infinint &pos) const override
whether the implementation is able to truncate to the given position
fichier_local & operator=(const fichier_local &ref)
assignment operator
virtual bool skip(const infinint &pos) override
skip at the absolute position
virtual bool skip_to_eof() override
skip to the end of file
virtual void inherited_flush_read() override
reset internal engine, flush caches in order to read the data at current position
virtual bool skip_relative(S_I x) override
skip relatively to the current position
virtual void inherited_sync_write() override
write down any pending data
fichier_local(const std::string &chemin, bool furtive_mode=false)
constructor without user_interaction
fichier_local(fichier_local &&ref) noexcept
move constructor
~fichier_local()
destructor
virtual infinint get_size() const override
return the size of the file
virtual void fadvise(advise adv) const override
set posix_fadvise for the whole file
virtual void change_ownership(const std::string &user, const std::string &group) override
set the ownership of the file
virtual infinint get_position() const override
get the current read/write position
virtual U_I fichier_global_inherited_write(const char *a, U_I size) override
replaces generic_file::inherited_write() method, to allow the return of partial writings
virtual void inherited_truncate(const infinint &pos) override
truncate file at the give offset
S_I give_fd_and_terminate()
provide the low level filedescriptor to the call and terminate()
void fsync() const
sync the data to disk
virtual bool skippable(skippability direction, const infinint &amount) override
whether the implementation is able to skip
void terminate()
destructor-like call, except that it is allowed to throw exceptions
virtual U_I read(char *a, U_I size) override
read data from the generic_file inherited from proto_generic_file
the arbitrary large positive integer class
class fichier_global definition. This class is a pure virtual class class fichier_global is an abstra...
gf_mode
generic_file openning modes
Definition: gf_mode.hpp:44
are defined here basic integer types that tend to be portable
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47
defines the interaction interface between libdar and users.