Main Page   Modules   Data Structures   File List   Data Fields   Globals  

Mask
[Class_wrapper]

Masks are used to build custom string matching rules by which libdar will select and exclude both file names and directory paths. More...

Data Structures

struct  dar_mask
 Incomplete struct for use as mask reference pointer. More...


Functions

NAMESPACE_LIBDAR_START dar_maskdar_mask_create_same_path (char *path, bool case_sensit)
 Matches if string is exactly the given mask (without wildcard expressions).

dar_maskdar_mask_create_bool (bool always)
 Always matches or never matches.

dar_maskdar_mask_create_and ()
 Evaluates the logical and between two or more masks.

dar_maskdar_mask_create_or ()
 Evaluates the logical or between two or more masks.

dar_maskdar_mask_create_exclude_dir (char *path, bool case_sensit)
 Matches any file and it's children.

dar_maskdar_mask_create_not (dar_mask *mask)
 Negation of another mask.

dar_maskdar_mask_create_regular (char *expr, bool case_sensit)
 Full regular expression matching.

dar_maskdar_mask_create_simple (char *expr, bool case_sensit)
 Simple text matching similiar to that done on the command line.

dar_maskdar_mask_create_simple_path (char *path, bool case_sensit)
 Matches any path and it's children plus any parents of that given path.

void dar_mask_destroy (dar_mask *mask)
 Frees memory used by mask object.

void dar_mask_and_add (dar_mask *ref, dar_mask *new_mask)
 Expands a union by adding another mask to an and mask.

void dar_mask_and_clear (dar_mask *ref)
 Clears all entries from an and mask.

U_I dar_mask_and_size (dar_mask *ref)
 Gets the number of elements in a union.

void dar_mask_or_add (dar_mask *ref, dar_mask *new_mask)
 Narrows an intersection by adding another mask to an or mask.

void dar_mask_or_clear (dar_mask *ref)
 Clears all entries from an or mask.

U_I dar_mask_or_size (dar_mask *ref)
 Gets the number of elements in an intersection.


Detailed Description

Masks are used to build custom string matching rules by which libdar will select and exclude both file names and directory paths.

Masks may concentrate on individual names, absolute, and relative paths. Masks may be combined in multiple layers recursively.

In the C bindings path classes are controlled by a set of functions; some type specific, some more general. Function names are organized starting with dar_mask. All constructor functions are grouped together are dar_mask_create followed by the name of the C++ library class minus the "mask". For example, the libdar::simple_path_mask constructor is dar_mask_create_simple_path. There are a few exceptions where the french names were translated into english (et and ou).

Almost all masks are treated as immutable in the C bindings. The exceptions are the union and intersection masks (and and or). Each of these masks has an additional set of functions for adding elements, clearing the set, and querying the amount of elements contained in the set. Each of these functions takes a reference to the element in question and any additional arguments required. Their names are organized as dar_mask_TYPE_FUNCTION. There are memory considerations when using these functions. More on that later.

Because all mask types end up as the same pointer type the system is obviously not very typesafe. This isn't a big deal for the most part and is useful because all mask types inherit from the same parent class. However, it is extremely important not to use a non-boolean combination mask as a reference in said operations. Such usage will not be fatal, but will not result in any useful results. See the functions which operate on the and and or masks for more information.

The last function is a wrapper for the destructor function. All mask classes override the same destructor, which will be called using the delete method when the destructor wrapper is invoked. This functions is called dar_mask_destroy.

The memory consideration is thus: The responsibility of invoking the destructor is in the users hands. The union and intersection masks copy all data passed in, leaving the original pointers untouched. Thus, if you want to avoid memory leaks this is a bad idea:

dar_mask* result =  dar_mask_create_or();
dar_mask_or_add( result, dar_mask_create_simple("/f*", TRUE) );
dar_mask_or_add( result, dar_mask_create_simple("/t*", TRUE) );

The pointer passed in will not be deleted. You need to call the destroy method after passing mask objects to other objects. The following is better.

dar_mask* result = dar_mask_create_or();
dar_mask* m1 = dar_mask_create_simple("/f*", TRUE);
dar_mask* m2 = dar_mask_create_simple("/t*", TRUE);
dar_mask_or_add(result, m1);
dar_mask_or_add(result, m2);
dar_mask_destroy(m1);
dar_mask_destroy(m2);

// later...
dar_mask_destroy(result);

That's what you have to do for every mask you make. Sorry.

Remember to delete your own c strings too.


Function Documentation

void dar_mask_and_add dar_mask   ref,
dar_mask   new_mask
 

Expands a union by adding another mask to an and mask.

Note:
It is important that only an and mask is used as the reference argument to this function. If the reference argument is not appropriate, null will be returned.

Definition at line 111 of file mask.cpp.

void dar_mask_and_clear dar_mask   ref
 

Clears all entries from an and mask.

Note:
It is important that only an and mask is used as the reference argument to this function. If the reference argument is not appropriate, the invalid reference mask will be returned unmodified.

Definition at line 119 of file mask.cpp.

U_I dar_mask_and_size dar_mask   ref
 

Gets the number of elements in a union.

Note:
It is important that only an and mask is used as the reference argument to this function. If the reference argument is not appropriate, the value zero will be returned.

Definition at line 126 of file mask.cpp.

dar_mask* dar_mask_create_and  
 

Evaluates the logical and between two or more masks.

Given the paths:

  • /foo
  • /foo/bar
  • /fast
  • /this
We use an and mask to combine two simple masks.

dar_mask* result = dar_mask_create_and();
dar_mask* m1 = dar_mask_create_simple("/f*", TRUE);
dar_mask* m2 = dar_mask_create_simple("*bar", TRUE);
dar_mask_and_add( m1 );
dar_mask_and_add( m2 );
dar_mask_destroy( m1 );
dar_mask_destroy( m2 );

