Disk ARchive  2.5.9
Full featured and portable backup and archiving tool
criterium.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 #ifndef CRITERIUM_HPP
27 #define CRITERIUM_HPP
28 
29 #include "../my_config.h"
30 
31 #include "on_pool.hpp"
32 #include "cat_nomme.hpp"
33 #include "cat_inode.hpp"
34 #include "cat_directory.hpp"
35 
36 namespace libdar
37 {
38 
41 
43 
45  {
46  data_preserve, //< do not overwrite (keep the 'in place' entry)
47  data_overwrite, //< overwirte the 'in place' entry by the 'to be added' one
48  data_preserve_mark_already_saved, //< keep the 'in place' but mark it as already saved in the archive of reference
49  data_overwrite_mark_already_saved, //< overwrite the 'in place' but mark the 'to be added' as already saved in the archive of reference
50  data_remove, //< remove the original data/EA (file is completely deleted)
51  data_undefined, //< action still undefined at this step of the evaluation
52  data_ask //< ask for user decision about file's data
53  };
54 
55 
57 
58  enum over_action_ea //< define the action to apply to each EA entry (not to the EA set of a particular inode)
59  {
60  EA_preserve, //< keep the EA of the 'in place' entry
61  EA_overwrite, //< keep the EA of the 'to be added' entry
62  EA_clear, //< drop the EA for the elected entry
63  EA_preserve_mark_already_saved, //< drop any EA but mark them as already saved in the archive of reference (ctime is the one of the 'in place' inode)
64  EA_overwrite_mark_already_saved, //< drop any EA but mark them as already saved in the archive of reference (ctime is the one of the 'to be added' inode)
65  EA_merge_preserve, //< merge EA but do not overwrite existing EA of 'in place' by one of the same name of 'to be added' inode
66  EA_merge_overwrite, //< merge EA but if both inode share an EA with the same name, take keep the one of the 'to be added' inode
67  EA_undefined, //< action still undefined at this step of the evaluation
68  EA_ask //< ask for user decision about EA
69  };
70 
71 
73 
76 
77  class crit_action: public on_pool
78  {
79  public:
81  virtual ~crit_action() {};
82 
84 
89  virtual void get_action(const cat_nomme & first, const cat_nomme & second, over_action_data & data, over_action_ea & ea) const = 0;
90 
92 
96  virtual crit_action *clone() const = 0;
97  };
98 
99 
101 
104 
106  {
107  public:
109 
112  crit_constant_action(over_action_data data, over_action_ea ea) { x_data = data; x_ea = ea; };
113 
114 
116  void get_action(const cat_nomme & first, const cat_nomme & second, over_action_data & data, over_action_ea & ea) const { data = x_data; ea = x_ea; };
117  crit_action *clone() const { return new (get_pool()) crit_constant_action(*this); };
118 
119  private:
120  over_action_data x_data;
121  over_action_ea x_ea;
122  };
123 
124 
125 
127 
132 
133  class criterium : public on_pool
134  {
135  public:
136  virtual ~criterium() throw(Ebug) {};
137 
139 
143  virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const = 0;
144 
146 
150  virtual criterium *clone() const = 0;
151 
152  protected:
153  static const cat_inode *get_inode(const cat_nomme * arg);
154  };
155 
156 
157 
159 
162 
163  class testing : public crit_action
164  {
165  public:
167 
171  testing(const criterium & input, const crit_action & go_true, const crit_action & go_false);
172  testing(const testing & ref) : crit_action(ref) { copy_from(ref); if(!check()) throw Ememory("testing::testing(const testing &)"); };
173  const testing & operator = (const testing & ref) { free(); copy_from(ref); if(!check()) throw Ememory("testing::testing(const testing &)"); return *this; };
174  ~testing() { free(); };
175 
176 
178  void get_action(const cat_nomme & first, const cat_nomme & second, over_action_data & data, over_action_ea & ea) const
179  {
180  if(x_input->evaluate(first, second))
181  x_go_true->get_action(first, second, data, ea);
182  else
183  x_go_false->get_action(first, second, data, ea);
184  };
185 
186  crit_action *clone() const { return new (get_pool()) testing(*this); };
187 
188  private:
189  criterium *x_input;
190  crit_action *x_go_true;
191  crit_action *x_go_false;
192 
193  void free();
194  void copy_from(const testing & ref);
195  bool check() const; //< returns false if an field is nullptr
196  };
197 
198 
200 
203 
204  class crit_chain : public crit_action
205  {
206  public:
207  crit_chain() { sequence.clear(); };
208  crit_chain(const crit_chain & ref) : crit_action(ref) { copy_from(ref); };
209  const crit_chain & operator = (const crit_chain & ref) { destroy(); copy_from(ref); return *this; };
210  ~crit_chain() { destroy(); };
211 
212  void add(const crit_action & act);
213  void clear() { destroy(); };
214  void gobe(crit_chain & to_be_voided);
215 
216  void get_action(const cat_nomme & first, const cat_nomme & second, over_action_data & data, over_action_ea & ea) const;
217 
218  crit_action *clone() const { return new (get_pool()) crit_chain(*this); };
219 
220  private:
221  std::vector<crit_action *> sequence;
222 
223  void destroy();
224  void copy_from(const crit_chain & ref);
225  };
226 
230 
231 
233 
236 
238  {
239  public:
240  bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
241  criterium *clone() const { return new (get_pool()) crit_in_place_is_inode(*this); };
242  };
243 
244 
246 
248  {
249  public:
250  bool evaluate(const cat_nomme &first, const cat_nomme &second) const { return dynamic_cast<const cat_directory *>(&first) != nullptr; };
251  criterium *clone() const { return new (get_pool()) crit_in_place_is_dir(*this); };
252  };
253 
254 
256 
258  {
259  public:
260  bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
261  criterium *clone() const { return new (get_pool()) crit_in_place_is_file(*this); };
262  };
263 
265 
267 
269  {
270  public:
271  bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
272  criterium *clone() const { return new (get_pool()) crit_in_place_is_hardlinked_inode(*this); };
273  };
274 
275 
278  {
279  public:
280  bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
281  criterium *clone() const { return new (get_pool()) crit_in_place_is_new_hardlinked_inode(*this); };
282  };
283 
284 
286 
288 
290  {
291  public:
292  crit_in_place_data_more_recent(const infinint & hourshift = 0) : x_hourshift(hourshift) {};
293 
294  bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
295  criterium *clone() const { return new (get_pool()) crit_in_place_data_more_recent(*this); };
296 
297  private:
298  infinint x_hourshift;
299  };
300 
301 
303 
305 
306 
308  {
309  public:
310  crit_in_place_data_more_recent_or_equal_to(const infinint & date, const infinint & hourshift = 0) : x_hourshift(hourshift), x_date(date) {};
311 
312  bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
314 
315  private:
316  infinint x_hourshift;
317  infinint x_date;
318  };
319 
320 
322 
324 
326  {
327  public:
328  bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
329  criterium *clone() const { return new (get_pool()) crit_in_place_data_bigger(*this); };
330  };
331 
332 
333 
335 
337 
339  {
340  public:
341  bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
342  criterium *clone() const { return new (get_pool()) crit_in_place_data_saved(*this); };
343  };
344 
345 
347 
349  {
350  public:
351  bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
352  criterium *clone() const { return new (get_pool()) crit_in_place_data_dirty(*this); };
353  };
354 
356 
358  {
359  public:
360  bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
361  criterium *clone() const { return new (get_pool()) crit_in_place_data_sparse(*this); };
362  };
363 
364 
367 
369  {
370  public:
371  bool evaluate(const cat_nomme &first, const cat_nomme &second) const
372  {
373  const cat_inode *tmp = dynamic_cast<const cat_inode *>(&first);
374  return tmp != nullptr && tmp->ea_get_saved_status() != cat_inode::ea_none && tmp->ea_get_saved_status() != cat_inode::ea_removed;
375  };
376  criterium *clone() const { return new (get_pool()) crit_in_place_EA_present(*this); };
377  };
378 
379 
381 
386 
388  {
389  public:
390  crit_in_place_EA_more_recent(const infinint & hourshift = 0) : x_hourshift(hourshift) {};
391 
392  bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
393  criterium *clone() const { return new (get_pool()) crit_in_place_EA_more_recent(*this); };
394 
395  private:
396  infinint x_hourshift;
397  };
398 
399 
401 
404 
406  {
407  public:
408  crit_in_place_EA_more_recent_or_equal_to(const infinint & date, const infinint & hourshift = 0) : x_hourshift(hourshift), x_date(date) {};
409 
410  bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
412 
413  private:
414  infinint x_hourshift;
415  infinint x_date;
416  };
417 
418 
420 
422 
424  {
425  public:
426  bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
427  criterium *clone() const { return new (get_pool()) crit_in_place_more_EA(*this); };
428  };
429 
430 
431 
433 
435 
437  {
438  public:
439  bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
440  criterium *clone() const { return new (get_pool()) crit_in_place_EA_bigger(*this); };
441  };
442 
443 
445 
447 
449  {
450  public:
451  bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
452  criterium *clone() const { return new (get_pool()) crit_in_place_EA_saved(*this); };
453  };
454 
455 
457 
460 
461  class crit_same_type : public criterium
462  {
463  public:
464  bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
465  criterium *clone() const { return new (get_pool()) crit_same_type(*this); };
466  };
467 
468 
470 
471  class crit_not : public criterium
472  {
473  public:
474  crit_not(const criterium & crit) { x_crit = crit.clone(); if(x_crit == nullptr) throw Ememory("crit_not::crit_not"); };
475  crit_not(const crit_not & ref) : criterium (ref) { copy_from(ref); };
476  const crit_not & operator = (const crit_not & ref) { destroy(); copy_from(ref); return *this; };
477  ~crit_not() { destroy(); };
478 
479  bool evaluate(const cat_nomme & first, const cat_nomme & second) const { return ! x_crit->evaluate(first, second); };
480  criterium *clone() const { return new (get_pool()) crit_not(*this); };
481 
482  protected:
483  const criterium *x_crit;
484 
485  private:
486  void copy_from(const crit_not & ref);
487  void destroy() { if(x_crit != nullptr) { delete x_crit; x_crit = nullptr; } };
488  };
489 
491 
492  class crit_and : public criterium
493  {
494  public:
495  crit_and() { clear(); };
496  crit_and(const crit_and & ref) : criterium(ref) { copy_from(ref); };
497  const crit_and & operator = (const crit_and & ref) { detruit(); copy_from(ref); return *this; };
498  ~crit_and() { detruit(); };
499 
500  void add_crit(const criterium & ref);
501  void clear() { detruit(); };
502 
504  void gobe(crit_and & to_be_voided);
505 
506  virtual bool evaluate(const cat_nomme & first, const cat_nomme & second) const;
507  criterium *clone() const { return new (get_pool()) crit_and(*this); };
508 
509  protected:
510  std::vector<criterium *> operand;
511 
512  private:
513  void copy_from(const crit_and & ref);
514  void detruit();
515  };
516 
517  class crit_or : public crit_and
518  {
519  public:
520  crit_or() { clear(); };
521 
522  bool evaluate(const cat_nomme & first, const cat_nomme & second) const;
523  criterium *clone() const { return new (get_pool()) crit_or(*this); };
524 
525  };
526 
527  class crit_invert : public crit_not
528  {
529  public:
530  crit_invert(const criterium & crit) : crit_not(crit) {};
531 
532  bool evaluate(const cat_nomme & first, const cat_nomme & second) const { return x_crit->evaluate(second, first); };
533  criterium *clone() const { return new (get_pool()) crit_invert(*this); };
534  };
535 
536 
538 
544  extern over_action_ea crit_ask_user_for_EA_action(user_interaction & dialog, const std::string & full_name, const cat_entree *already_here, const cat_entree *dolly);
545 
547 
553  extern over_action_ea crit_ask_user_for_FSA_action(user_interaction & dialog, const std::string & full_name, const cat_entree *already_here, const cat_entree *dolly);
554 
556 
562  extern over_action_data crit_ask_user_for_data_action(user_interaction & dialog, const std::string & full_name, const cat_entree *already_here, const cat_entree *dolly);
563 
564 
566 
571  extern void crit_show_entry_info(user_interaction & dialog, const std::string & full_name, const cat_entree *already_here, const cat_entree *dolly);
572 
574 
575 } // end of namespace
576 
577 #endif
returns true if the first entry is a inode with several hard links (whatever is the second entry) and...
Definition: criterium.hpp:277
over_action_data crit_ask_user_for_data_action(user_interaction &dialog, const std::string &full_name, const cat_entree *already_here, const cat_entree *dolly)
ask user for Data action
base class of all objects contained in a catalogue and that can be named
class used to organize objects in tree in catalogue as like directories in a filesystem ...
return true if the entry is a sparse file (or hard linked sparse file)
Definition: criterium.hpp:357
criterium * clone() const
clone construction method
Definition: criterium.hpp:411
memory_pool * get_pool() const
Definition: on_pool.hpp:144
over_action_data
the possible actions for overwriting data
Definition: criterium.hpp:44
virtual void get_action(const cat_nomme &first, const cat_nomme &second, over_action_data &data, over_action_ea &ea) const =0
the action to take based on the files to compare
criterium * clone() const
clone construction method
Definition: criterium.hpp:507
returns true if the in place entry has its EA saved (not just marked as saved) in the archve of refer...
Definition: criterium.hpp:448
crit_action * clone() const
clone construction method
Definition: criterium.hpp:186
criterium * clone() const
clone construction method
Definition: criterium.hpp:342
returns true if the data of the first entry is more recent or of the same date as the fixed date give...
Definition: criterium.hpp:307
virtual criterium * clone() const =0
clone construction method
bool ea()
returns whether EA support has been activated at compilation time
criterium * clone() const
clone construction method
Definition: criterium.hpp:261
returns true if the first entry is a plain file (whatever is the second)
Definition: criterium.hpp:257
This is a pure virtual class that is used by libdar when interaction with the user is required...
returns true if the space used by EA of the first entry is greater or equal to the space used by the ...
Definition: criterium.hpp:436
realises the negation of the criterium given in argument to its constructor
Definition: criterium.hpp:471
the basic constant action
Definition: criterium.hpp:105
criterium * clone() const
clone construction method
Definition: criterium.hpp:393
over_action_ea
the possible action for overwriting EA
Definition: criterium.hpp:58
realises the AND operator
Definition: criterium.hpp:492
returns true if the data of the first entry is bigger or equal to the one of the second entry ...
Definition: criterium.hpp:325
void crit_show_entry_info(user_interaction &dialog, const std::string &full_name, const cat_entree *already_here, const cat_entree *dolly)
show information suited for user comparison and decision for entry in conflict
over_action_ea crit_ask_user_for_FSA_action(user_interaction &dialog, const std::string &full_name, const cat_entree *already_here, const cat_entree *dolly)
ask user for FSA action
the cat_directory inode class
crit_action * clone() const
clone construction method
Definition: criterium.hpp:218
bool evaluate(const cat_nomme &first, const cat_nomme &second) const
criterum interface method
Definition: criterium.hpp:250
returns true if the first entry is a inode with several hard links (whatever is the second entry) ...
Definition: criterium.hpp:268
return true if the entry is a dirty file (or hard linked dirty file)
Definition: criterium.hpp:348
the crit_chain class sequences crit_actions up to full definition of the action
Definition: criterium.hpp:204
bool evaluate(const cat_nomme &first, const cat_nomme &second) const
criterum interface method
Definition: criterium.hpp:371
criterium * clone() const
clone construction method
Definition: criterium.hpp:251
criterium * clone() const
clone construction method
Definition: criterium.hpp:295
criterium * clone() const
clone construction method
Definition: criterium.hpp:480
returns true if the EA of the first entry is more recent or equal to the one of the second entry ...
Definition: criterium.hpp:387
exception used when memory has been exhausted
Definition: erreurs.hpp:111
the global action for overwriting
Definition: criterium.hpp:77
criterium * clone() const
clone construction method
Definition: criterium.hpp:440
returns true if the two entries are of the same type (plain-file/char dev/block dev/named pipe/symlin...
Definition: criterium.hpp:461
the base class for all entry that have a name
Definition: cat_nomme.hpp:44
virtual crit_action * clone() const =0
clone construction method
criterium * clone() const
clone construction method
Definition: criterium.hpp:452
criterium * clone() const
clone construction method
Definition: criterium.hpp:427
criterium * clone() const
clone construction method
Definition: criterium.hpp:313
criterium * clone() const
clone construction method
Definition: criterium.hpp:361
exception used to signal a bug. A bug is triggered when reaching some code that should never be reach...
Definition: erreurs.hpp:137
the generic criterium class, parent of all criterium
Definition: criterium.hpp:133
this is the base class of object that can be allocated on a memory pool
criterium * clone() const
clone construction method
Definition: criterium.hpp:465
the root class for all cat_inode
Definition: cat_inode.hpp:54
returns true if the first entry is an inode (whatever is the second)
Definition: criterium.hpp:237
criterium * clone() const
clone construction method
Definition: criterium.hpp:352
returns true if the data of the first entry is more recent or of the same date of the one of the seco...
Definition: criterium.hpp:289
base object for all inode types, managed EA and FSA, dates, permissions, ownership, ...
criterium * clone() const
clone construction method
Definition: criterium.hpp:281
the testing class binds criterium to actions
Definition: criterium.hpp:163
returns true if the data of the first entry is saved int the archive (not marked as unchanged since t...
Definition: criterium.hpp:338
over_action_ea crit_ask_user_for_EA_action(user_interaction &dialog, const std::string &full_name, const cat_entree *already_here, const cat_entree *dolly)
ask user for EA action
the arbitrary large positive integer class
criterium * clone() const
clone construction method
Definition: criterium.hpp:241
criterium * clone() const
clone construction method
Definition: criterium.hpp:272
the root class from all other inherite for any entry in the catalogue
Definition: cat_entree.hpp:85
void get_action(const cat_nomme &first, const cat_nomme &second, over_action_data &data, over_action_ea &ea) const
the inherited pure virtual method from class action that must be gimplemented
Definition: criterium.hpp:178
crit_constant_action(over_action_data data, over_action_ea ea)
the constuctor
Definition: criterium.hpp:112
virtual ~crit_action()
the destructor
Definition: criterium.hpp:81
bool evaluate(const cat_nomme &first, const cat_nomme &second) const
criterum interface method
Definition: criterium.hpp:479
returns true if the first entry has more or even EA (in number not in size) than the second entry ...
Definition: criterium.hpp:423
criterium * clone() const
clone construction method
Definition: criterium.hpp:329
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47
returns true if the first entry is a cat_directory (whatever is the second)
Definition: criterium.hpp:247
criterium * clone() const
clone construction method
Definition: criterium.hpp:376
returns true if the EA of the first entry is more recent or equal to the fixed date given in argument...
Definition: criterium.hpp:405
void get_action(const cat_nomme &first, const cat_nomme &second, over_action_data &data, over_action_ea &ea) const
the inherited pure virtual methods from class action that must be implemented
Definition: criterium.hpp:116
crit_action * clone() const
clone construction method
Definition: criterium.hpp:117