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

Loading...
Searching...
No Matches
list_entry.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 LIST_ENTRY_HPP
28#define LIST_ENTRY_HPP
29
30#include <string>
31#include <set>
32
33#include "../my_config.h"
34#include "infinint.hpp"
35#include "deci.hpp"
36#include "compression.hpp"
37#include "integers.hpp"
38#include "datetime.hpp"
39#include "range.hpp"
40#include "cat_status.hpp"
41#include "ea.hpp"
42#include "fsa_family.hpp"
43
44namespace libdar
45{
46
49
50 class crc;
51
59 class list_entry
60 {
61 public:
62 list_entry() { clear(); };
63 list_entry(const list_entry & ref) = default;
64 list_entry(list_entry && ref) = default;
65 list_entry & operator = (const list_entry & ref) = default;
66 list_entry & operator = (list_entry && ref) noexcept = default;
67 ~list_entry() = default;
68
70
74 bool is_eod() const { return type == 'z'; };
75
76 // methods for API users
77 // field that are not set are returned as empty string
78
79 const std::string & get_name() const { return my_name; };
80 unsigned char get_type() const { return type; };
81 bool is_dir() const { return type == 'd'; };
82 bool is_file() const { return type == 'f'; };
83 bool is_symlink() const { return type == 'l'; };
84 bool is_char_device() const { return type == 'c'; };
85 bool is_block_device() const { return type == 'b'; };
86 bool is_unix_socket() const { return type == 's'; };
87 bool is_named_pipe() const { return type == 'p'; };
88 bool is_hard_linked() const { return hard_link; };
89 bool is_removed_entry() const { return type == 'x'; };
90 bool is_door_inode() const { return type == 'o'; };
91 bool is_empty_dir() const { return empty_dir; };
92
93 unsigned char get_removed_type() const;
94
95 bool has_data_present_in_the_archive() const { return data_status == saved_status::saved || data_status == saved_status::delta; };
96 std::string get_data_flag() const;
97 saved_status get_data_status() const { return data_status; };
98
99 bool has_EA() const { return ea_status != ea_saved_status::none && ea_status != ea_saved_status::removed; };
100 bool has_EA_saved_in_the_archive() const { return ea_status == ea_saved_status::full; };
101 std::string get_ea_flag() const;
102 ea_saved_status get_ea_status() const { return ea_status; };
103
104 bool has_FSA() const { return fsa_status != fsa_saved_status::none; };
105 bool has_FSA_saved_in_the_archive() const { return fsa_status == fsa_saved_status::full; };
106 std::string get_fsa_flag() const;
107
108 std::string get_uid(bool try_resolving_name = false) const;
109 std::string get_gid(bool try_resolving_name = false) const;
110 std::string get_perm() const;
111
114 void set_fully_detailed_dates(bool mode) const { full_date = mode; };
115 std::string get_last_access() const;
116 std::string get_last_modif() const;
117 std::string get_last_change() const;
118 std::string get_removal_date() const;
119 time_t get_last_access_s() const { return datetime2time_t(last_access); };
120 time_t get_last_modif_s() const;
121 time_t get_last_change_s() const { return datetime2time_t(last_change); };
122 time_t get_removal_date_s() const;
123
125
129 void get_last_access(datetime::time_unit tu, time_t & second, time_t & fraction) const
130 { last_access.get_value(second, fraction, tu); }
131
133 void get_last_modif(datetime::time_unit tu, time_t & second, time_t & fraction) const
134 { last_modif.get_value(second, fraction, tu); }
135
137 void get_last_change(datetime::time_unit tu, time_t & second, time_t & fraction) const
138 { last_change.get_value(second, fraction, tu); }
139
140 std::string get_file_size(bool size_in_bytes = true) const;
141 std::string get_compression_ratio() const;
142 std::string get_compression_ratio_flag() const;
143 bool is_sparse() const { return sparse_file; };
144 std::string get_sparse_flag() const { return sparse_file ? "[X]" : "[ ]"; };
145 std::string get_compression_algo() const { return compression2string(compression_algo); };
146 bool is_dirty() const { return dirty; };
147 std::string get_link_target() const { return target; };
148 std::string get_major() const;
149 std::string get_minor() const;
150
152
156 const range & get_slices() const { return slices; };
157 bool has_delta_signature() const { return delta_sig; };
158 std::string get_delta_flag() const;
159
160
162
172 bool get_archive_offset_for_data(infinint & val) const { val = offset_for_data; return !val.is_zero(); };
173 bool get_archive_offset_for_data(U_64 & val) const;
174 std::string get_archive_offset_for_data() const { return offset_for_data.is_zero() ? "" : deci(offset_for_data).human(); };
175
177
180 bool get_storage_size_for_data(infinint & val) const { val = storage_size_for_data; return !val.is_zero(); };
181 bool get_storage_size_for_data(U_64 & val) const;
182 std::string get_storage_size_for_data(bool size_in_bytes = true) const;
183
185
189 bool get_archive_offset_for_EA(infinint & val) const { val = offset_for_EA; return !val.is_zero(); };
190 bool get_archive_offset_for_EA(U_64 & val) const;
191 std::string get_archive_offset_for_EA() const { return offset_for_EA.is_zero() ? "" : deci(offset_for_EA).human(); };
192
194 bool get_storage_size_for_EA(infinint & val) const { val = storage_size_for_EA; return !val.is_zero(); };
195 bool get_storage_size_for_EA(U_64 & val) const;
196 std::string get_storage_size_for_EA() const { return storage_size_for_EA.is_zero() ? "" : deci(storage_size_for_EA).human(); };
197
199
203 bool get_archive_offset_for_FSA(infinint & val) const { val = offset_for_FSA; return !val.is_zero(); };
204 bool get_archive_offset_for_FSA(U_64 & val) const;
205 std::string get_archive_offset_for_FSA() const { return offset_for_FSA.is_zero() ? "" : deci(offset_for_FSA).human(); };
206
208 bool get_storage_size_for_FSA(infinint & val) const { val = storage_size_for_FSA; return !val.is_zero(); };
209 bool get_storage_size_for_FSA(U_64 & val) const;
210 std::string get_storage_size_for_FSA() const { return storage_size_for_FSA.is_zero() ? "" : deci(storage_size_for_FSA).human(); };
211
213
215 void get_ea_reset_read() const { it_ea = ea.begin(); };
216
218
224 bool get_ea_read_next(std::string & key) const;
225
226 std::string get_etiquette() const { return deci(etiquette).human(); };
227
228 fsa_scope get_fsa_scope() const { return fsa_sc; };
229
230 std::string get_data_crc() const { return data_crc; };
231 std::string get_delta_patch_base_crc() const { return patch_base_crc; };
232 std::string get_delta_patch_result_crc() const { return patch_result_crc; };
233
234 // methods for libdar to setup the object
235
236 void set_name(const std::string & val) { my_name = val; };
237 void set_type(unsigned char val) { type = val; };
238 void set_removed_type(unsigned char val);
239 void set_hard_link(bool val) { hard_link = val; };
240 void set_uid(const infinint & val) { uid = val; };
241 void set_gid(const infinint & val) { gid = val; };
242 void set_perm(U_16 val) { perm = val; };
243 void set_last_access(const datetime & val) { last_access = val; };
244 void set_last_modif(const datetime & val) { last_modif = val; };
245 void set_removal_date(const datetime & val);
246 void set_saved_status(saved_status val) { data_status = val; };
247 void set_ea_status(ea_saved_status val) { ea_status = val; };
248 void set_last_change(const datetime & val) { last_change = val; };
249 void set_fsa_status(fsa_saved_status val) { fsa_status = val; };
250 void set_file_size(const infinint & val) { file_size = val; };
251 void set_is_sparse_file(bool val) { sparse_file = val; };
252 void set_compression_algo(compression val) { compression_algo = val; };
253 void set_dirtiness(bool val) { dirty = val; };
254 void set_link_target(const std::string & val) { target = val; };
255 void set_major(int val) { major = val; };
256 void set_minor(int val) { minor = val; };
257 void set_slices(const range & sl) { slices = sl; };
258 void set_delta_sig(bool val) { delta_sig = val; };
259 void set_archive_offset_for_data(const infinint & val) { offset_for_data = val; };
260 void set_storage_size_for_data(const infinint & val) { storage_size_for_data = val; };
261 void set_archive_offset_for_EA(const infinint & val) { offset_for_EA = val; };
262 void set_storage_size_for_EA(const infinint & val) { storage_size_for_EA = val; };
263 void set_archive_offset_for_FSA(const infinint & val) { offset_for_FSA = val; };
264 void set_storage_size_for_FSA(const infinint & val) { storage_size_for_FSA = val; };
265 void set_ea(const ea_attributs & arg);
266 void set_etiquette(const infinint & arg) { etiquette = arg; };
267 void set_fsa_scope(const fsa_scope & arg) { fsa_sc = arg; };
268 void set_data_crc(const crc & ptr);
269 void set_delta_patch_base_crc(const crc & ptr);
270 void set_delta_patch_result_crc(const crc & ptr);
271 void set_empty_dir(bool val) { if(!is_dir()) throw SRC_BUG; empty_dir = val; };
272
273 void clear();
274
275 private:
276 std::string my_name;
277 bool hard_link;
278 unsigned char type;
279 infinint uid;
280 infinint gid;
281 U_16 perm;
282 mutable bool full_date;
283 datetime last_access;
284 datetime last_modif;
285 saved_status data_status;
286 ea_saved_status ea_status;
287 datetime last_change;
288 fsa_saved_status fsa_status;
289 fsa_scope fsa_sc;
290 infinint file_size;
291 bool sparse_file;
292 compression compression_algo;
293 bool dirty;
294 std::string target;
295 int major;
296 int minor;
297 range slices;
298 bool delta_sig;
299 infinint offset_for_data;
300 infinint storage_size_for_data;
301 infinint offset_for_EA;
302 infinint storage_size_for_EA;
303 infinint offset_for_FSA;
304 infinint storage_size_for_FSA;
305 std::deque<std::string> ea;
306 mutable std::deque<std::string>::const_iterator it_ea;
307 infinint etiquette;
308 std::string data_crc;
309 std::string patch_base_crc;
310 std::string patch_result_crc;
311 bool empty_dir;
312
313 static time_t datetime2time_t(const datetime & val);
314 };
315
317
318} // end of namespace
319
320#endif
cat_status.hpp
the different status of data and EA
libdar::datetime
stores time information
Definition datetime.hpp:59
libdar::datetime::get_value
bool get_value(time_t &second, time_t &subsecond, time_unit unit) const
return a time as time_t arguments
libdar::deci
decimal class, convert infinint from and to decimal represention
Definition deci.hpp:51
libdar::deci::human
std::string human() const
this produce a string from the decimal stored in the current object
libdar::infinint
the arbitrary large positive integer class
Definition real_infinint.hpp:62
libdar::list_entry
Definition list_entry.hpp:60
libdar::list_entry::set_fully_detailed_dates
void set_fully_detailed_dates(bool mode) const
Definition list_entry.hpp:114
libdar::list_entry::get_archive_offset_for_FSA
bool get_archive_offset_for_FSA(infinint &val) const
offset in byte where to find the first byte of Filesystem Specific Attributes
Definition list_entry.hpp:203
libdar::list_entry::get_last_modif
void get_last_modif(datetime::time_unit tu, time_t &second, time_t &fraction) const
yet an alternative method to get the last modification date (see get_last_access() for details)
Definition list_entry.hpp:133
libdar::list_entry::get_storage_size_for_data
bool get_storage_size_for_data(infinint &val) const
amount of byte used to store the file's data
Definition list_entry.hpp:180
libdar::list_entry::get_ea_reset_read
void get_ea_reset_read() const
reset the reading of Extended Attributes names
Definition list_entry.hpp:215
libdar::list_entry::get_last_access
void get_last_access(datetime::time_unit tu, time_t &second, time_t &fraction) const
yet an alternative method to get last access time
Definition list_entry.hpp:129
libdar::list_entry::get_removal_date
std::string get_removal_date() const
for removed_entry only
libdar::list_entry::get_last_change
void get_last_change(datetime::time_unit tu, time_t &second, time_t &fraction) const
yet an alternative method to get the last change date (see get_last_access() for details)
Definition list_entry.hpp:137
libdar::list_entry::get_fsa_scope
fsa_scope get_fsa_scope() const
this is the hard-link ID, only valid for hard linked entries
Definition list_entry.hpp:228
libdar::list_entry::is_eod
bool is_eod() const
method used to know whether the returned entry signals a End of Directory
Definition list_entry.hpp:74
libdar::list_entry::last_modif
datetime last_modif
also used to store removal_date for removed entries
Definition list_entry.hpp:284
libdar::list_entry::etiquette
infinint etiquette
hard link identification
Definition list_entry.hpp:307
libdar::list_entry::target
std::string target
target[0] used to store signature of removed entry for removed entries
Definition list_entry.hpp:294
libdar::list_entry::get_storage_size_for_EA
bool get_storage_size_for_EA(infinint &val) const
amount of byte used to store the file's EA
Definition list_entry.hpp:194
libdar::list_entry::get_removed_type
unsigned char get_removed_type() const
valid only for removed_entries
libdar::list_entry::get_ea_read_next
bool get_ea_read_next(std::string &key) const
read the next Extended Attribute name
libdar::list_entry::get_storage_size_for_FSA
bool get_storage_size_for_FSA(infinint &val) const
amount of byte used to store the file's FSA
Definition list_entry.hpp:208
libdar::list_entry::get_slices
const range & get_slices() const
provides slice information
Definition list_entry.hpp:156
libdar::list_entry::get_removal_date_s
time_t get_removal_date_s() const
for removed_entry only
libdar::list_entry::get_archive_offset_for_EA
bool get_archive_offset_for_EA(infinint &val) const
offset in byte whert to find the first byte of Extended Attributes
Definition list_entry.hpp:189
libdar::list_entry::get_archive_offset_for_data
bool get_archive_offset_for_data(infinint &val) const
offset in byte where to find first byte of data
Definition list_entry.hpp:172
libdar::range
stores a range of integers or a set of ranges
Definition range.hpp:44
compression.hpp
compression parameters for API
datetime.hpp
this file contains the definition of class datetime that stores unix times in a portable way
deci.hpp
manages the decimal representation of infinint
ea.hpp
contains a set of routines to manage EA values associated to a file
fsa_family.hpp
filesystem specific attributes available families and fsa_scope definition
libdar::compression2string
std::string compression2string(compression c)
convert a compression to its string representation
libdar::fsa_scope
std::set< fsa_family > fsa_scope
set of fsa families
Definition fsa_family.hpp:70
libdar::compression
compression
the different compression algorithm available
Definition compression.hpp:46
libdar::infinint::is_zero
bool is_zero() const
libdar::fsa_saved_status
fsa_saved_status
FSA saved status for an entry.
Definition cat_status.hpp:73
libdar::saved_status
saved_status
data saved status for an entry
Definition cat_status.hpp:44
libdar::ea_saved_status
ea_saved_status
EA saved status for an entry.
Definition cat_status.hpp:55
libdar::fsa_saved_status::none
@ none
no FSA saved
libdar::fsa_saved_status::full
@ full
FSA saved.
libdar::saved_status::saved
@ saved
inode is saved in the archive
libdar::saved_status::delta
@ delta
inode is saved but as delta binary from the content (delta signature) of what was found in the archiv...
libdar::ea_saved_status::none
@ none
no EA present for this inode in filesystem
libdar::ea_saved_status::removed
@ removed
EA were present in the reference version, but not present anymore.
libdar::ea_saved_status::full
@ full
EA present in filesystem and attached to this inode.
infinint.hpp
switch module to limitint (32 ou 64 bits integers) or infinint
integers.hpp
are defined here basic integer types that tend to be portable
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
range.hpp
class than provide a way to manipulate and represent range of integer numbers (infinint)