| Disk ARchive 2.6.11 Full featured and portable backup and archiving tool

filesystem_restore.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2020 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 : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21
25
26 #ifndef FILESYSTEM_RESTORE_HPP
27 #define FILESYSTEM_RESTORE_HPP
28
29 #include "../my_config.h"
30
31 extern "C"
32 {
33 #if HAVE_UNISTD_H
34 #include <unistd.h>
35 #endif
36
37 #if HAVE_SYS_STAT_H
38 #include <sys/stat.h>
39 #endif
40 } // end extern "C"
41
42 #include <deque>
43 #include "crit_action.hpp"
44 #include "fsa_family.hpp"
45 #include "cat_all_entrees.hpp"
46 #include "filesystem_hard_link_read.hpp"
47 #include "filesystem_hard_link_write.hpp"
48
49 #include <set>
50
51 namespace libdar
52 {
55
57
58 class filesystem_restore : public filesystem_hard_link_write, public filesystem_hard_link_read
59 {
60 public:
62 filesystem_restore(const std::shared_ptr<user_interaction> & dialog,
63 const path & root,
64 bool x_warn_overwrite,
65 bool x_info_details,
66 const mask & x_ea_mask,
67 comparison_fields what_to_check,
68 bool x_warn_remove_no_match,
69 bool empty,
70 const crit_action *x_overwrite,
71 bool x_only_overwrite,
72 const fsa_scope & scope);
73
75 filesystem_restore(const filesystem_restore & ref) = delete;
76
78 filesystem_restore(filesystem_restore && ref) = delete;
79
81 filesystem_restore & operator = (const filesystem_restore & ref) = delete;
82
84 filesystem_restore & operator = (filesystem_restore && ref) = delete;
85
87 ~filesystem_restore() { restore_stack_dir_ownership(); detruire(); };
88
90 void reset_write();
91
92 using action_done_for_data = enum
93 {
94 done_data_restored, //< data has been restored to filesystem
95 done_no_change_no_data, //< no change in filesystem because no data present in archive
96 done_no_change_policy, //< no change in filesystem because of overwiting policy decision
97 done_data_removed //< data (= whole inode) removed from filesystem
98 };
99
101
110 void write(const cat_entree *x,
111 action_done_for_data & data_restored,
112 bool & ea_restored,
113 bool & data_created,
114 bool & hard_link,
115 bool & fsa_restored);
116
117
119
123 void ignore_overwrite_restrictions_for_next_write() { ignore_over_restricts = true; };
124
125
126 private:
127 class stack_dir_t : public cat_directory
128 {
129 public:
130 stack_dir_t(const cat_directory & ref, bool restore) : cat_directory(ref) { restore_date = restore; };
131
132 bool get_restore_date() const { return restore_date; };
133 void set_restore_date(bool val) { restore_date = val; };
134
135 private:
136 bool restore_date;
137 };
138
139 path *fs_root;
140 bool info_details;
141 mask *ea_mask;
142 bool warn_overwrite;
143 comparison_fields what_to_check;
144 bool warn_remove_no_match;
145 std::deque<stack_dir_t> stack_dir;
146 path *current_dir;
147 bool empty;
148 bool ignore_over_restricts;
149 const crit_action *overwrite;
150 bool only_overwrite;
151
152 void detruire();
153 void restore_stack_dir_ownership();
154 user_interaction & get_ui() const { return filesystem_hard_link_read::get_ui(); };
155 std::shared_ptr<user_interaction> get_pointer() const { return filesystem_hard_link_read::get_pointer(); };
156
157 // subroutines of write()
158
160 void action_over_remove(const cat_inode *in_place,
161 const cat_detruit *to_be_added,
162 const std::string & spot,
163 over_action_data action);
165 void action_over_data(const cat_inode *in_place,
166 const cat_nomme *to_be_added,
167 const std::string & spot,
168 over_action_data action,
169 action_done_for_data & data_done);
171 bool action_over_ea(const cat_inode *in_place,
172 const cat_nomme *to_be_added,
173 const std::string & spot,
174 over_action_ea action);
176 bool action_over_fsa(const cat_inode *in_place,
177 const cat_nomme *to_be_added,
178 const std::string & spot,
179 over_action_ea action);
180
181 };
182
184
185 } // end of namespace
186
187 #endif
libdar::filesystem_restore::write
void write(const cat_entree *x, action_done_for_data &data_restored, bool &ea_restored, bool &data_created, bool &hard_link, bool &fsa_restored)
restore a libdar object to a filesystem entry both data and EA
libdar::mem_ui::get_ui
user_interaction & get_ui() const
get access to the user_interaction object
Definition: mem_ui.hpp:95
cat_all_entrees.hpp
include file gathering all entree found in a catalogue
libdar::filesystem_restore::action_over_ea
bool action_over_ea(const cat_inode *in_place, const cat_nomme *to_be_added, const std::string &spot, over_action_ea action)
perform action for EA due to overwriting policy
libdar::filesystem_restore::action_over_fsa
bool action_over_fsa(const cat_inode *in_place, const cat_nomme *to_be_added, const std::string &spot, over_action_ea action)
perform action for FSA due to overwriting policy
libdar::filesystem_restore::filesystem_restore
filesystem_restore(const filesystem_restore &ref)=delete
copy constructor is forbidden
libdar::filesystem_restore::filesystem_restore
filesystem_restore(filesystem_restore &&ref)=delete
move constructor is forbidden
libdar::filesystem_restore::filesystem_restore
filesystem_restore(const std::shared_ptr< user_interaction > &dialog, const path &root, bool x_warn_overwrite, bool x_info_details, const mask &x_ea_mask, comparison_fields what_to_check, bool x_warn_remove_no_match, bool empty, const crit_action *x_overwrite, bool x_only_overwrite, const fsa_scope &scope)
constructor
libdar::cat_nomme
the base class for all entry that have a name
Definition: cat_nomme.hpp:45
libdar::filesystem_restore::operator=
filesystem_restore & operator=(const filesystem_restore &ref)=delete
assignment operator is forbidden
libdar::cat_detruit
the deleted file entry
Definition: cat_detruit.hpp:49
libdar::mask
the generic class, parent of all masks
Definition: mask.hpp:62
libdar::over_action_ea
over_action_ea
the possible action for overwriting EA
Definition: crit_action.hpp:62
libdar::cat_entree
the root class from all other inherite for any entry in the catalogue
Definition: cat_entree.hpp:60
libdar::filesystem_hard_link_read
keep trace of hard links when reading the filesystem
Definition: filesystem_hard_link_read.hpp:58
libdar::cat_inode
the root class for all cat_inode
Definition: cat_inode.hpp:53
filesystem_hard_link_read.hpp
filesystem_hard_link_read classes manages hardlinked inode read from filesystem
libdar::filesystem_restore::reset_write
void reset_write()
reset the writing process for the current object
libdar::path
the class path is here to manipulate paths in the Unix notation: using'/'
Definition: path.hpp:51
libdar::filesystem_restore::action_over_data
void action_over_data(const cat_inode *in_place, const cat_nomme *to_be_added, const std::string &spot, over_action_data action, action_done_for_data &data_done)
perform action for data due to the overwriting policy when the "to be added" entry is not a cat_detru...
libdar::filesystem_restore::~filesystem_restore
~filesystem_restore()
destructor
Definition: filesystem_restore.hpp:87
libdar::filesystem_restore::action_over_remove
void action_over_remove(const cat_inode *in_place, const cat_detruit *to_be_added, const std::string &spot, over_action_data action)
perform action due to the overwriting policy when the "to be added" entry is a detruit object
libdar::filesystem_hard_link_write
keep trace of already written inodes to restore hard links
Definition: filesystem_hard_link_write.hpp:58
filesystem_hard_link_write.hpp
class filesystem_hard_link_write keeps trace of already written inode to restore hard links
libdar::filesystem_restore
receive the flow of inode from the restoration filtering routing and promotes these to real filesyste...
Definition: filesystem_restore.hpp:59
libdar::comparison_fields
comparison_fields
how to consider file change during comparison and incremental backup
Definition: archive_aux.hpp:53
fsa_family.hpp
filesystem specific attributes available families and fsa_scope definition
libdar::mem_ui::get_pointer
std::shared_ptr< user_interaction > get_pointer() const
get access to the shared_ptr pointing to the user_interaction
Definition: mem_ui.hpp:98
libdar::cat_directory
the cat_directory inode class
Definition: cat_directory.hpp:52
libdar::filesystem_restore::ignore_overwrite_restrictions_for_next_write
void ignore_overwrite_restrictions_for_next_write()
ask for no warning or user interaction for the next write operation
Definition: filesystem_restore.hpp:123
libdar::crit_action
the global action for overwriting
Definition: crit_action.hpp:81
crit_action.hpp
contains classes that let the user define the policy for overwriting files
libdar::over_action_data
over_action_data
the possible actions for overwriting data
Definition: crit_action.hpp:47
libdar::fsa_scope
std::set< fsa_family > fsa_scope
set of fsa families
Definition: fsa_family.hpp:70
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47