Disk ARchive 2.7.16
Full featured and portable backup and archiving tool
entrepot.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
32
33#ifndef ENTREPOT_HPP
34#define ENTREPOT_HPP
35
36#include "../my_config.h"
37
38#include <string>
39#include <memory>
40#include "user_interaction.hpp"
41#include "path.hpp"
42#include "archive_aux.hpp"
43#include "gf_mode.hpp"
44
45namespace libdar
46{
49
50 // no need to dig into this from API header
51 class fichier_global;
52
54
56 {
57 public:
58
61
63 entrepot(const entrepot & ref) = default;
64
66 entrepot(entrepot && ref) noexcept = default;
67
69 entrepot & operator = (const entrepot & ref) = default;
70
72 entrepot & operator = (entrepot && ref) noexcept = default;
73
75 virtual ~entrepot() = default;
76
78 bool operator == (const entrepot & ref) const { return get_url() == ref.get_url(); };
79
80
82 virtual void set_location(const path & chemin);
83
85 virtual void set_root(const path & p_root);
86
88
90 virtual path get_full_path() const;
91
93 virtual std::string get_url() const = 0;
94
96 void set_user_ownership(const std::string & x_user) { user = x_user; };
97 void set_group_ownership(const std::string & x_group) { group = x_group; };
98
99 virtual const path & get_location() const { return where; }; //< retreives relative to root path the current location points to
100 virtual const path & get_root() const { return root; }; //< retrieves the given root location
101
102 const std::string & get_user_ownership() const { return user; };
103 const std::string & get_group_ownership() const { return group; };
104
106
118 fichier_global *open(const std::shared_ptr<user_interaction> & dialog,
119 const std::string & filename,
120 gf_mode mode,
121 bool force_permission,
122 U_I permission,
123 bool fail_if_exists,
124 bool erase,
125 hash_algo algo,
126 bool provide_a_plain_file = true) const;
127
129 virtual void read_dir_reset() const = 0;
130 virtual bool read_dir_next(std::string & filename) const = 0;
131
132 void unlink(const std::string & filename) const { inherited_unlink(filename); }; //< done this way for homogeneity with open/inherited_open
133
135
138 virtual entrepot *clone() const = 0;
139
140 protected:
141 virtual fichier_global *inherited_open(const std::shared_ptr<user_interaction> & dialog, //< for user interaction
142 const std::string & filename, //< filename to open
143 gf_mode mode, //< mode to use
144 bool force_permission, //< set the permission of the file to open
145 U_I permission, //< value of the permission to assign when force_permission is true
146 bool fail_if_exists, //< whether to fail if file exists (write mode)
147 bool erase) const = 0; //< whether to erase file if file already exists (write mode)
148
149 virtual void inherited_unlink(const std::string & filename) const = 0;
150
151 virtual void read_dir_flush() = 0; //< ends the read_dir_next, (no more entry available)
152
153 private:
154 path where;
155 path root;
156 std::string user;
157 std::string group;
158 };
159
161
162} // end of namespace
163
164#endif
set of datastructures used to interact with a catalogue object
the Entrepot interface
Definition: entrepot.hpp:56
fichier_global * open(const std::shared_ptr< user_interaction > &dialog, const std::string &filename, gf_mode mode, bool force_permission, U_I permission, bool fail_if_exists, bool erase, hash_algo algo, bool provide_a_plain_file=true) const
defines the way to open a file and return a "class fichier_global" object as last argument upon succe...
virtual path get_full_path() const
returns the full path of location
virtual void read_dir_reset() const =0
routines to read existing files in the current directory (see set_location() / set_root() methods)
entrepot(entrepot &&ref) noexcept=default
move constructor
entrepot()
constructor
entrepot(const entrepot &ref)=default
copy constructor
virtual void set_location(const path &chemin)
defines the directory where to proceed to future open() – this is a "chdir" semantics
bool operator==(const entrepot &ref) const
says whether two entrepot objects points to the same location
Definition: entrepot.hpp:78
void set_user_ownership(const std::string &x_user)
set default ownership for files to be created thanks to the open() methods
Definition: entrepot.hpp:96
virtual ~entrepot()=default
destructor
entrepot & operator=(const entrepot &ref)=default
assignment operator
virtual std::string get_url() const =0
full path of current directory + anything necessary to provide URL formated information
virtual void set_root(const path &p_root)
defines the root to use if set_location is given a relative path
virtual entrepot * clone() const =0
generate a clone of "this"
abstraction of filesystem files for entrepot
the class path is here to manipulate paths in the Unix notation: using'/'
Definition: path.hpp:51
generic modes to open file
hash_algo
hashing algorithm available
Definition: archive_aux.hpp:63
gf_mode
generic_file openning modes
Definition: gf_mode.hpp:44
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47
here is the definition of the path class
defines the interaction interface between libdar and users.