Loading...
Searching...
No Matches
list_entry.hpp
Go to the documentation of this file.
/*********************************************************************/
// dar - disk archive - a backup/restoration program
// Copyright (C) 2002-2025 Denis Corbin
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// to contact the author, see the AUTHOR file
/*********************************************************************/
#ifndef LIST_ENTRY_HPP
#define LIST_ENTRY_HPP
#include <string>
#include <set>
#include "../my_config.h"
#include "infinint.hpp"
#include "deci.hpp"
#include "compression.hpp"
#include "integers.hpp"
#include "datetime.hpp"
#include "range.hpp"
#include "cat_status.hpp"
#include "ea.hpp"
#include "fsa_family.hpp"
namespace libdar
{
class crc;
class list_entry
{
public:
list_entry() { clear(); };
list_entry(const list_entry & ref) = default;
list_entry(list_entry && ref) = default;
list_entry & operator = (const list_entry & ref) = default;
list_entry & operator = (list_entry && ref) noexcept = default;
~list_entry() = default;
bool is_eod() const { return type == 'z'; };
// methods for API users
// field that are not set are returned as empty string
const std::string & get_name() const { return my_name; };
unsigned char get_type() const { return type; };
bool is_dir() const { return type == 'd'; };
bool is_file() const { return type == 'f'; };
bool is_symlink() const { return type == 'l'; };
bool is_char_device() const { return type == 'c'; };
bool is_block_device() const { return type == 'b'; };
bool is_unix_socket() const { return type == 's'; };
bool is_named_pipe() const { return type == 'p'; };
bool is_hard_linked() const { return hard_link; };
bool is_removed_entry() const { return type == 'x'; };
bool is_door_inode() const { return type == 'o'; };
bool is_empty_dir() const { return empty_dir; };
unsigned char get_removed_type() const;
bool has_data_present_in_the_archive() const { return data_status == saved_status::saved || data_status == saved_status::delta; };
std::string get_data_flag() const;
saved_status get_data_status() const { return data_status; };
bool has_EA() const { return ea_status != ea_saved_status::none && ea_status != ea_saved_status::removed; };
bool has_EA_saved_in_the_archive() const { return ea_status == ea_saved_status::full; };
std::string get_ea_flag() const;
ea_saved_status get_ea_status() const { return ea_status; };
bool has_FSA() const { return fsa_status != fsa_saved_status::none; };
bool has_FSA_saved_in_the_archive() const { return fsa_status == fsa_saved_status::full; };
std::string get_fsa_flag() const;
std::string get_uid(bool try_resolving_name = false) const;
std::string get_gid(bool try_resolving_name = false) const;
std::string get_perm() const;
void set_fully_detailed_dates(bool mode) const { full_date = mode; };
std::string get_last_access() const;
std::string get_last_modif() const;
std::string get_last_change() const;
std::string get_removal_date() const;
time_t get_last_access_s() const { return datetime2time_t(last_access); };
time_t get_last_modif_s() const;
time_t get_last_change_s() const { return datetime2time_t(last_change); };
time_t get_removal_date_s() const;
void get_last_access(datetime::time_unit tu, time_t & second, time_t & fraction) const
{ last_access.get_value(second, fraction, tu); }
void get_last_modif(datetime::time_unit tu, time_t & second, time_t & fraction) const
{ last_modif.get_value(second, fraction, tu); }
void get_last_change(datetime::time_unit tu, time_t & second, time_t & fraction) const
{ last_change.get_value(second, fraction, tu); }
std::string get_file_size(bool size_in_bytes = true) const;
std::string get_compression_ratio() const;
std::string get_compression_ratio_flag() const;
bool is_sparse() const { return sparse_file; };
std::string get_sparse_flag() const { return sparse_file ? "[X]" : "[ ]"; };
std::string get_compression_algo() const { return compression2string(compression_algo); };
bool is_dirty() const { return dirty; };
std::string get_link_target() const { return target; };
std::string get_major() const;
std::string get_minor() const;
const range & get_slices() const { return slices; };
bool has_delta_signature() const { return delta_sig; };
std::string get_delta_flag() const;
bool get_archive_offset_for_data(infinint & val) const { val = offset_for_data; return !val.is_zero(); };
bool get_archive_offset_for_data(U_64 & val) const;
std::string get_archive_offset_for_data() const { return offset_for_data.is_zero() ? "" : deci(offset_for_data).human(); };
bool get_storage_size_for_data(infinint & val) const { val = storage_size_for_data; return !val.is_zero(); };
bool get_storage_size_for_data(U_64 & val) const;
std::string get_storage_size_for_data(bool size_in_bytes = true) const;
bool get_archive_offset_for_EA(infinint & val) const { val = offset_for_EA; return !val.is_zero(); };
bool get_archive_offset_for_EA(U_64 & val) const;
std::string get_archive_offset_for_EA() const { return offset_for_EA.is_zero() ? "" : deci(offset_for_EA).human(); };
bool get_storage_size_for_EA(infinint & val) const { val = storage_size_for_EA; return !val.is_zero(); };
bool get_storage_size_for_EA(U_64 & val) const;
std::string get_storage_size_for_EA() const { return storage_size_for_EA.is_zero() ? "" : deci(storage_size_for_EA).human(); };
bool get_archive_offset_for_FSA(infinint & val) const { val = offset_for_FSA; return !val.is_zero(); };
bool get_archive_offset_for_FSA(U_64 & val) const;
std::string get_archive_offset_for_FSA() const { return offset_for_FSA.is_zero() ? "" : deci(offset_for_FSA).human(); };
bool get_storage_size_for_FSA(infinint & val) const { val = storage_size_for_FSA; return !val.is_zero(); };
bool get_storage_size_for_FSA(U_64 & val) const;
std::string get_storage_size_for_FSA() const { return storage_size_for_FSA.is_zero() ? "" : deci(storage_size_for_FSA).human(); };
void get_ea_reset_read() const { it_ea = ea.begin(); };
bool get_ea_read_next(std::string & key) const;
std::string get_etiquette() const { return deci(etiquette).human(); };
fsa_scope get_fsa_scope() const { return fsa_sc; };
std::string get_data_crc() const { return data_crc; };
std::string get_delta_patch_base_crc() const { return patch_base_crc; };
std::string get_delta_patch_result_crc() const { return patch_result_crc; };
// methods for libdar to setup the object
void set_name(const std::string & val) { my_name = val; };
void set_type(unsigned char val) { type = val; };
void set_removed_type(unsigned char val);
void set_hard_link(bool val) { hard_link = val; };
void set_uid(const infinint & val) { uid = val; };
void set_gid(const infinint & val) { gid = val; };
void set_perm(U_16 val) { perm = val; };
void set_last_access(const datetime & val) { last_access = val; };
void set_last_modif(const datetime & val) { last_modif = val; };
void set_removal_date(const datetime & val);
void set_saved_status(saved_status val) { data_status = val; };
void set_ea_status(ea_saved_status val) { ea_status = val; };
void set_last_change(const datetime & val) { last_change = val; };
void set_fsa_status(fsa_saved_status val) { fsa_status = val; };
void set_file_size(const infinint & val) { file_size = val; };
void set_is_sparse_file(bool val) { sparse_file = val; };
void set_compression_algo(compression val) { compression_algo = val; };
void set_dirtiness(bool val) { dirty = val; };
void set_link_target(const std::string & val) { target = val; };
void set_major(int val) { major = val; };
void set_minor(int val) { minor = val; };
void set_slices(const range & sl) { slices = sl; };
void set_delta_sig(bool val) { delta_sig = val; };
void set_archive_offset_for_data(const infinint & val) { offset_for_data = val; };
void set_storage_size_for_data(const infinint & val) { storage_size_for_data = val; };
void set_archive_offset_for_EA(const infinint & val) { offset_for_EA = val; };
void set_storage_size_for_EA(const infinint & val) { storage_size_for_EA = val; };
void set_archive_offset_for_FSA(const infinint & val) { offset_for_FSA = val; };
void set_storage_size_for_FSA(const infinint & val) { storage_size_for_FSA = val; };
void set_ea(const ea_attributs & arg);
void set_etiquette(const infinint & arg) { etiquette = arg; };
void set_fsa_scope(const fsa_scope & arg) { fsa_sc = arg; };
void set_data_crc(const crc & ptr);
void set_delta_patch_base_crc(const crc & ptr);
void set_delta_patch_result_crc(const crc & ptr);
void set_empty_dir(bool val) { if(!is_dir()) throw SRC_BUG; empty_dir = val; };
void clear();
private:
std::string my_name;
bool hard_link;
unsigned char type;
infinint uid;
infinint gid;
U_16 perm;
mutable bool full_date;
datetime last_access;
datetime last_modif;
saved_status data_status;
ea_saved_status ea_status;
datetime last_change;
fsa_saved_status fsa_status;
fsa_scope fsa_sc;
infinint file_size;
bool sparse_file;
compression compression_algo;
bool dirty;
std::string target;
int major;
int minor;
range slices;
bool delta_sig;
infinint offset_for_data;
infinint storage_size_for_data;
infinint offset_for_EA;
infinint storage_size_for_EA;
infinint offset_for_FSA;
infinint storage_size_for_FSA;
std::deque<std::string> ea;
mutable std::deque<std::string>::const_iterator it_ea;
infinint etiquette;
std::string data_crc;
std::string patch_base_crc;
std::string patch_result_crc;
bool empty_dir;
static time_t datetime2time_t(const datetime & val);
};
} // end of namespace
#endif
cat_status.hpp
the different status of data and EA
libdar::crc
pure virtual class defining interface of a CRC object
Definition crc.hpp:47
libdar::datetime
stores time information
Definition datetime.hpp:59
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::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
Definition cat_status.hpp:74
libdar::fsa_saved_status::full
@ full
FSA saved.
Definition cat_status.hpp:76
libdar::saved_status::saved
@ saved
inode is saved in the archive
Definition cat_status.hpp:45
libdar::saved_status::delta
@ delta
inode is saved but as delta binary from the content (delta signature) of what was found in the archiv...
Definition cat_status.hpp:49
libdar::ea_saved_status::none
@ none
no EA present for this inode in filesystem
Definition cat_status.hpp:56
libdar::ea_saved_status::removed
@ removed
EA were present in the reference version, but not present anymore.
Definition cat_status.hpp:60
libdar::ea_saved_status::full
@ full
EA present in filesystem and attached to this inode.
Definition cat_status.hpp:59
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)