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 // $Id: entrepot.hpp,v 1.1 2012/04/27 11:24:30 edrusb Exp $ 22 // 23 /*********************************************************************/ 24 25 26 /// \file entrepot.hpp 27 /// \brief defines the entrepot interface. 28 /// Entrepot interface defines a generic way to interact with files (slices) 29 /// on a filesystem. It is used to instanciate file-like objects (from class inherited 30 /// from class fichier_global, in order to read or write data to such file. 31 /// The entrepot_local and fichier_local classes are the only one classes 32 /// available from libdar to implement the entrepot and fichier classes interfaces 33 /// respectively. External applications like webdar can implement entrepot_ftp 34 /// and fichier_ftp classes to provide transparent access to dar backup localted on a 35 /// remote ftp server. More can follow in the future. 36 37 /// \ingroup Private 38 39 #ifndef ENTREPOT_HPP 40 #define ENTREPOT_HPP 41 42 #include "../my_config.h" 43 44 #include <string> 45 #include "infinint.hpp" 46 #include "generic_file.hpp" 47 #include "user_interaction.hpp" 48 #include "fichier_global.hpp" 49 #include "hash_fichier.hpp" 50 #include "etage.hpp" 51 #include "path.hpp" 52 #include "on_pool.hpp" 53 54 namespace libdar 55 { 56 /// \addtogroup Private 57 /// @{ 58 59 /// the Entrepot interface 60 61 class entrepot : public on_pool 62 { 63 public: 64 65 /// constructor 66 entrepot(); 67 68 /// destructor ~entrepot()69 virtual ~entrepot() {}; 70 71 /// says whether two entrepot objects points to the same location operator ==(const entrepot & ref) const72 bool operator == (const entrepot & ref) const { return get_url() == ref.get_url(); }; 73 74 75 /// defines the directory where to proceed to future open() -- this is a "chdir" semantics 76 void set_location(const path & chemin); 77 78 /// defines the root to use if set_location is given a relative path set_root(const path & p_root)79 void set_root(const path & p_root) { if(p_root.is_relative()) throw Erange("entrepot::set_root", std::string(gettext("root's entrepot must be an absolute path: ")) + p_root.display()); root = p_root; }; 80 81 /// set default ownership for files to be created thanks to the open() methods set_user_ownership(const std::string & x_user)82 void set_user_ownership(const std::string & x_user) { user = x_user; }; set_group_ownership(const std::string & x_group)83 void set_group_ownership(const std::string & x_group) { group = x_group; }; 84 get_location() const85 const path & get_location() const { return where; }; //< retreives relative to root path the current location points to get_root() const86 const path & get_root() const { return root; }; //< retrieves the given root location 87 path get_full_path() const; 88 virtual std::string get_url() const = 0; //< defines an URL-like normalized full location of slices get_user_ownership() const89 const std::string & get_user_ownership() const { return user; }; get_group_ownership() const90 const std::string & get_group_ownership() const { return group; }; 91 92 /// defines the way to open a file and return a "class fichier_global" object as last argument upon success 93 /// 94 /// \param[in] dialog for user interaction 95 /// \param[in] filename is the full path+name of the file to open (read/create/write to) 96 /// \param[in] mode defines which way to open the file (read-only, read-write or write-only) 97 /// \param[in] force_permission whether to set the file permission to the value given in the permission argument 98 /// \param[in] permission if force_permission is set, change the file permission to that value 99 /// \param[in] fail_if_exists tells whether the underlying implementation have to fail throwing Erange("exists") if the file already exist when write access is required 100 /// \param[in] erase tells whether the underlying implementation will empty an existing file before writing to it 101 /// \param[in] algo defines the hash file to create, other value than hash_none are accepted only in writeonly mode with erase or fail_if_exist set 102 /// \return upon success returns an object from a class inherited from fichier_global that the caller has the duty to delete, else an exception is thrown (most of the time it should be a Esystem object) 103 /// by the called inherited class 104 fichier_global *open(user_interaction & dialog, 105 const std::string & filename, 106 gf_mode mode, 107 bool force_permission, 108 U_I permission, 109 bool fail_if_exists, 110 bool erase, 111 hash_algo algo) const; 112 113 /// routines to read existing files in the current directory (see set_location() / set_root() methods) 114 virtual void read_dir_reset() = 0; 115 virtual bool read_dir_next(std::string & filename) = 0; 116 unlink(const std::string & filename) const117 void unlink(const std::string & filename) const { inherited_unlink(filename); }; //< done this way for homogeneity with open/inherited_open 118 119 120 virtual entrepot *clone() const = 0; 121 122 protected: 123 virtual fichier_global *inherited_open(user_interaction & dialog, //< for user interaction 124 const std::string & filename, //< filename to open 125 gf_mode mode, //< mode to use 126 bool force_permission, //< set the permission of the file to open 127 U_I permission, //< value of the permission to assign when force_permission is true 128 bool fail_if_exists, //< whether to fail if file exists (write mode) 129 bool erase) const = 0; //< whether to erase file if file already exists (write mode) 130 131 virtual void inherited_unlink(const std::string & filename) const = 0; 132 133 virtual void read_dir_flush() = 0; //< ends the read_dir_next, (no more entry available) 134 135 private: 136 path where; 137 path root; 138 std::string user; 139 std::string group; 140 }; 141 142 /// @} 143 144 } // end of namespace 145 146 #endif 147