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 );
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 );
289l_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 );
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 );
ruleaction_t rules_search_getperm(const char *fpath, mode_t st_mode, rule_t *rules_p, const ruleaction_t ruleaction, rule_t **rule_pp)
Checks file path by rules' expressions (parsed from file)