The resulting match will be:

  • /foo/bar

Definition at line 59 of file mask.cpp.

dar_mask* dar_mask_create_exclude_dir char *    path,
bool    case_sensit
 

Matches any file and it's children.

Despite the name, this mask does not implicitly exclude. Wrap in a not mask to implement exclusion.

Given the paths:

  • /
  • /foo
  • /foo/bar
  • /foo/this
  • /foo/bar/fast
  • /foo/bar/faster
  • /slow
In this example we want to select only the path "/foo/bar" and exclude everything else. We will attempt that will an exclude directory mask. However, read below for an important warning about this.

dar_mask* result = dar_mask_create_exclude_dir( "/foo/bar", TRUE );

The resulting matches will be:

  • /foo/bar
  • /foo/bar/fast
  • /foo/bar/faster
NOTE WELL that the above example, assuming that we are creating our backup from the root directory ("/") may not work as expected! This is because while "bar" and its children will be accepted, "/" and "/foo" will not, meaning that there will be no directories to attach "bar" to.

To fix this problem, you must (if you really want to save the absolute path) use a simple path mask or save only the relative path information. In such a case:

Given the paths:

  • bar
  • bar/fast
  • bar/faster
You will be able to use an exclude directory mask, passing the string "bar" instead of "/foo/bar".

NOTE FURTHER that if you use a relative path a simple mask will often be easier.

Really, the exclude directory mask is meant for excluding specific paths within a hierarchy. When wrapped in a not mask the combination will provide the expected behavior.

dar_mask* m = dar_mask_create_exclude_dir( "/foo/bar", TRUE );
dar_mask* result = dar_mask_create_not( m );
dar_mask_destroy( m );

Given the original paths, the above code will produce the following matches:

  • /
  • /foo
  • /foo/this
  • /slow

Definition at line 69 of file mask.cpp.

dar_mask* dar_mask_create_not dar_mask   mask
 

Negation of another mask.

Useful for selective exclusion.

Given the paths:

  • /foo
  • /foo/bar
  • /fast
  • /this
We can use a simple mask wrapped in a not mask to exclude a desired path.

dar_mask* m = dar_mask_create_simple("/this", TRUE);
dar_mask* result = dar_mask_create_not( m );
dar_mask_destroy( m );

The resulting matches will be:

  • /foo
  • /foo/bar
  • /fast

Definition at line 76 of file mask.cpp.

dar_mask* dar_mask_create_or  
 

Evaluates the logical or between two or more masks.

Given the paths:

  • /foo
  • /foo/bar
  • /fast
  • /this
We use an or mask to combine two simple masks.

dar_mask* result = dar_mask_create_or();
dar_mask* m1 = dar_mask_create_simple("/f*", TRUE);
dar_mask* m2 = dar_mask_create_simple("/t*", TRUE);
dar_mask_or_add( m1 );
dar_mask_or_add( m2 );
dar_mask_destroy( m1 );
dar_mask_destroy( m2 );

The resulting matches will be:

  • /foo
  • /foo/bar
  • /fast
  • /this

Definition at line 64 of file mask.cpp.

dar_mask* dar_mask_create_regular char *    expr,
bool    case_sensit
 

Full regular expression matching.

See man 7 regex for more information.

Definition at line 83 of file mask.cpp.

NAMESPACE_LIBDAR_START dar_mask* dar_mask_create_same_path char *    path,
bool    case_sensit
 

Matches if string is exactly the given mask (without wildcard expressions).

Remember to destroy your input path when finished with it!

Definition at line 44 of file mask.cpp.

dar_mask* dar_mask_create_simple char *    expr,
bool    case_sensit
 

Simple text matching similiar to that done on the command line.

See man 7 glob for more information.

Definition at line 90 of file mask.cpp.

dar_mask* dar_mask_create_simple_path char *    path,
bool    case_sensit
 

Matches any path and it's children plus any parents of that given path.

Given the paths:

  • /
  • /foo
  • /foo/bar
  • /foo/this
  • /foo/bar/fast
  • /foo/bar/faster
  • /slow
In this example, we want to save everything in the directory "bar". Instead of passing the relative path, we want to save the whole tree, but want to exclude any excess data.

dar_mask* result = dar_mask_create_simple_path( "/foo/bar", TRUE );

The resulting matches will be:

  • /
  • /foo
  • /foo/bar
  • /foo/bar/fast
  • /foo/bar/faster
These extra directories would be excluded:
  • /slow
  • /foo/this

Definition at line 97 of file mask.cpp.

void dar_mask_destroy dar_mask   mask
 

Frees memory used by mask object.

Works for all mask types.

Definition at line 104 of file mask.cpp.

Referenced by dar_sup_spec_destroy(), and dar_sup_storage_destroy().

void dar_mask_or_add dar_mask   ref,
dar_mask   new_mask
 

Narrows an intersection by adding another mask to an or mask.

Note:
It is important that only an or mask is used as the reference argument to this function. If the reference argument is not appropriate, null will be returned.

Definition at line 132 of file mask.cpp.

void dar_mask_or_clear dar_mask   ref
 

Clears all entries from an or mask.

Note:
It is important that only an or mask is used as the reference argument to this function. If the reference argument is not appropriate, the invalid reference mask will be returned unmodified.

Definition at line 140 of file mask.cpp.

U_I dar_mask_or_size dar_mask   ref
 

Gets the number of elements in an intersection.

Note:
It is important that only an or mask is used as the reference argument to this function. If the reference argument is not appropriate, the value zero will be returned.

Definition at line 147 of file mask.cpp.