Working towards exclusion of user defined absolute paths and leaf patterns

This commit is contained in:
Thomas Schmitt 2008-05-03 22:32:51 +00:00
parent 1576983e17
commit 28d68a79a5
4 changed files with 82 additions and 27 deletions

View File

@ -2680,19 +2680,29 @@ int Exclusions_add_not_leafs(struct ExclusionS *o, char *not_leafs_descr,
} }
/* @return 0=no match , 1=not_paths , 2=not_leafs, <0=error /* @param flag bit0= whole subtree is banned with -not_paths
@return 0=no match , 1=not_paths , 2=not_leafs, <0=error
*/ */
int Exclusions_match(struct ExclusionS *o, char *abs_path, int flag) int Exclusions_match(struct ExclusionS *o, char *abs_path, int flag)
{ {
struct LstrinG *s; struct LstrinG *s;
char leaf[SfileadrL], *leaf_pt; char leaf[SfileadrL], *leaf_pt;
regmatch_t match[1]; regmatch_t match[1];
int ret, was_non_slash; int ret, was_non_slash, l;
/* test abs_paths */ /* test abs_paths */
for(s= o->not_paths; s!=NULL; s= s->next) if(flag&1) {
if(strcmp(abs_path, s->text)==0) for(s= o->not_paths; s!=NULL; s= s->next) {
return(1); l= strlen(s->text);
if(strncmp(abs_path, s->text, l)==0)
if(abs_path[l]=='/' || abs_path[l]==0)
return(1);
}
} else {
for(s= o->not_paths; s!=NULL; s= s->next)
if(strcmp(abs_path, s->text)==0)
return(1);
}
/* determine leafname */ /* determine leafname */
was_non_slash= 0; was_non_slash= 0;
@ -3962,10 +3972,11 @@ int Xorriso_status(struct XorrisO *xorriso, char *filter, FILE *fp, int flag)
} }
is_default= (xorriso->disk_excl_mode==1); is_default= (xorriso->disk_excl_mode==1);
sprintf(line, "-not_mgt %s:%s:%s\n", sprintf(line, "-not_mgt %s:%s:%s:%s\n",
(xorriso->disk_excl_mode&1 ? "on" : "off"), (xorriso->disk_excl_mode&1 ? "on" : "off"),
(xorriso->disk_excl_mode&2 ? "param_on" : "param_off"), (xorriso->disk_excl_mode&2 ? "param_on" : "param_off"),
(xorriso->disk_excl_mode&4 ? "subtree_on" : "subtree_off")); (xorriso->disk_excl_mode&4 ? "subtree_on" : "subtree_off"),
(xorriso->disk_excl_mode&8 ? "ignore_on" : "ignore_off"));
if(!(is_default && no_defaults)) if(!(is_default && no_defaults))
Xorriso_status_result(xorriso,filter,fp,flag&2); Xorriso_status_result(xorriso,filter,fp,flag&2);
@ -4429,6 +4440,7 @@ cannot_address:;
bit1= compare ctime bit1= compare ctime
bit2= check only existence of both file objects bit2= check only existence of both file objects
count one or both missing as "difference" count one or both missing as "difference"
bit27= for Xorriso_path_is_excluded(): bit0
bit28= examine eventual disk_path link target rather than link bit28= examine eventual disk_path link target rather than link
bit29= do not issue pacifier messages bit29= do not issue pacifier messages
bit30= omit adr_common_tail in report messages bit30= omit adr_common_tail in report messages
@ -4453,19 +4465,37 @@ int Xorriso_compare_2_files(struct XorrisO *xorriso, char *disk_adr,
*result= 0; *result= 0;
respt= xorriso->result_line; respt= xorriso->result_line;
if(flag&(1<<28))
ret= stat(disk_adr, &s1); if(!(xorriso->disk_excl_mode&8)) {
else ret= Xorriso_path_is_excluded(xorriso, disk_adr, 2 | !!(flag&(1<<27)));
ret= lstat(disk_adr, &s1); if(ret>0) {
if(ret==-1) { sprintf(respt , "? %s (DISK) : exluded by %s\n",
sprintf(respt , "? %s (DISK) : cannot lstat() : %s\n", Text_shellsafe(disk_adr, sfe, 0),
Text_shellsafe(disk_adr, sfe, 0), strerror(errno)); (ret==1 ? "-not_paths" : "-not_leaf"));
if(!(flag&(1<<31))) if(!(flag&(1<<31)))
Xorriso_result(xorriso,0); Xorriso_result(xorriso,0);
missing= 1; missing= 1;
(*result)|= 1; (*result)|= 1;
}
} }
strcpy(a, Ftypetxt(s1.st_mode, 1)); if(!missing) {
if(flag&(1<<28))
ret= stat(disk_adr, &s1);
else
ret= lstat(disk_adr, &s1);
if(ret==-1) {
sprintf(respt , "? %s (DISK) : cannot lstat() : %s\n",
Text_shellsafe(disk_adr, sfe, 0), strerror(errno));
if(!(flag&(1<<31)))
Xorriso_result(xorriso,0);
missing= 1;
(*result)|= 1;
}
}
if(missing)
strcpy(a, "?");
else
strcpy(a, Ftypetxt(s1.st_mode, 1));
strcat(a, " "); strcat(a, " ");
if(adr_common_tail[0]) if(adr_common_tail[0])
strcat(a, Text_shellsafe(adr_common_tail, sfe, 0)); strcat(a, Text_shellsafe(adr_common_tail, sfe, 0));
@ -4664,7 +4694,10 @@ int Xorriso_find_compare(struct XorrisO *xorriso, void *boss_iter,
return(ret); return(ret);
/* compare exclusions against disk_path resp. leaf name */ /* compare exclusions against disk_path resp. leaf name */
ret= Xorriso_path_is_excluded(xorriso, disk_path, !(flag&2)); if(xorriso->disk_excl_mode&8)
ret= Xorriso_path_is_excluded(xorriso, disk_path, !(flag&2));
else
ret= 0;
if(ret<0) if(ret<0)
return(ret); return(ret);
if(ret>0) if(ret>0)
@ -4673,7 +4706,7 @@ int Xorriso_find_compare(struct XorrisO *xorriso, void *boss_iter,
follow_links= (xorriso->do_follow_links || follow_links= (xorriso->do_follow_links ||
(xorriso->do_follow_param && !(flag&2))) <<28; (xorriso->do_follow_param && !(flag&2))) <<28;
ret= Xorriso_compare_2_files(xorriso, disk_path, iso_path, adrc, &result, ret= Xorriso_compare_2_files(xorriso, disk_path, iso_path, adrc, &result,
2|follow_links|((!(flag&1))<<29)|((flag&1)<<31)); 2 | follow_links | ((!(flag&2))<<27) | ((!(flag&1))<<29) | ((flag&1)<<31));
if(ret<xorriso->find_compare_result) if(ret<xorriso->find_compare_result)
xorriso->find_compare_result= ret; xorriso->find_compare_result= ret;
if(flag&1) { if(flag&1) {
@ -7470,7 +7503,8 @@ int Xorriso_path_is_excluded(struct XorrisO *xorriso, char *path, int flag)
return(0); return(0);
if((flag&1) && !(xorriso->disk_excl_mode&2)) /* params are exempted */ if((flag&1) && !(xorriso->disk_excl_mode&2)) /* params are exempted */
return(0); return(0);
ret= Exclusions_match(xorriso->disk_exclusions, path, 0); ret= Exclusions_match(xorriso->disk_exclusions, path,
!!(xorriso->disk_excl_mode&4));
if(ret<0) { if(ret<0) {
sprintf(xorriso->info_text, sprintf(xorriso->info_text,
"Error during disk file exclusion decision"); "Error during disk file exclusion decision");
@ -8203,7 +8237,10 @@ int Xorriso_option_compare(struct XorrisO *xorriso, char *disk_path,
if(ipth[0]==0) if(ipth[0]==0)
ipth= disk_path; ipth= disk_path;
ret= Xorriso_path_is_excluded(xorriso, disk_path, 1); if(xorriso->disk_excl_mode&8)
ret= Xorriso_path_is_excluded(xorriso, disk_path, 1);
else
ret= 0;
if(ret!=0) if(ret!=0)
goto report_outcome; goto report_outcome;
if(!(flag&2)) { if(!(flag&2)) {
@ -9082,7 +9119,7 @@ int Xorriso_option_help(struct XorrisO *xorriso, int flag)
" iso_rr_path a matching copy of disk_path.", " iso_rr_path a matching copy of disk_path.",
" -update_r disk_path iso_rr_path", " -update_r disk_path iso_rr_path",
" Like -update but affecting all files below directories.", " Like -update but affecting all files below directories.",
" -cpr disk_path [...] iso_rr_path", " -cpr disk_path [***] iso_rr_path",
" Insert the given files or directory trees from filesystem", " Insert the given files or directory trees from filesystem",
" into the ISO image.", " into the ISO image.",
" -cut_out disk_path byte_offset byte_count iso_rr_path", " -cut_out disk_path byte_offset byte_count iso_rr_path",
@ -9131,6 +9168,12 @@ int Xorriso_option_help(struct XorrisO *xorriso, int flag)
" Delete empty directories.", " Delete empty directories.",
" -- Mark end of particular action argument list.", " -- Mark end of particular action argument list.",
"", "",
" -not_paths disk_path [***]",
" Add the given paths to the list of excluded absolute paths.",
" -not_leaf pattern",
" Add the given pattern to the list of leafname exclusions.",
" -not_mgt \"reset\"|\"on\"|\"off\"|\"param_on\"|\"subtree_on\"|\"ignore_on\"",
" Control effect of exclusion lists.",
" -follow \"on\"|\"pattern:param:link:mount:limit=#\"|\"default\"|\"off\"", " -follow \"on\"|\"pattern:param:link:mount:limit=#\"|\"default\"|\"off\"",
" Follow symbolic links and mount points within disk_path.", " Follow symbolic links and mount points within disk_path.",
" -overwrite \"on\"|\"nondir\"|\"off\"", " -overwrite \"on\"|\"nondir\"|\"off\"",
@ -9756,6 +9799,10 @@ int Xorriso_option_not_mgt(struct XorrisO *xorriso, char *setting, int flag)
xorriso->disk_excl_mode|= 4; xorriso->disk_excl_mode|= 4;
} else if(strcmp(what, "subtree_off")==0) { } else if(strcmp(what, "subtree_off")==0) {
xorriso->disk_excl_mode&= ~4; xorriso->disk_excl_mode&= ~4;
} else if(strcmp(what, "ignore_on")==0) {
xorriso->disk_excl_mode|= 8;
} else if(strcmp(what, "ignore_off")==0) {
xorriso->disk_excl_mode&= ~8;
} else { } else {
sprintf(xorriso->info_text, "-not_mgt: unknown setting '%s'", what); sprintf(xorriso->info_text, "-not_mgt: unknown setting '%s'", what);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
@ -10573,7 +10620,10 @@ int Xorriso_option_update(struct XorrisO *xorriso, char *disk_path,
Text_shellsafe(ipth, sfe, 0)); Text_shellsafe(ipth, sfe, 0));
Xorriso_info(xorriso,0); Xorriso_info(xorriso,0);
} }
ret= Xorriso_path_is_excluded(xorriso, disk_path, 1); if(xorriso->disk_excl_mode&8)
ret= Xorriso_path_is_excluded(xorriso, disk_path, 1);
else
ret= 0;
if(ret!=0) if(ret!=0)
goto report_outcome; goto report_outcome;
if(flag&8) { if(flag&8) {

View File

@ -169,7 +169,9 @@ struct XorrisO { /* the global context of xorriso */
struct ExclusionS *disk_exclusions; struct ExclusionS *disk_exclusions;
int disk_excl_mode; /* bit0= on (else off) int disk_excl_mode; /* bit0= on (else off)
bit1= parameter too (else rekursion only) bit1= parameter too (else rekursion only)
>>> bit2= whole subtree banned (else only exact path) bit2= whole subtree banned (else only exact path)
bit3= when comparing ignore excluded files rather
than to treat them as truely missing on disk
*/ */
int use_stdin; /* use raw stdin even if readline support is compiled */ int use_stdin; /* use raw stdin even if readline support is compiled */

View File

@ -1 +1 @@
#define Xorriso_timestamP "2008.05.03.151106" #define Xorriso_timestamP "2008.05.03.223204"

View File

@ -2126,6 +2126,9 @@ int Xorriso_cut_out(struct XorrisO *xorriso, char *disk_path,
2|4); 2|4);
if(ret<=0) if(ret<=0)
return(ret); return(ret);
ret= Xorriso_path_is_excluded(xorriso, disk_path, !(flag&1));
if(ret!=0)
return(0);
if(lstat(eff_source, &stbuf)==-1) { if(lstat(eff_source, &stbuf)==-1) {
Xorriso_msgs_submit(xorriso, 0, eff_source, 0, "ERRFILE", 0); Xorriso_msgs_submit(xorriso, 0, eff_source, 0, "ERRFILE", 0);