Disk ARchive  2.5.5
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-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 
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 "catalogue.hpp"
37 #include "tools.hpp"
38 #include "compressor.hpp"
39 #include "integers.hpp"
40 #include "on_pool.hpp"
41 #include "datetime.hpp"
42 #include "range.hpp"
43 
44 namespace libdar
45 {
46 
55  class list_entry : public on_pool
56  {
57  public:
58  list_entry();
59 
60  // methods for API users
61  // field that are not set are returned as empty string
62 
63  const std::string & get_name() const { return my_name; };
64  unsigned char get_type() const { return type; };
65  bool is_dir() const { return type == 'd'; };
66  bool is_file() const { return type == 'f'; };
67  bool is_symlink() const { return type == 'l'; };
68  bool is_char_device() const { return type == 'c'; };
69  bool is_block_device() const { return type == 'b'; };
70  bool is_unix_socket() const { return type == 's'; };
71  bool is_named_pipe() const { return type == 'p'; };
72  bool is_hard_linked() const { return hard_link; };
73  bool is_removed_entry() const { return type == 'x'; };
74  bool is_door_inode() const { return type == 'o'; };
75 
76  bool has_data_present_in_the_archive() const { return data_status == s_saved; };
77  bool has_EA() const { return ea_status != cat_inode::ea_none && ea_status != cat_inode::ea_removed; };
78  bool has_EA_saved_in_the_archive() const { return ea_status == cat_inode::ea_full; };
79  bool has_FSA() const { return fsa_status != cat_inode::fsa_none; };
80  bool has_FSA_saved_in_the_archive() const { return fsa_status == cat_inode::fsa_full; };
81 
82  std::string get_uid() const { return deci(uid).human(); };
83  std::string get_gid() const { return deci(gid).human(); };
84  std::string get_perm() const { return tools_get_permission_string(type, perm, hard_link); };
85  std::string get_last_access() const { return last_access.is_null() ? "" : tools_display_date(last_access); };
86  std::string get_last_modif() const { return last_modif.is_null() ? "" : tools_display_date(last_modif); };
87  std::string get_last_change() const { return last_change.is_null() ? "" : tools_display_date(last_change); };
88  time_t get_last_access_s() const { return datetime2time_t(last_access); };
89  time_t get_last_modif_s() const { return datetime2time_t(last_modif); };
90  time_t get_last_change_s() const { return datetime2time_t(last_change); };
91 
97  void get_last_access(datetime::time_unit tu, time_t & second, time_t & fraction) const
98  { last_access.get_value(second, fraction, tu); }
99 
101  void get_last_modif(datetime::time_unit tu, time_t & second, time_t & fraction) const
102  { last_modif.get_value(second, fraction, tu); }
103 
105  void get_last_change(datetime::time_unit tu, time_t & second, time_t & fraction) const
106  { last_change.get_value(second, fraction, tu); }
107 
108  std::string get_file_size() const { return deci(file_size).human(); };
109  std::string get_compression_ratio() const { return tools_get_compression_ratio(storage_size, file_size, compression_algo != none); };
110  bool is_sparse() const { return sparse_file; };
111  std::string get_compression_algo() const { return compression2string(compression_algo); };
112  bool is_dirty() const { return dirty; };
113  std::string get_link_target() const { return target; };
114  std::string get_major() const { return tools_int2str(major); };
115  std::string get_minor() const { return tools_int2str(minor); };
116  const range & get_slices() const { return slices; };
117 
118 
130  bool get_archive_offset_for_data(infinint & val) const { val = offset_for_data; return !val.is_zero(); };
131  bool get_archive_offset_for_data(U_64 & val) const { return tools_infinint2U_64(offset_for_data, val) && !offset_for_data.is_zero(); };
132  std::string get_archive_offset_for_data() const { return offset_for_data.is_zero() ? "" : deci(offset_for_data).human(); };
133 
138  bool get_storage_size_for_data(infinint & val) const { val = storage_size_for_data; return !val.is_zero(); };
139  bool get_storage_size_for_data(U_64 & val) const { return tools_infinint2U_64(storage_size_for_data, val) && !storage_size_for_data.is_zero(); };
140  std::string get_storage_size_for_data() const { return storage_size_for_data.is_zero() ? "" : deci(storage_size_for_data).human(); };
141 
147  bool get_archive_offset_for_EA(infinint & val) const { val = offset_for_EA; return !val.is_zero(); };
148  bool get_archive_offset_for_EA(U_64 & val) const { return tools_infinint2U_64(offset_for_EA, val) && !offset_for_EA.is_zero(); };
149  std::string get_archive_offset_for_EA() const { return offset_for_EA.is_zero() ? "" : deci(offset_for_EA).human(); };
150 
152  bool get_storage_size_for_EA(infinint & val) const { val = storage_size_for_EA; return !val.is_zero(); };
153  bool get_storage_size_for_EA(U_64 & val) const { return tools_infinint2U_64(storage_size_for_EA, val) && !storage_size_for_EA.is_zero(); };
154  std::string get_storage_size_for_EA() const { return storage_size_for_EA.is_zero() ? "" : deci(storage_size_for_EA).human(); };
155 
161  bool get_archive_offset_for_FSA(infinint & val) const { val = offset_for_FSA; return !val.is_zero(); };
162  bool get_archive_offset_for_FSA(U_64 & val) const { return tools_infinint2U_64(offset_for_FSA, val) && !offset_for_FSA.is_zero(); };
163  std::string get_archive_offset_for_FSA() const { return offset_for_FSA.is_zero() ? "" : deci(offset_for_FSA).human(); };
164 
166  bool get_storage_size_for_FSA(infinint & val) const { val = storage_size_for_FSA; return !val.is_zero(); };
167  bool get_storage_size_for_FSA(U_64 & val) const { return tools_infinint2U_64(storage_size_for_FSA, val) && !storage_size_for_FSA.is_zero(); };
168  std::string get_storage_size_for_FSA() const { return storage_size_for_FSA.is_zero() ? "" : deci(storage_size_for_FSA).human(); };
169 
170 
171  // methods for libdar to setup the object
172 
173  void set_name(const std::string & val) { my_name = val; };
174  void set_type(unsigned char val) { type = val; };
175  void set_hard_link(bool val) { hard_link = val; };
176  void set_uid(const infinint & val) { uid = val; };
177  void set_gid(const infinint & val) { gid = val; };
178  void set_perm(U_16 val) { perm = val; };
179  void set_last_access(const datetime & val) { last_access = val; };
180  void set_last_modif(const datetime & val) { last_modif = val; };
181  void set_saved_status(saved_status val) { data_status = val; };
182  void set_ea_status(cat_inode::ea_status val) { ea_status = val; };
183  void set_last_change(const datetime & val) { last_change = val; };
184  void set_fsa_status(cat_inode::fsa_status val) { fsa_status = val; };
185  void set_file_size(const infinint & val) { file_size = val; };
186  void set_storage_size(const infinint & val) { storage_size = val; };
187  void set_is_sparse_file(bool val) { sparse_file = val; };
188  void set_compression_algo(compression val) { compression_algo = val; };
189  void set_dirtiness(bool val) { dirty = val; };
190  void set_link_target(const std::string & val) { target = val; };
191  void set_major(int val) { major = val; };
192  void set_minor(int val) { minor = val; };
193  void set_slices(const range & sl) { slices = sl; };
194  void set_archive_offset_for_data(const infinint & val) { offset_for_data = val; };
195  void set_storage_size_for_data(const infinint & val) { storage_size_for_data = val; };
196  void set_archive_offset_for_EA(const infinint & val) { offset_for_EA = val; };
197  void set_storage_size_for_EA(const infinint & val) { storage_size_for_EA = val; };
198  void set_archive_offset_for_FSA(const infinint & val) { offset_for_FSA = val; };
199  void set_storage_size_for_FSA(const infinint & val) { storage_size_for_FSA = val; };
200 
201  private:
202  std::string my_name;
203  bool hard_link;
204  unsigned char type;
205  infinint uid;
206  infinint gid;
207  U_16 perm;
208  datetime last_access;
209  datetime last_modif;
210  saved_status data_status;
211  cat_inode::ea_status ea_status;
212  datetime last_change;
213  cat_inode::fsa_status fsa_status;
214  infinint file_size;
215  infinint storage_size;
216  bool sparse_file;
217  compression compression_algo;
218  bool dirty;
219  std::string target;
220  int major;
221  int minor;
222  range slices;
223  infinint offset_for_data;
224  infinint storage_size_for_data;
225  infinint offset_for_EA;
226  infinint storage_size_for_EA;
227  infinint offset_for_FSA;
228  infinint storage_size_for_FSA;
229 
230  static time_t datetime2time_t(const datetime & val);
231  };
232 
233 } // end of namespace
234 
235 #endif
bool get_storage_size_for_EA(infinint &val) const
amount of byte used to store the file&#39;s EA
Definition: list_entry.hpp:152
bool get_archive_offset_for_FSA(infinint &val) const
Definition: list_entry.hpp:161
are defined here basic integer types that tend to be portable
a set of general purpose routines
decimal class, convert infinint from and to decimal represention
Definition: deci.hpp:50
bool get_storage_size_for_data(infinint &val) const
Definition: list_entry.hpp:138
bool get_storage_size_for_FSA(infinint &val) const
amount of byte used to store the file&#39;s FSA
Definition: list_entry.hpp:166
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:105
bool get_archive_offset_for_data(infinint &val) const
Definition: list_entry.hpp:130
bool get_archive_offset_for_EA(infinint &val) const
Definition: list_entry.hpp:147
no compression
Definition: compressor.hpp:45
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:101
bool tools_infinint2U_64(infinint val, U_64 &res)
std::string tools_display_date(const datetime &date)
convert a date in second to its human readable representation
void get_last_access(datetime::time_unit tu, time_t &second, time_t &fraction) const
Definition: list_entry.hpp:97
std::string tools_int2str(S_I x)
convert integer to string
std::string tools_get_permission_string(char type, U_32 perm, bool hard)
convert a permission number into its string representation (rwxrwxrwx)
switch module to limitint (32 ou 64 bits integers) or infinint
manages the decimal representation of infinint
compression
the different compression algorithm available
Definition: compressor.hpp:43
this file contains the definition of class datetime that stores unix times in a portable way ...
compression engine implementation
this is the base class of object that can be allocated on a memory pool
std::string tools_get_compression_ratio(const infinint &storage_size, const infinint &file_size, bool compressed)
return the string about compression ratio
the arbitrary large positive integer class
class than provide a way to manipulate and represent range of integer numbers (infinint) ...
std::string human() const
this produce a string from the decimal stored in the current object
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47
here is defined the many classed which is build of the catalogue
Definition: list_entry.hpp:55