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

Loading...
Searching...
No Matches
cat_directory.hpp
Go to the documentation of this file.
1/*********************************************************************/
2// dar - disk archive - a backup/restoration program
3// Copyright (C) 2002-2026 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#ifndef CAT_DIRECTORY_HPP
27#define CAT_DIRECTORY_HPP
28
29#include "../my_config.h"
30
31 extern "C"
32{
33} // end extern "C"
34
35#include "cat_inode.hpp"
36
37#ifdef LIBDAR_FAST_DIR
38#include <map>
39#endif
40#include <list>
41
42 namespace libdar
43{
44 class cat_eod;
45
48
50
51 class cat_directory : public cat_inode
52 {
53 public :
54 cat_directory(const infinint & xuid,
55 const infinint & xgid,
56 U_16 xperm,
57 const datetime & last_access,
58 const datetime & last_modif,
59 const datetime & last_change,
60 const std::string & xname,
61 const infinint & device);
62 cat_directory(const std::shared_ptr<user_interaction> & dialog,
63 const smart_pointer<pile_descriptor> & pdesc,
64 const archive_version & reading_ver,
65 saved_status saved,
66 entree_stats & stats,
67 std::map <infinint, cat_etoile *> & corres,
68 compression default_algo,
69 bool lax,
70 bool only_detruit, // objects of other class than detruit and cat_directory are not built in memory
71 bool small);
72 cat_directory(const cat_directory &ref); // only the inode part is build, no children is duplicated (empty dir)
73 cat_directory(cat_directory && ref) noexcept;
74 cat_directory & operator = (const cat_directory & ref); // set the inode part *only* no subdirectories/subfiles are copies or removed.
75 cat_directory & operator = (cat_directory && ref);
76 ~cat_directory() noexcept(false); // detruit aussi tous les fils et se supprime de son 'parent'
77
79 virtual bool operator == (const cat_entree & ref) const override;
80
81 void add_children(cat_nomme *r); // when r is a cat_directory, 'parent' is set to 'this'
82 bool has_children() const { return !ordered_fils.empty(); };
83 void reset_read_children() const;
84 void end_read() const;
85 bool read_children(const cat_nomme * &r) const; // read the direct children of the cat_directory, returns false if no more is available
86
88
90 bool remove_last_read();
91
93
96 bool tail_to_read_children(bool including_last_read);
97
98
100
110 void remove(const std::string & name);
111
113 void remove_if_no_mirage(const std::string & name);
114
116 void clear();
117
118 cat_directory * get_parent() const { return parent; };
119 bool search_children(const std::string &name, const cat_nomme *&ref) const;
120
122 path get_path() const;
123
124 // using is_more_recent_than() from cat_inode class
125 // using method has_changed_since() from cat_inode class
126 virtual unsigned char signature() const override { return 'd'; };
127
128 virtual std::string get_description() const override { return "folder"; };
129
130
132 bool get_recursive_has_changed() const { return recursive_has_changed; };
133
135 void recursive_has_changed_update() const;
136
138 infinint get_dir_size() const { return ordered_fils.size(); };
139
141 infinint get_tree_size() const;
142
144 infinint get_tree_ea_num() const;
145
147 infinint get_tree_mirage_num() const;
148
149 // for each mirage found (hard link implementation) in the cat_directory tree, add its etiquette to the returned
150 // list with the number of reference that has been found in the tree. (map[etiquette] = number of occurence)
151 // from outside of class cat_directory, the given argument is expected to be an empty map.
152 void get_etiquettes_found_in_tree(std::map<infinint, infinint> & already_found) const;
153
155 bool is_empty() const { return ordered_fils.empty(); };
156
158 void remove_all_mirages_and_reduce_dirs();
159
161 void remove_all_ea_and_fsa();
162
164 void set_all_mirage_s_inode_wrote_field_to(bool val) const;
165
167 void set_all_mirage_s_inode_dumped_field_to(bool val) const;
168
169 virtual cat_entree *clone() const override { return new (std::nothrow) cat_directory(*this); };
170
171 const infinint & get_size() const { recursive_update_sizes(); return x_size; };
172 const infinint & get_storage_size() const { recursive_update_sizes(); return x_storage_size; };
173
174 void recursively_set_to_unsaved_data_and_FSA();
175
177 virtual void change_location(const smart_pointer<pile_descriptor> & pdesc) override;
178
179 protected:
180 virtual void inherited_dump(const pile_descriptor & pdesc, bool small) const override;
181
182 private:
183 static const cat_eod fin;
184
185 mutable infinint x_size;
186 mutable infinint x_storage_size;
187 mutable bool updated_sizes;
188 cat_directory *parent;
189#ifdef LIBDAR_FAST_DIR
190 std::map<std::string, cat_nomme *> fils; // used for fast lookup
191#endif
192 std::deque<cat_nomme *> ordered_fils;
193 mutable std::deque<cat_nomme *>::const_iterator it;
194 mutable bool recursive_has_changed;
195
196 void init() noexcept;
197 void recursive_update_sizes() const;
198 void recursive_flag_size_to_update() const;
199 void erase_ordered_fils(std::deque<cat_nomme *>::const_iterator debut,
200 std::deque<cat_nomme *>::const_iterator fin);
201
203
206 bool remove_all_except_mirages();
207
208
209 };
210
212
213} // end of namespace
214
215#endif
cat_inode.hpp
base object for all inode types, managed EA and FSA, dates, permissions, ownership,...
libdar::archive_version
class archive_version manages the version of the archive format
Definition archive_version.hpp:47
libdar::cat_directory::set_all_mirage_s_inode_wrote_field_to
void set_all_mirage_s_inode_wrote_field_to(bool val) const
recursively set all mirage inode_wrote flag
libdar::cat_directory::get_tree_ea_num
infinint get_tree_ea_num() const
get the number of entry having some EA set in the cat_directory tree (recursive call)
libdar::cat_directory::tail_to_read_children
bool tail_to_read_children(bool including_last_read)
remove all entry not yet read by read_children
libdar::cat_directory::it
std::deque< cat_nomme * >::const_iterator it
next entry to be returned by read_children
Definition cat_directory.hpp:193
libdar::cat_directory::recursive_has_changed_update
void recursive_has_changed_update() const
ask recursive update for the recursive_has_changed field
libdar::cat_directory::set_all_mirage_s_inode_dumped_field_to
void set_all_mirage_s_inode_dumped_field_to(bool val) const
set the value of inode_dumped for all mirage (recusively)
libdar::cat_directory::remove_last_read
bool remove_last_read()
remove last read entry of self from parent directory
libdar::cat_directory::remove_all_mirages_and_reduce_dirs
void remove_all_mirages_and_reduce_dirs()
recursively remove all mirage entries
libdar::cat_directory::get_dir_size
infinint get_dir_size() const
get the number of "cat_nomme" entry directly containted in this cat_directory (no recursive call)
Definition cat_directory.hpp:138
libdar::cat_directory::get_description
virtual std::string get_description() const override
inherited class designation
Definition cat_directory.hpp:128
libdar::cat_directory::inherited_dump
virtual void inherited_dump(const pile_descriptor &pdesc, bool small) const override
true if object has been created by sequential reading of an archive
libdar::cat_directory::signature
virtual unsigned char signature() const override
inherited class signature
Definition cat_directory.hpp:126
libdar::cat_directory::get_tree_mirage_num
infinint get_tree_mirage_num() const
get the number of entry that are hard linked inode (aka mirage in dar implementation) (recursive call...
libdar::cat_directory::clone
virtual cat_entree * clone() const override
a way to copy the exact type of an object even if pointed to by a parent class pointer
Definition cat_directory.hpp:169
libdar::cat_directory::remove_all_except_mirages
bool remove_all_except_mirages()
remove all entry of the current directory except cat_mirage or cat_directory containing cat_mirage
libdar::cat_directory::remove
void remove(const std::string &name)
remove the given entry from the catalogue
libdar::cat_directory::change_location
virtual void change_location(const smart_pointer< pile_descriptor > &pdesc) override
overwrite virtual method of cat_entree to propagate the action to all entries of the directory tree
libdar::cat_directory::remove_all_ea_and_fsa
void remove_all_ea_and_fsa()
remove all EA and FSA recursively (those "full" get flagged "partial")
libdar::cat_directory::clear
void clear()
remove all entries contained in this directory (recursively)
libdar::cat_directory::get_recursive_has_changed
bool get_recursive_has_changed() const
detemine whether some data has changed since archive of reference in this cat_directory or subdirecto...
Definition cat_directory.hpp:132
libdar::cat_directory::get_path
path get_path() const
provide the current path of the directory (including its parent and ancestor)
libdar::cat_directory::get_tree_size
infinint get_tree_size() const
get then number of "cat_nomme" entry contained in this cat_directory and subdirectories (recursive ca...
libdar::cat_directory::is_empty
bool is_empty() const
whether this cat_directory is empty or not
Definition cat_directory.hpp:155
libdar::cat_directory::operator==
virtual bool operator==(const cat_entree &ref) const override
attention this compares only the directories themselves, not the list of their children
libdar::cat_directory::remove_if_no_mirage
void remove_if_no_mirage(const std::string &name)
remove the given entry if it is not a cat_mirage or a directory tree with cat_mirage objects
libdar::cat_entree
the root class from all other inherite for any entry in the catalogue
Definition cat_entree.hpp:60
libdar::cat_eod
the End of Directory entry class
Definition cat_eod.hpp:46
libdar::cat_inode::cat_inode
cat_inode(const infinint &xuid, const infinint &xgid, U_16 xperm, const datetime &last_access, const datetime &last_modif, const datetime &last_change, const std::string &xname, const infinint &device)
flag used to only consider certain fields when comparing/restoring inodes
libdar::cat_nomme
the base class for all entry that have a name
Definition cat_nomme.hpp:45
libdar::datetime
stores time information
Definition datetime.hpp:59
libdar::infinint
the arbitrary large positive integer class
Definition real_infinint.hpp:62
libdar::path
the class path is here to manipulate paths in the Unix notation: using'/'
Definition path.hpp:51
libdar::smart_pointer
smart pointer class to be used to automagically manage multiple time pointed to address
Definition smart_pointer.hpp:79
libdar::compression
compression
the different compression algorithm available
Definition compression.hpp:46
libdar::saved_status
saved_status
data saved status for an entry
Definition cat_status.hpp:44
libdar::saved_status::saved
@ saved
inode is saved in the archive
Definition cat_status.hpp:45
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
libdar::entree_stats
holds the statistics contents of a catalogue
Definition entree_stats.hpp:49