Disk ARchive  2.4.21
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 <new>
32 
33 #include "catalogue.hpp"
34 
35 namespace libdar
36 {
37 
40 
42 
44  {
45  data_preserve, //< do not overwrite (keep the 'in place' entry)
46  data_overwrite, //< overwirte the 'in place' entry by the 'to be added' one
47  data_preserve_mark_already_saved, //< keep the 'in place' but mark it as already saved in the archive of reference
48  data_overwrite_mark_already_saved, //< overwrite the 'in place' but mark the 'to be added' as already saved in the archive of reference
49  data_remove, //< remove the original data/EA (file is completely deleted)
50  data_undefined, //< action still undefined at this step of the evaluation
51  data_ask //< ask for user decision about file's data
52  };
53 
54 
56 
57  enum over_action_ea //< define the action to apply to each EA entry (not to the EA set of a particular inode)
58  {
59  EA_preserve, //< keep the EA of the 'in place' entry
60  EA_overwrite, //< keep the EA of the 'to be added' entry
61  EA_clear, //< drop the EA for the elected entry
62  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)
63  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)
64  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
65  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
66  EA_undefined, //< action still undefined at this step of the evaluation
67  EA_ask //< ask for user decision about EA
68  };
69 
70 
72 
75 
77  {
78  public:
80  virtual ~crit_action() {};
81 
83 
88  virtual void get_action(const nomme & first, const nomme & second, over_action_data & data, over_action_ea & ea) const = 0;
89 
91 
95  virtual crit_action *clone() const = 0;
96  };
97 
98 
100 
103 
105  {
106  public:
108 
111  crit_constant_action(over_action_data data, over_action_ea ea) { x_data = data; x_ea = ea; };
112 
113 
115  void get_action(const nomme & first, const nomme & second, over_action_data & data, over_action_ea & ea) const { data = x_data; ea = x_ea; };
116  crit_action *clone() const { return new (std::nothrow) crit_constant_action(*this); };
117 
118  private:
119  over_action_data x_data;
120  over_action_ea x_ea;
121  };
122 
123 
124 
126 
131 
132  class criterium
133  {
134  public:
135  virtual ~criterium() {};
136 
138 
142  virtual bool evaluate(const nomme &first, const nomme &second) const = 0;
143 
145 
149  virtual criterium *clone() const = 0;
150 
151  protected:
152  static const inode *get_inode(const nomme * arg);
153  };
154 
155 
156 
158 
161 
162  class testing : public crit_action
163  {
164  public:
166 
170  testing(const criterium & input, const crit_action & go_true, const crit_action & go_false);
171  testing(const testing & ref) : crit_action(ref) { copy_from(ref); if(!check()) throw Ememory("testing::testing(const testing &)"); };
172  const testing & operator = (const testing & ref) { free(); copy_from(ref); if(!check()) throw Ememory("testing::testing(const testing &)"); return *this; };
173  ~testing() { free(); };
174 
175 
177  void get_action(const nomme & first, const nomme & second, over_action_data & data, over_action_ea & ea) const
178  {
179  if(x_input->evaluate(first, second))
180  x_go_true->get_action(first, second, data, ea);
181  else
182  x_go_false->get_action(first, second, data, ea);
183  };
184 
185  crit_action *clone() const { return new (std::nothrow) testing(*this); };
186 
187  private:
188  criterium *x_input;
189  crit_action *x_go_true;
190  crit_action *x_go_false;
191 
192  void free();
193  void copy_from(const testing & ref);
194  bool check() const; //< returns false if an field is NULL
195  };
196 
197 
199 
202 
203  class crit_chain : public crit_action
204  {
205  public:
206  crit_chain() { sequence.clear(); };
207  crit_chain(const crit_chain & ref) : crit_action(ref) { copy_from(ref); };
208  const crit_chain & operator = (const crit_chain & ref) { destroy(); copy_from(ref); return *this; };
209  ~crit_chain() { destroy(); };
210 
211  void add(const crit_action & act);
212  void clear() { destroy(); };
213  void gobe(crit_chain & to_be_voided);
214 
215  void get_action(const nomme & first, const nomme & second, over_action_data & data, over_action_ea & ea) const;
216 
217  crit_action *clone() const { return new (std::nothrow) crit_chain(*this); };
218 
219  private:
220  std::vector<crit_action *> sequence;
221 
222  void destroy();
223  void copy_from(const crit_chain & ref);
224  };
225 
229 
230 
232 
235 
237  {
238  public:
239  bool evaluate(const nomme &first, const nomme &second) const { return dynamic_cast<const inode *>(&first) != NULL || dynamic_cast<const mirage *>(&first) != NULL; };
240  criterium *clone() const { return new (std::nothrow) crit_in_place_is_inode(*this); };
241  };
242 
243 
245 
247  {
248  public:
249  bool evaluate(const nomme &first, const nomme &second) const { return dynamic_cast<const directory *>(&first) != NULL; };
250  criterium *clone() const { return new (std::nothrow) crit_in_place_is_dir(*this); };
251  };
252 
253 
255 
257  {
258  public:
259  bool evaluate(const nomme &first, const nomme &second) const;
260  criterium *clone() const { return new (std::nothrow) crit_in_place_is_file(*this); };
261  };
262 
264 
266 
268  {
269  public:
270  bool evaluate(const nomme &first, const nomme &second) const { return dynamic_cast<const mirage *>(&first) != NULL; };
271  criterium *clone() const { return new (std::nothrow) crit_in_place_is_hardlinked_inode(*this); };
272  };
273 
274 
277  {
278  bool evaluate(const nomme &first, const nomme &second) const
279  {
280  const mirage * tmp = dynamic_cast<const mirage *>(&first);
281  return tmp != NULL && tmp->is_first_mirage();
282  };
283  criterium *clone() const { return new (std::nothrow) crit_in_place_is_new_hardlinked_inode(*this); };
284  };
285 
286 
288 
290 
292  {
293  public:
294  crit_in_place_data_more_recent(const infinint & hourshift = 0) : x_hourshift(hourshift) {};
295 
296  bool evaluate(const nomme &first, const nomme &second) const;
297  criterium *clone() const { return new (std::nothrow) crit_in_place_data_more_recent(*this); };
298 
299  private:
300  infinint x_hourshift;
301  };
302 
303 
305 
307 
308 
310  {
311  public:
312  crit_in_place_data_more_recent_or_equal_to(const infinint & date, const infinint & hourshift = 0) : x_hourshift(hourshift), x_date(date) {};
313 
314  bool evaluate(const nomme &first, const nomme &second) const;
315  criterium *clone() const { return new (std::nothrow) crit_in_place_data_more_recent_or_equal_to(*this); };
316 
317  private:
318  infinint x_hourshift;
319  infinint x_date;
320  };
321 
322 
324 
326 
328  {
329  public:
330  bool evaluate(const nomme &first, const nomme &second) const;
331  criterium *clone() const { return new (std::nothrow) crit_in_place_data_bigger(*this); };
332  };
333 
334 
335 
337 
339 
341  {
342  public:
343  bool evaluate(const nomme &first, const nomme &second) const;
344  criterium *clone() const { return new (std::nothrow) crit_in_place_data_saved(*this); };
345  };
346 
347 
349 
351  {
352  public:
353  bool evaluate(const nomme &first, const nomme &second) const;
354  criterium *clone() const { return new (std::nothrow) crit_in_place_data_dirty(*this); };
355  };
356 
358 
360  {
361  public:
362  bool evaluate(const nomme &first, const nomme &second) const;
363  criterium *clone() const { return new (std::nothrow) crit_in_place_data_sparse(*this); };
364  };
365 
366 
369 
371  {
372  public:
373  bool evaluate(const nomme &first, const nomme &second) const
374  {
375  const inode *tmp = dynamic_cast<const inode *>(&first);
376  return tmp != NULL && tmp->ea_get_saved_status() != inode::ea_none && tmp->ea_get_saved_status() != inode::ea_removed;
377  };
378  criterium *clone() const { return new (std::nothrow) crit_in_place_EA_present(*this); };
379  };
380 
381 
383 
388 
390  {
391  public:
392  crit_in_place_EA_more_recent(const infinint & hourshift = 0) : x_hourshift(hourshift) {};
393 
394  bool evaluate(const nomme &first, const nomme &second) const;
395  criterium *clone() const { return new (std::nothrow) crit_in_place_EA_more_recent(*this); };
396 
397  private:
398  infinint x_hourshift;
399  };
400 
401 
403 
406 
408  {
409  public:
410  crit_in_place_EA_more_recent_or_equal_to(const infinint & date, const infinint & hourshift = 0) : x_hourshift(hourshift), x_date(date) {};
411 
412  bool evaluate(const nomme &first, const nomme &second) const;
413  criterium *clone() const { return new (std::nothrow) crit_in_place_EA_more_recent_or_equal_to(*this); };
414 
415  private:
416  infinint x_hourshift;
417  infinint x_date;
418  };
419 
420 
422 
424 
426  {
427  public:
428  bool evaluate(const nomme &first, const nomme &second) const;
429  criterium *clone() const { return new (std::nothrow) crit_in_place_more_EA(*this); };
430  };
431 
432 
433 
435 
437 
439  {
440  public:
441  bool evaluate(const nomme &first, const nomme &second) const;
442  criterium *clone() const { return new (std::nothrow) crit_in_place_EA_bigger(*this); };
443  };
444 
445 
447 
449 
451  {
452  public:
453  bool evaluate(const nomme &first, const nomme &second) const;
454  criterium *clone() const { return new (std::nothrow) crit_in_place_EA_saved(*this); };
455  };
456 
457 
459 
462 
463  class crit_same_type : public criterium
464  {
465  public:
466  bool evaluate(const nomme &first, const nomme &second) const;
467  criterium *clone() const { return new (std::nothrow) crit_same_type(*this); };
468  };
469 
470 
472 
473  class crit_not : public criterium
474  {
475  public:
476  crit_not(const criterium & crit) { x_crit = crit.clone(); if(x_crit == NULL) throw Ememory("crit_not::crit_not"); };
477  crit_not(const crit_not & ref) : criterium (ref) { copy_from(ref); };
478  const crit_not & operator = (const crit_not & ref) { destroy(); copy_from(ref); return *this; };
479  ~crit_not() { destroy(); };
480 
481  bool evaluate(const nomme & first, const nomme & second) const { return ! x_crit->evaluate(first, second); };
482  criterium *clone() const { return new (std::nothrow) crit_not(*this); };
483 
484  protected:
485  const criterium *x_crit;
486 
487  private:
488  void copy_from(const crit_not & ref);
489  void destroy() { if(x_crit != NULL) { delete x_crit; x_crit = NULL; } };
490  };
491 
493 
494  class crit_and : public criterium
495  {
496  public:
497  crit_and() { clear(); };
498  crit_and(const crit_and & ref) : criterium(ref) { copy_from(ref); };
499  const crit_and & operator = (const crit_and & ref) { detruit(); copy_from(ref); return *this; };
500  ~crit_and() { detruit(); };
501 
502  void add_crit(const criterium & ref);
503  void clear() { detruit(); };
504 
506  void gobe(crit_and & to_be_voided);
507 
508  virtual bool evaluate(const nomme & first, const nomme & second) const;
509  criterium *clone() const { return new (std::nothrow) crit_and(*this); };
510 
511  protected:
512  std::vector<criterium *> operand;
513 
514  private:
515  void copy_from(const crit_and & ref);
516  void detruit();
517  };
518 
519  class crit_or : public crit_and
520  {
521  public:
522  crit_or() { clear(); };
523 
524  bool evaluate(const nomme & first, const nomme & second) const;
525  criterium *clone() const { return new (std::nothrow) crit_or(*this); };
526 
527  };
528 
529  class crit_invert : public crit_not
530  {
531  public:
532  crit_invert(const criterium & crit) : crit_not(crit) {};
533 
534  bool evaluate(const nomme & first, const nomme & second) const { return x_crit->evaluate(second, first); };
535  criterium *clone() const { return new (std::nothrow) crit_invert(*this); };
536  };
537 
538 
540 
546  extern over_action_ea crit_ask_user_for_EA_action(user_interaction & dialog, const std::string & full_name, const entree *already_here, const entree *dolly);
547 
549 
555  extern over_action_data crit_ask_user_for_data_action(user_interaction & dialog, const std::string & full_name, const entree *already_here, const entree *dolly);
556 
558 
563  extern void crit_show_entry_info(user_interaction & dialog, const std::string & full_name, const entree *already_here, const entree *dolly);
564 
566 
567 } // end of namespace
568 
569 #endif
returns true if the first entry is a inode with several hard links (whatever is the second entry) and...
Definition: criterium.hpp:276
bool evaluate(const nomme &first, const nomme &second) const
criterum interface method
Definition: criterium.hpp:249
return true if the entry is a sparse file (or hard linked sparse file)
Definition: criterium.hpp:359
criterium * clone() const
clone construction method
Definition: criterium.hpp:413
bool evaluate(const nomme &first, const nomme &second) const
criterum interface method
Definition: criterium.hpp:373
over_action_data
the possible actions for overwriting data
Definition: criterium.hpp:43
criterium * clone() const
clone construction method
Definition: criterium.hpp:509
returns true if the in place entry has its EA saved (not just marked as saved) in the archve of refer...
Definition: criterium.hpp:450
void get_action(const nomme &first, const 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:115
crit_action * clone() const
clone construction method
Definition: criterium.hpp:185
the deleted file entry
Definition: catalogue.hpp:912
criterium * clone() const
clone construction method
Definition: criterium.hpp:344
bool evaluate(const nomme &first, const nomme &second) const
criterum interface method
Definition: criterium.hpp:239
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:309
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:260
returns true if the first entry is a plain file (whatever is the second)
Definition: criterium.hpp:256
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:438
realises the negation of the criterium given in argument to its constructor
Definition: criterium.hpp:473
the root class from all other inherite for any entry in the catalogue
Definition: catalogue.hpp:94
the base class for all entry that have a name
Definition: catalogue.hpp:174
the basic constant action
Definition: criterium.hpp:104
the hard link implementation, mirage is the named entry owned by a directory it points to a common "e...
Definition: catalogue.hpp:399
criterium * clone() const
clone construction method
Definition: criterium.hpp:395
the directory inode class
Definition: catalogue.hpp:653
over_action_ea
the possible action for overwriting EA
Definition: criterium.hpp:57
void get_action(const nomme &first, const 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:177
realises the AND operator
Definition: criterium.hpp:494
returns true if the data of the first entry is bigger or equal to the one of the second entry ...
Definition: criterium.hpp:327
crit_action * clone() const
clone construction method
Definition: criterium.hpp:217
returns true if the first entry is a inode with several hard links (whatever is the second entry) ...
Definition: criterium.hpp:267
return true if the entry is a dirty file (or hard linked dirty file)
Definition: criterium.hpp:350
the crit_chain class sequences crit_actions up to full definition of the action
Definition: criterium.hpp:203
criterium * clone() const
clone construction method
Definition: criterium.hpp:250
criterium * clone() const
clone construction method
Definition: criterium.hpp:297
criterium * clone() const
clone construction method
Definition: criterium.hpp:482
the root class for all inode
Definition: catalogue.hpp:203
returns true if the EA of the first entry is more recent or equal to the one of the second entry ...
Definition: criterium.hpp:389
exception used when memory has been exhausted
Definition: erreurs.hpp:105
the global action for overwriting
Definition: criterium.hpp:76
criterium * clone() const
clone construction method
Definition: criterium.hpp:442
returns true if the two entries are of the same type (plain-file/char dev/block dev/named pipe/symlin...
Definition: criterium.hpp:463
virtual crit_action * clone() const =0
clone construction method
over_action_data crit_ask_user_for_data_action(user_interaction &dialog, const std::string &full_name, const entree *already_here, const entree *dolly)
ask user for Data action
criterium * clone() const
clone construction method
Definition: criterium.hpp:454
void crit_show_entry_info(user_interaction &dialog, const std::string &full_name, const entree *already_here, const entree *dolly)
show information suited for user comparison and decision for entry in conflict
criterium * clone() const
clone construction method
Definition: criterium.hpp:429
criterium * clone() const
clone construction method
Definition: criterium.hpp:315
criterium * clone() const
clone construction method
Definition: criterium.hpp:363
over_action_ea crit_ask_user_for_EA_action(user_interaction &dialog, const std::string &full_name, const entree *already_here, const entree *dolly)
ask user for EA action
virtual void get_action(const nomme &first, const nomme &second, over_action_data &data, over_action_ea &ea) const =0
the action to take based on the files to compare
the generic criterium class, parent of all criterium
Definition: criterium.hpp:132
bool evaluate(const nomme &first, const nomme &second) const
criterum interface method
Definition: criterium.hpp:481
criterium * clone() const
clone construction method
Definition: criterium.hpp:467
returns true if the first entry is an inode (whatever is the second)
Definition: criterium.hpp:236
criterium * clone() const
clone construction method
Definition: criterium.hpp:354
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:291
the testing class binds criterium to actions
Definition: criterium.hpp:162
returns true if the data of the first entry is saved int the archive (not marked as unchanged since t...
Definition: criterium.hpp:340
the arbitrary large positive integer class
bool is_first_mirage() const
whether we are the mirage that triggered this hard link creation
Definition: catalogue.hpp:452
criterium * clone() const
clone construction method
Definition: criterium.hpp:240
criterium * clone() const
clone construction method
Definition: criterium.hpp:271
crit_constant_action(over_action_data data, over_action_ea ea)
the constuctor
Definition: criterium.hpp:111
virtual ~crit_action()
the destructor
Definition: criterium.hpp:80
returns true if the first entry has more or even EA (in number not in size) than the second entry ...
Definition: criterium.hpp:425
bool evaluate(const nomme &first, const nomme &second) const
criterum interface method
Definition: criterium.hpp:270
criterium * clone() const
clone construction method
Definition: criterium.hpp:331
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:43
returns true if the first entry is a directory (whatever is the second)
Definition: criterium.hpp:246
here is defined the many classed which is build of the catalogue
criterium * clone() const
clone construction method
Definition: criterium.hpp:378
returns true if the EA of the first entry is more recent or equal to the fixed date given in argument...
Definition: criterium.hpp:407
crit_action * clone() const
clone construction method
Definition: criterium.hpp:116