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

Loading...
Searching...
No Matches
data_tree.hpp
Go to the documentation of this file.
1/*********************************************************************/
2// dar - disk archive - a backup/restoration program
3// Copyright (C) 2002-2025 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
25
26
27#ifndef DATA_TREE_HPP
28#define DATA_TREE_HPP
29
30#include "../my_config.h"
31
32#include <map>
33#include <string>
34#include <deque>
35#include <set>
36#include "infinint.hpp"
37#include "generic_file.hpp"
38#include "user_interaction.hpp"
39#include "path.hpp"
40#include "database_listing_callback.hpp"
41#include "database_aux.hpp"
42
43namespace libdar
44{
45
48
50
53 class data_tree
54 {
55 public:
56 data_tree(const std::string &name);
57 data_tree(generic_file & f, unsigned char db_version);
58 data_tree(const data_tree & ref) = default;
59 data_tree(data_tree && ref) noexcept = default;
60 data_tree & operator = (const data_tree & ref) = default;
61 data_tree & operator = (data_tree && ref) noexcept = default;
62 virtual ~data_tree() = default;
63
64 virtual void dump(generic_file & f) const;
65 std::string get_name() const { return filename; };
66 void set_name(const std::string & name) { filename = name; };
67
74 db_lookup get_data(std::set<archive_num> & archive, const datetime & date, bool even_when_removed) const;
75
77 db_lookup get_EA(archive_num & archive, const datetime & date, bool even_when_removed) const;
78
80 bool read_data(archive_num num,
81 datetime & val,
82 db_etat & present) const;
83
85 bool read_EA(archive_num num, datetime & val, db_etat & present) const;
86
87 void set_data(const archive_num & archive,
88 const datetime & date,
89 db_etat present) { set_data(archive, date, present, nullptr, nullptr); };
90
91 void set_data(const archive_num & archive,
92 const datetime & date,
93 db_etat present,
94 const crc *base,
95 const crc *result) { last_mod[archive] = status_plus(date, present, base, result); (void) check_delta_validity(); };
96
97 void set_EA(const archive_num & archive, const datetime & date, db_etat present) { status sta(date, present); last_change[archive] = sta; };
98
100 virtual bool check_order(user_interaction & dialog, const path & current_path, bool & initial_warn) const { return check_map_order(dialog, last_mod, current_path, "data", initial_warn) && check_map_order(dialog, last_change, current_path, "EA", initial_warn); };
101
103
111 virtual void finalize(const archive_num & archive,
112 const datetime & deleted_date,
113 const archive_num & ignore_archive_greater_or_equal);
114
116 virtual bool remove_all_from(const archive_num & archive_to_remove, const archive_num & last_archive);
117
119 void listing(database_listing_get_version_callback callback,
120 void *tag) const;
121 virtual void apply_permutation(archive_num src, archive_num dst);
122
124 virtual void skip_out(archive_num num);
125
127
135 virtual void compute_most_recent_stats(std::deque<infinint> & data,
136 std::deque<infinint> & ea,
137 std::deque<infinint> & total_data,
138 std::deque<infinint> & total_ea,
139 const datetime & ignore_older_than_that) const;
140
141
143
146 virtual void compute_restoration_needed_archives(std::deque<infinint> & data,
147 std::deque<infinint> & ea,
148 std::deque<infinint> & total_data,
149 std::deque<infinint> & total_ea,
150 const datetime & ignore_older_than_that) const;
151
152 virtual char obj_signature() const { return signature(); };
153 static char signature() { return 't'; };
154
155 // fix corruption case that was brought by bug in release 2.4.0 to 2.4.9
156 virtual bool fix_corruption(); // return true whether corruption could be fixed (meaning this entry can be safely removed from base)
157
158 private:
159
160 static constexpr const char * const ETAT_SAVED = "S";
161 static constexpr const char * const ETAT_PATCH = "O";
162 static constexpr const char * const ETAT_PATCH_UNUSABLE = "U";
163 static constexpr const char * const ETAT_PRESENT = "P";
164 static constexpr const char * const ETAT_REMOVED = "R";
165 static constexpr const char * const ETAT_ABSENT = "A";
166 static constexpr const char * const ETAT_INODE = "I";
167
168 static constexpr unsigned char STATUS_PLUS_FLAG_ME = 0x01;
169 static constexpr unsigned char STATUS_PLUS_FLAG_REF = 0x02;
170
171 class status
172 {
173 public:
174 status(): date(0) { present = db_etat::et_absent; };
175 status(const datetime & d, db_etat p) { date = d; present = p; };
176 status(const status & ref) = default;
177 status(status && ref) noexcept = default;
178 status & operator = (const status & ref) = default;
179 status & operator = (status && ref) noexcept = default;
180 virtual ~status() = default;
181
182 datetime date;
183 db_etat present;
184
185 virtual void dump(generic_file & f) const;
186 virtual void read(generic_file &f,
187 unsigned char db_version);
188 };
189
190
191 class status_plus : public status
192 {
193 public:
194 status_plus() { base = result = nullptr; };
195 status_plus(const datetime & d, db_etat p, const crc *xbase, const crc *xresult);
196 status_plus(const status_plus & ref): status(ref) { copy_from(ref); };
197 status_plus(status_plus && ref) noexcept: status(std::move(ref)) { nullifyptr(); move_from(std::move(ref)); };
198 status_plus & operator = (const status_plus & ref) { detruit(); copy_from(ref); return *this; };
199 status_plus & operator = (status_plus && ref) noexcept { status::operator = (std::move(ref)); move_from(std::move(ref)); return *this; };
200 ~status_plus() { detruit(); };
201
202 crc *base;
203 crc *result;
204
205 void dump(generic_file & f) const;
206 void read(generic_file &f,
207 unsigned char db_version);
208
209 private:
210 void nullifyptr() noexcept { base = result = nullptr; };
211 void copy_from(const status_plus & ref);
212 void move_from(status_plus && ref) noexcept;
213 void detruit();
214 };
215
216
217 std::string filename;
218 std::map<archive_num, status_plus> last_mod;
219 std::map<archive_num, status> last_change;
220
221
222 // when false is returned, this means that the user wants to ignore subsequent error of the same type
223 // else either no error yet met or user want to continue receiving the same type of error for other files
224 // in that later case initial_warn is set to false (first warning has been shown).
225 template <class T> bool check_map_order(user_interaction & dialog,
226 const std::map<archive_num, T> the_map,
227 const path & current_path,
228 const std::string & field_nature,
229 bool & initial_warn) const;
230
231 bool check_delta_validity(); // return true if no error has been met about delta patch (no delta is broken, missing its reference)
232
234
243 void compute_for_flag_set(std::deque<infinint> & data,
244 std::deque<infinint> & ea,
245 std::deque<infinint> & total_data,
246 std::deque<infinint> & total_ea,
247 const datetime & ignore_older_than_that,
248 const std::set<db_etat> & flag_set,
249 bool even_when_removed) const;
250
251
253
258 static archive_num data_tree_permutation(archive_num src, archive_num dst, archive_num x);
259
261 static void display_line(database_listing_get_version_callback callback,
262 void *tag,
263 archive_num num,
264 const datetime *data,
265 db_etat data_presence,
266 const datetime *ea,
267 db_etat ea_presence);
268
269 };
270
271
272
274
275} // end of namespace
276
277#endif
libdar::archive_num
class archive_num stores the position of an archive inside a dar_manager database
Definition archive_num.hpp:47
libdar::archive
the archive class realizes the most general operations on archives
Definition archive.hpp:68
libdar::crc
pure virtual class defining interface of a CRC object
Definition crc.hpp:47
libdar::data_tree
the data_tree class stores presence of a given file in a set of archives
Definition data_tree.hpp:54
libdar::data_tree::finalize
virtual void finalize(const archive_num &archive, const datetime &deleted_date, const archive_num &ignore_archive_greater_or_equal)
add deleted entry if no object of the current archive exist and the entry of the previous archive is ...
libdar::data_tree::last_mod
std::map< archive_num, status_plus > last_mod
key is archive number ; value is last_mod time
Definition data_tree.hpp:218
libdar::data_tree::remove_all_from
virtual bool remove_all_from(const archive_num &archive_to_remove, const archive_num &last_archive)
return true if the corresponding file is no more located in any archive (thus, the object is no more ...
libdar::data_tree::data_tree_permutation
static archive_num data_tree_permutation(archive_num src, archive_num dst, archive_num x)
gives new archive number when an database has its archive reordered
libdar::data_tree::compute_for_flag_set
void compute_for_flag_set(std::deque< infinint > &data, std::deque< infinint > &ea, std::deque< infinint > &total_data, std::deque< infinint > &total_ea, const datetime &ignore_older_than_that, const std::set< db_etat > &flag_set, bool even_when_removed) const
give number of entry's last state (for data and ea) per archive number, followed by the total number ...
libdar::data_tree::skip_out
virtual void skip_out(archive_num num)
decrement archive numbers above num
libdar::data_tree::check_order
virtual bool check_order(user_interaction &dialog, const path &current_path, bool &initial_warn) const
check date order between archives withing the database ; throw Erange if problem found with date orde...
Definition data_tree.hpp:100
libdar::data_tree::read_EA
bool read_EA(archive_num num, datetime &val, db_etat &present) const
return the date of last inode change and whether the EA has been saved or deleted
libdar::data_tree::get_EA
db_lookup get_EA(archive_num &archive, const datetime &date, bool even_when_removed) const
if EA has been saved alone later, returns in which version for the state of the file at the given dat...
libdar::data_tree::compute_restoration_needed_archives
virtual void compute_restoration_needed_archives(std::deque< infinint > &data, std::deque< infinint > &ea, std::deque< infinint > &total_data, std::deque< infinint > &total_ea, const datetime &ignore_older_than_that) const
provide a summary of the archives that will be required to restore the data in the latest state
libdar::data_tree::dump
virtual void dump(generic_file &f) const
dump signature followed by data constructor will read
libdar::data_tree::compute_most_recent_stats
virtual void compute_most_recent_stats(std::deque< infinint > &data, std::deque< infinint > &ea, std::deque< infinint > &total_data, std::deque< infinint > &total_ea, const datetime &ignore_older_than_that) const
provide a summary of the latest version of file and ea per archive number of the database
libdar::data_tree::last_change
std::map< archive_num, status > last_change
key is archive number ; value is last_change time
Definition data_tree.hpp:219
libdar::data_tree::data_tree
data_tree(generic_file &f, unsigned char db_version)
constructor does not read signature
libdar::data_tree::listing
void listing(database_listing_get_version_callback callback, void *tag) const
list where is saved this file
libdar::data_tree::get_data
db_lookup get_data(std::set< archive_num > &archive, const datetime &date, bool even_when_removed) const
libdar::data_tree::display_line
static void display_line(database_listing_get_version_callback callback, void *tag, archive_num num, const datetime *data, db_etat data_presence, const datetime *ea, db_etat ea_presence)
helper method to provide information to a database_listing_get_version_callback
libdar::data_tree::read_data
bool read_data(archive_num num, datetime &val, db_etat &present) const
return the date of file's last modification date within the give archive and whether the file has bee...
libdar::datetime
stores time information
Definition datetime.hpp:59
libdar::generic_file
this is the interface class from which all other data transfer classes inherit
Definition generic_file.hpp:77
libdar::path
the class path is here to manipulate paths in the Unix notation: using'/'
Definition path.hpp:51
libdar::user_interaction
This is a pure virtual class that is used by libdar when interaction with the user is required.
Definition user_interaction.hpp:58
database_aux.hpp
set of datastructures used to interact with a database object
database_listing_callback.hpp
definition of the user defined callback function used for database listing
generic_file.hpp
class generic_file is defined here as well as class fichier
libdar::db_lookup
db_lookup
the available status of a lookup
Definition database_aux.hpp:41
libdar::db_etat
db_etat
the status for a founded entry
Definition database_aux.hpp:55
libdar::database_listing_get_version_callback
void(*)(void *context, archive_num num, db_etat data_presence, bool has_data_date, datetime data, db_etat ea_presence, bool has_ea_date, datetime ea) database_listing_get_version_callback
called with the information of presence for an entry in archive number num
Definition database_listing_callback.hpp:63
libdar::db_etat::et_absent
@ et_absent
file not even mentionned in the archive, This entry is equivalent to et_removed, but is required to b...
infinint.hpp
switch module to limitint (32 ou 64 bits integers) or infinint
my_config.h
include macro defined by the configure script and some specific additional ones
libdar
libdar namespace encapsulate all libdar symbols
Definition archive.hpp:47
path.hpp
here is the definition of the path class
user_interaction.hpp
defines the interaction interface between libdar and users.