Implemented -find test -type
This commit is contained in:
@ -2491,6 +2491,12 @@ struct FindjoB {
|
||||
regmatch_t name_match;
|
||||
#endif
|
||||
|
||||
/* b = blockdev, c = chardev, d = directory, p = fifo, f = reg , - = reg,
|
||||
s = socket, X = other , 0x0 = test inactive
|
||||
*/
|
||||
char file_type;
|
||||
|
||||
|
||||
/* 0= echo
|
||||
>>> 1= rm
|
||||
>>> 2= rm_r
|
||||
@ -2529,6 +2535,7 @@ int Findjob_new(struct FindjoB **o, char *start_path, int flag)
|
||||
return(-1);
|
||||
m->start_path= NULL;
|
||||
m->name_expr= NULL;
|
||||
m->file_type= 0;
|
||||
m->action= 0; /* print */
|
||||
m->target= NULL; /* a mere pointer, not managed memory */
|
||||
m->user= 0;
|
||||
@ -2605,6 +2612,18 @@ int Findjob_set_name_expr(struct FindjoB *o, char *name_expr, int flag)
|
||||
}
|
||||
|
||||
|
||||
int Findjob_set_file_type(struct FindjoB *o, char file_type, int flag)
|
||||
{
|
||||
static char known[]= {"bcdpf-lsX"};
|
||||
|
||||
if(file_type!=0)
|
||||
if(strchr(known, file_type)==NULL)
|
||||
return(0);
|
||||
o->file_type= file_type;
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
/* @return 0=no match , 1=match , <0 = error
|
||||
*/
|
||||
int Findjob_test(struct FindjoB *o, char *name,
|
||||
@ -2623,6 +2642,34 @@ int Findjob_test(struct FindjoB *o, char *name,
|
||||
return(0);
|
||||
}
|
||||
|
||||
if(o->file_type!=0) {
|
||||
if(S_ISBLK(stbuf->st_mode)) {
|
||||
if(o->file_type!='b')
|
||||
return(0);
|
||||
} else if(S_ISCHR(stbuf->st_mode)) {
|
||||
if(o->file_type!='c')
|
||||
return(0);
|
||||
} else if(S_ISDIR(stbuf->st_mode)) {
|
||||
if(o->file_type!='d')
|
||||
return(0);
|
||||
} else if(S_ISFIFO(stbuf->st_mode)) {
|
||||
if(o->file_type!='p')
|
||||
return(0);
|
||||
} else if(S_ISREG(stbuf->st_mode)) {
|
||||
if(o->file_type!='f' && o->file_type!='-')
|
||||
return(0);
|
||||
} else if(((stbuf->st_mode)&S_IFMT)==S_IFLNK) {
|
||||
if(o->file_type!='l')
|
||||
return(0);
|
||||
} else if(((stbuf->st_mode)&S_IFMT)==S_IFSOCK) {
|
||||
if(o->file_type!='s')
|
||||
return(0);
|
||||
} else {
|
||||
if(o->file_type!='X')
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
|
||||
/* ??? >>> more tests to come ?*/;
|
||||
|
||||
return(1);
|
||||
@ -6871,6 +6918,15 @@ not_enough_arguments:;
|
||||
Text_shellsafe(argv[i], sfe, 0));
|
||||
goto sorry_ex;
|
||||
}
|
||||
} else if(strcmp(argv[i], "-type")==0) {
|
||||
if(i+1>=end_idx)
|
||||
goto not_enough_arguments;
|
||||
i++;
|
||||
ret= Findjob_set_file_type(job, argv[i][0], 0);
|
||||
if(ret<=0) {
|
||||
sprintf(xorriso->info_text, "-find[ix]: unknown -type '%c'",argv[i][0]);
|
||||
goto sorry_ex;
|
||||
}
|
||||
} else {
|
||||
sprintf(xorriso->info_text, "-find[ix]: unknown option %s",
|
||||
Text_shellsafe(argv[i], sfe, 0));
|
||||
@ -7023,6 +7079,16 @@ int Xorriso_option_help(struct XorrisO *xorriso, int flag)
|
||||
" access time, modification time, both times.",
|
||||
" -alter_date_r type timestring iso_rr_path [***]",
|
||||
" Like -alter_date but affecting all files below directories.",
|
||||
" -find iso_rr_path [-name pattern] [-type t] [-exec action [params]]",
|
||||
" performs an action on files below the current working",
|
||||
" directory in the ISO image. If -name pattern is given",
|
||||
" then only files with matching leaf names are processed.",
|
||||
" If -type is given then only files with matching type are",
|
||||
" processed. Types: block,char,dir,pipe,file,link,socket.",
|
||||
" action may be one of: echo, chown, chown_r, chgrp, chgrp_r",
|
||||
" chmod, chmod_r, alter_date, alter_date_r, lsdl, find.",
|
||||
" params are their arguments except iso_rr_path.",
|
||||
" I.e. echo and lsdl have no params at all.",
|
||||
" -mkdir iso_rr_path [...]",
|
||||
" Create empty directories if they do not exist yet.",
|
||||
" -rmdir iso_rr_path [***]",
|
||||
@ -7102,13 +7168,6 @@ int Xorriso_option_help(struct XorrisO *xorriso, int flag)
|
||||
" -dusx pattern [***] like -dux but summing up subdirectories without",
|
||||
" listing them explicitely.",
|
||||
"",
|
||||
" -find iso_r_path [-name pattern] [-exec action [params]]",
|
||||
" performs an action on files below the current working",
|
||||
" directory in the ISO image. If -name pattern is given",
|
||||
" then only files with matching leaf names are processes.",
|
||||
" action may be one of: echo, chown, chgrp, chmod, alter_date",
|
||||
" lsdl. params are their arguments up to iso_rr_path.",
|
||||
" I.e. echo and lsdl have no params at all.",
|
||||
" -findx disk_path [-name pattern] like -find but in local filesystem.",
|
||||
" Any -exec option is ignored. Action is always echo.",
|
||||
"",
|
||||
|
Reference in New Issue
Block a user