29 debug ( 3,
"<%s>.", expr );
33 error (
"Received a rule with rule_p->mask == 0x00. Exit." );
46 if ( ( ret = regcomp ( &rule_p->
expr, expr, REG_EXTENDED | REG_NOSUB ) ) ) {
48 error (
"Invalid regexp pattern <%s>: %s (regex-errno: %i).", expr, buf, ret );
62 char *line_buf = NULL;
63 FILE *f = fopen ( rulfpath,
"r" );
68 error (
"Cannot open \"%s\" for reading.", rulfpath );
72 GHashTable *autowrules_ht = g_hash_table_new_full ( g_str_hash, g_str_equal, free, 0 );
77 while ( ( linelen = getline ( &line_buf, &size, f ) ) != -1 ) {
80 char *line = line_buf;
84 memset (
rule, 0,
sizeof ( *
rule ) );
104 error (
"Wrong rule action <%c>.", *line );
131 #ifdef DETAILED_FTYPE
171 warning (
"Used \"w\" or/and \"m\" or/and \"s\" rule in rsync \"--monitor\" case."
172 " This may cause unexpected problems." );
197 warning (
"Cannot parse the rule <%s>", &line[-1] );
208 goto l_parse_rules_fromfile_end;
215 if ( *line !=
'w' ) {
220 char *expr = alloca ( linelen + 2 );
221 memcpy ( expr, line, linelen + 1 );
222 size_t exprlen = linelen;
225 if ( line[1] ==
'^' ) {
233 if ( *line ==
'd' || *line ==
'*' ) {
235 end = &expr[exprlen];
237 if ( end[-1] !=
'$' )
243 g_hash_table_insert ( autowrules_ht, strdup ( expr ), GINT_TO_POINTER ( 1 ) );
249 end = strrchr ( expr,
'/' );
252 if ( end[-1] !=
'$' )
256 exprlen = ( size_t ) ( end - expr );
264 if ( !g_hash_table_lookup ( autowrules_ht, expr ) ) {
272 debug ( 1,
"Rule #%i <+> <w> pattern <%s> (length: %i) [auto].",
276 goto l_parse_rules_fromfile_end;
278 g_hash_table_insert ( autowrules_ht, strdup ( expr ), GINT_TO_POINTER ( 1 ) );
280 }
while ( end != NULL );
289 l_parse_rules_fromfile_end:
295 debug ( 3,
"Adding tail-rule #%u (effective #%u).", -1, i );
298 g_hash_table_destroy ( autowrules_ht );
300 debug ( 3,
"Total (p == %p):", rules );
304 debug ( 4,
"\t%i\t%i\t%p/%p", i, rules[i].objtype, (
void * ) (
long ) rules[i].perm, (
void * ) (
long ) rules[i].mask );
306 }
while ( rules[i].mask !=
RA_NONE );
329 debug ( 3,
"rules_search_getperm(\"%s\", %p, %p, %p, %p)",
330 fpath, (
void * ) (
unsigned long ) st_mode, rules_p,
331 (
void * ) (
long ) ruleaction, (
void * ) (
long ) rule_pp
336 mode_t ftype = st_mode & S_IFMT;
338 debug ( 3,
"Rules (p == %p):", rules_p );
342 debug ( 3,
"\t%i\t%i\t%p/%p", i, rules_p[i].objtype, (
void * ) (
long ) rules_p[i].perm, (
void * ) (
long ) rules_p[i].mask );
344 }
while ( rules_p[i].mask !=
RA_NONE );
349 if ( rule_pp != NULL )
350 if ( *rule_pp != NULL ) {
351 debug ( 3,
"Previous position is set." );
356 rule_p = ++ ( *rule_pp );
360 debug ( 3,
"Starting from position %i", i );
363 debug ( 3,
"%i -> %p/%p: type compare: %p, %p -> %i",
365 (
void * ) (
long ) rule_p->
perm, (
void * ) (
long ) rule_p->
mask,
366 (
void * ) (
unsigned long ) ftype, (
void * ) (
unsigned long ) rule_p->
objtype,
367 (
unsigned char ) ! ( rule_p->
objtype && ( rule_p->
objtype != ftype ) )
370 if ( ! ( rule_p->
mask & ruleaction ) ) {
371 debug ( 3,
"action-mask mismatch. Skipping." );
378 debug ( 3,
"objtype mismatch. Skipping." );
384 if ( !regexec ( &rule_p->
expr, fpath, 0, NULL, 0 ) )
387 debug ( 3,
"doesn't match regex. Skipping." );
392 debug ( 2,
"matched to rule #%u for \"%s\":\t%p/%p (queried: %p).", rule_p->
mask ==
RA_NONE ? -1 : i, fpath,
393 (
void * ) (
long ) rule_p->
perm, (
void * ) (
long ) rule_p->
mask,
394 (
void * ) (
long ) ruleaction
397 if ( rule_pp != NULL )
408 debug ( 3,
"rules_getperm(\"%s\", %p, %p (#%u), %p)",
409 fpath, (
void * ) (
long ) st_mode, rules_p, rules_p->
num, (
void * ) (
long ) ruleactions );
411 while ( ( gotpermto & ruleactions ) != ruleactions ) {
415 resultperm |= rule_p->
perm & ( gotpermto ^
RA_ALL );
419 resultperm |= rule_p->
perm & ( ( gotpermto ^ rule_p->
mask ) &rule_p->
mask );
420 gotpermto |= rule_p->
mask;
423 debug ( 3,
"rules_getperm(\"%s\", %p, rules_p, %p): result perm is %p",
424 fpath, (
void * ) (
long ) st_mode, (
void * ) (
long ) ruleactions, (
void * ) (
long ) resultperm );