Disk ARchive  2.7.14
Full featured and portable backup and archiving tool
list_entry.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 
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 
44 namespace 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  std::string get_last_access() const;
112  std::string get_last_modif() const;
113  std::string get_last_change() const;
114  std::string get_removal_date() const;
115  time_t get_last_access_s() const { return datetime2time_t(last_access); };
116  time_t get_last_modif_s() const;
117  time_t get_last_change_s() const { return datetime2time_t(last_change); };
118  time_t get_removal_date_s() const;
119 
121 
125  void get_last_access(datetime::time_unit tu, time_t & second, time_t & fraction) const
126  { last_access.get_value(second, fraction, tu); }
127 
129  void get_last_modif(datetime::time_unit tu, time_t & second, time_t & fraction) const
130  { last_modif.get_value(second, fraction, tu); }
131 
133  void get_last_change(datetime::time_unit tu, time_t & second, time_t & fraction) const
134  { last_change.get_value(second, fraction, tu); }
135 
136  std::string get_file_size(bool size_in_bytes = true) const;
137  std::string get_compression_ratio() const;
138  std::string get_compression_ratio_flag() const;
139  bool is_sparse() const { return sparse_file; };
140  std::string get_sparse_flag() const { return sparse_file ? "[X]" : "[ ]"; };
141  std::string get_compression_algo() const { return compression2string(compression_algo); };
142  bool is_dirty() const { return dirty; };
143  std::string get_link_target() const { return target; };
144  std::string get_major() const;
145  std::string get_minor() const;
146 
148 
152  const range & get_slices() const { return slices; };
153  bool has_delta_signature() const { return delta_sig; };
154  std::string get_delta_flag() const;
155 
156 
158 
168  bool get_archive_offset_for_data(infinint & val) const { val = offset_for_data; return !val.is_zero(); };
169  bool get_archive_offset_for_data(U_64 & val) const;
170  std::string get_archive_offset_for_data() const { return offset_for_data.is_zero() ? "" : deci(offset_for_data).human(); };
171 
173 
176  bool get_storage_size_for_data(infinint & val) const { val = storage_size_for_data; return !val.is_zero(); };
177  bool get_storage_size_for_data(U_64 & val) const;
178  std::string get_storage_size_for_data(bool size_in_bytes = true) const;
179 
181 
185  bool get_archive_offset_for_EA(infinint & val) const { val = offset_for_EA; return !val.is_zero(); };
186  bool get_archive_offset_for_EA(U_64 & val) const;
187  std::string get_archive_offset_for_EA() const { return offset_for_EA.is_zero() ? "" : deci(offset_for_EA).human(); };
188 
190  bool get_storage_size_for_EA(infinint & val) const { val = storage_size_for_EA; return !val.is_zero(); };
191  bool get_storage_size_for_EA(U_64 & val) const;
192  std::string get_storage_size_for_EA() const { return storage_size_for_EA.is_zero() ? "" : deci(storage_size_for_EA).human(); };
193 
195 
199  bool get_archive_offset_for_FSA(infinint & val) const { val = offset_for_FSA; return !val.is_zero(); };
200  bool get_archive_offset_for_FSA(U_64 & val) const;
201  std::string get_archive_offset_for_FSA() const { return offset_for_FSA.is_zero() ? "" : deci(offset_for_FSA).human(); };
202 
204  bool get_storage_size_for_FSA(infinint & val) const { val = storage_size_for_FSA; return !val.is_zero(); };
205  bool get_storage_size_for_FSA(U_64 & val) const;
206  std::string get_storage_size_for_FSA() const { return storage_size_for_FSA.is_zero() ? "" : deci(storage_size_for_FSA).human(); };
207 
209 
211  void get_ea_reset_read() const { it_ea = ea.begin(); };
212 
214 
220  bool get_ea_read_next(std::string & key) const;
221 
222  std::string get_etiquette() const { return deci(etiquette).human(); };
223 
224  fsa_scope get_fsa_scope() const { return fsa_sc; };
225 
226  std::string get_data_crc() const { return data_crc; };
227  std::string get_delta_patch_base_crc() const { return patch_base_crc; };
228  std::string get_delta_patch_result_crc() const { return patch_result_crc; };
229 
230  // methods for libdar to setup the object
231 
232  void set_name(const std::string & val) { my_name = val; };
233  void set_type(unsigned char val) { type = val; };
234  void set_removed_type(unsigned char val);
235  void set_hard_link(bool val) { hard_link = val; };
236  void set_uid(const infinint & val) { uid = val; };
237  void set_gid(const infinint & val) { gid = val; };
238  void set_perm(U_16 val) { perm = val; };
239  void set_last_access(const datetime & val) { last_access = val; };
240  void set_last_modif(const datetime & val) { last_modif = val; };
241  void set_removal_date(const datetime & val);
242  void set_saved_status(saved_status val) { data_status = val; };
243  void set_ea_status(ea_saved_status val) { ea_status = val; };
244  void set_last_change(const datetime & val) { last_change = val; };
245  void set_fsa_status(fsa_saved_status val) { fsa_status = val; };
246  void set_file_size(const infinint & val) { file_size = val; };
247  void set_is_sparse_file(bool val) { sparse_file = val; };
248  void set_compression_algo(compression val) { compression_algo = val; };
249  void set_dirtiness(bool val) { dirty = val; };
250  void set_link_target(const std::string & val) { target = val; };
251  void set_major(int val) { major = val; };
252  void set_minor(int val) { minor = val; };
253  void set_slices(const range & sl) { slices = sl; };
254  void set_delta_sig(bool val) { delta_sig = val; };
255  void set_archive_offset_for_data(const infinint & val) { offset_for_data = val; };
256  void set_storage_size_for_data(const infinint & val) { storage_size_for_data = val; };
257  void set_archive_offset_for_EA(const infinint & val) { offset_for_EA = val; };
258  void set_storage_size_for_EA(const infinint & val) { storage_size_for_EA = val; };
259  void set_archive_offset_for_FSA(const infinint & val) { offset_for_FSA = val; };
260  void set_storage_size_for_FSA(const infinint & val) { storage_size_for_FSA = val; };
261  void set_ea(const ea_attributs & arg);
262  void set_etiquette(const infinint & arg) { etiquette = arg; };
263  void set_fsa_scope(const fsa_scope & arg) { fsa_sc = arg; };
264  void set_data_crc(const crc & ptr);
265  void set_delta_patch_base_crc(const crc & ptr);
266  void set_delta_patch_result_crc(const crc & ptr);
267  void set_empty_dir(bool val) { if(!is_dir()) throw SRC_BUG; empty_dir = val; };
268 
269  void clear();
270 
271  private:
272  std::string my_name;
273  bool hard_link;
274  unsigned char type;
275  infinint uid;
276  infinint gid;
277  U_16 perm;
278  datetime last_access;
280  saved_status data_status;
281  ea_saved_status ea_status;
282  datetime last_change;
283  fsa_saved_status fsa_status;
284  fsa_scope fsa_sc;
285  infinint file_size;
286  bool sparse_file;
287  compression compression_algo;
288  bool dirty;
289  std::string target;
290  int major;
291  int minor;
292  range slices;
293  bool delta_sig;
294  infinint offset_for_data;
295  infinint storage_size_for_data;
296  infinint offset_for_EA;
297  infinint storage_size_for_EA;
298  infinint offset_for_FSA;
299  infinint storage_size_for_FSA;
300  std::deque<std::string> ea;
301  mutable std::deque<std::string>::const_iterator it_ea;
303  std::string data_crc;
304  std::string patch_base_crc;
305  std::string patch_result_crc;
306  bool empty_dir;
307 
308  static time_t datetime2time_t(const datetime & val);
309  };
310 
312 
313 } // end of namespace
314 
315 #endif
the different status of data and EA
stores time information
Definition: datetime.hpp:59
bool get_value(time_t &second, time_t &subsecond, time_unit unit) const
return a time as time_t arguments
decimal class, convert infinint from and to decimal represention
Definition: deci.hpp:51
std::string human() const
this produce a string from the decimal stored in the current object
the arbitrary large positive integer class
Definition: list_entry.hpp:60
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:199
const range & get_slices() const
provides slice information
Definition: list_entry.hpp:152
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:129
bool get_storage_size_for_data(infinint &val) const
amount of byte used to store the file's data
Definition: list_entry.hpp:176
void get_ea_reset_read() const
reset the reading of Extended Attributes names
Definition: list_entry.hpp:211
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:125
std::string get_removal_date() const
for removed_entry only
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:133
fsa_scope get_fsa_scope() const
this is the hard-link ID, only valid for hard linked entries
Definition: list_entry.hpp:224
bool is_eod() const
method used to know whether the returned entry signals a End of Directory
Definition: list_entry.hpp:74
datetime last_modif
also used to store removal_date for removed entries
Definition: list_entry.hpp:279
infinint etiquette
hard link identification
Definition: list_entry.hpp:302
std::string target
target[0] used to store signature of removed entry for removed entries
Definition: list_entry.hpp:289
bool get_storage_size_for_EA(infinint &val) const
amount of byte used to store the file's EA
Definition: list_entry.hpp:190
unsigned char get_removed_type() const
valid only for removed_entries
bool get_ea_read_next(std::string &key) const
read the next Extended Attribute name
bool get_storage_size_for_FSA(infinint &val) const
amount of byte used to store the file's FSA
Definition: list_entry.hpp:204
time_t get_removal_date_s() const
for removed_entry only
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:185
bool get_archive_offset_for_data(infinint &val) const
offset in byte where to find first byte of data
Definition: list_entry.hpp:168
stores a range of integers or a set of ranges
Definition: range.hpp:44
compression parameters for API
this file contains the definition of class datetime that stores unix times in a portable way
manages the decimal representation of infinint
contains a set of routines to manage EA values associated to a file
filesystem specific attributes available families and fsa_scope definition
std::string compression2string(compression c)
convert a compression to its string representation
std::set< fsa_family > fsa_scope
set of fsa families
Definition: fsa_family.hpp:70
compression
the different compression algorithm available
Definition: compression.hpp:46
bool is_zero() const
fsa_saved_status
FSA saved status for an entry.
Definition: cat_status.hpp:74
saved_status
data saved status for an entry
Definition: cat_status.hpp:45
ea_saved_status
EA saved status for an entry.
Definition: cat_status.hpp:56
@ saved
inode is saved in the archive
@ delta
inode is saved but as delta binary from the content (delta signature) of what was found in the archiv...
@ none
no EA present for this inode in filesystem
@ removed
EA were present in the reference version, but not present anymore.
@ full
EA present in filesystem and attached to this inode.
switch module to limitint (32 ou 64 bits integers) or infinint
are defined here basic integer types that tend to be portable
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47
class than provide a way to manipulate and represent range of integer numbers (infinint)