Implemented option -findx
This commit is contained in:
parent
19671eaf94
commit
89d563b8a2
@ -2,7 +2,7 @@
|
||||
.\" First parameter, NAME, should be all caps
|
||||
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
|
||||
.\" other parameters are allowed: see man(7), man(1)
|
||||
.TH XORRISO 1 "December 21, 2007"
|
||||
.TH XORRISO 1 "December 22, 2007"
|
||||
.\" Please adjust this date whenever revising the manpage.
|
||||
.\"
|
||||
.\" Some roff macros, for reference:
|
||||
@ -668,8 +668,8 @@ SORRY event occured.
|
||||
.TP
|
||||
\fB\-follow\fR occasion[:occasion[...]]
|
||||
Enable or disable resolution of symbolic links and mountpoints under
|
||||
disk_paths. This applies to actions -add, -du*x, -ls*x and to -disk_pattern
|
||||
expansion.
|
||||
disk_paths. This applies to actions -add, -du*x, -ls*x, -findx,
|
||||
and to -disk_pattern expansion.
|
||||
.br
|
||||
There are two kinds of follow decisison to be made:
|
||||
.br
|
||||
@ -688,8 +688,9 @@ Less general than above occasions:
|
||||
.br
|
||||
"param" is link hopping for parameter words (after eventual pattern expansion).
|
||||
If enabled then -ls*x will show the link targets rather than the links
|
||||
themselves. -du*x and -add will process the link targets but not follow links
|
||||
in an eventual directory tree below the targets (unless "link" is enabled).
|
||||
themselves. -du*x, -findx, and -add will process the link targets but not
|
||||
follow links in an eventual directory tree below the targets (unless "link"
|
||||
is enabled).
|
||||
.br
|
||||
Occasions can be combined in a colon separated list. All occasions
|
||||
mentioned in the list will then lead to a positive follow decision.
|
||||
@ -970,14 +971,15 @@ Similar to shell command du -sk.
|
||||
.TP
|
||||
\fB\-find\fR iso_rr_path [-name pattern]
|
||||
A very restricted substitute for shell command find in the ISO image.
|
||||
It prints the paths of matchin file objects beginning with iso_rr_path.
|
||||
It prints the paths of matching file objects at or below iso_rr_path.
|
||||
.br
|
||||
Optional -name pattern is not expanded but used for comparison with
|
||||
the particular file names of the eventual directory tree underneath
|
||||
iso_rr_path. If no -name pattern is given, then any file name matches.
|
||||
.TP
|
||||
> \fB\-findx\fR pattern
|
||||
Like -find but operating on loacl filesystem and not on ISO image.
|
||||
\fB\-findx\fR disk_path [-name pattern]
|
||||
Like -find but operating on local filesystem and not on the ISO image.
|
||||
This action is subject to the settings of -follow.
|
||||
.TP
|
||||
.B Scripting, dialog and program control features:
|
||||
.TP
|
||||
|
@ -3738,9 +3738,10 @@ int Xorriso_status(struct XorrisO *xorriso, char *filter, FILE *fp, int flag)
|
||||
&& xorriso->do_follow_mount && (!xorriso->do_follow_links)
|
||||
&& xorriso->follow_link_limit==100);
|
||||
mode[0]= 0;
|
||||
if(xorriso->do_follow_pattern)
|
||||
if(xorriso->do_follow_pattern &&
|
||||
!(xorriso->do_follow_links && xorriso->do_follow_mount))
|
||||
strcat(mode,":pattern");
|
||||
if(xorriso->do_follow_param)
|
||||
if(xorriso->do_follow_param && !(xorriso->do_follow_links))
|
||||
strcat(mode,":param");
|
||||
if(xorriso->do_follow_links)
|
||||
strcat(mode,":link");
|
||||
@ -3963,11 +3964,16 @@ int Xorriso_check_for_root_pattern(struct XorrisO *xorriso,
|
||||
|
||||
|
||||
/* @param flag bit0= prepend wd only if name does not begin by '/'
|
||||
bit1= normalize image path
|
||||
bit2= prepend wd (automatically done if wd[0]!=0)
|
||||
bit3= (with bit1) this is an address in the disk world
|
||||
*/
|
||||
int Xorriso_make_abs_adr(struct XorrisO *xorriso, char *wd, char *name,
|
||||
char adr[], int flag)
|
||||
{
|
||||
char norm_adr[SfileadrL];
|
||||
int ret;
|
||||
|
||||
if((wd[0]!=0 || (flag&4)) && !((flag&1) && name[0]=='/')) {
|
||||
if(strlen(wd)+1>=SfileadrL)
|
||||
goto much_too_long;
|
||||
@ -3982,6 +3988,13 @@ much_too_long:;
|
||||
goto much_too_long;
|
||||
strcpy(adr, name);
|
||||
}
|
||||
if(flag&2) {
|
||||
ret= Xorriso_normalize_img_path(xorriso, "", adr, norm_adr,
|
||||
1|2|((flag&8)>>1));
|
||||
if(ret<=0)
|
||||
return(ret);
|
||||
strcpy(adr, norm_adr);
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
|
||||
@ -4714,6 +4727,7 @@ int Xorriso_check_temp_mem_limit(struct XorrisO *xorriso, off_t mem, int flag)
|
||||
|
||||
|
||||
/* @param flag bit0= for Xorriso_msgs_submit: use pager
|
||||
bit1= do not issue warnings
|
||||
*/
|
||||
int Xorriso_hop_link(struct XorrisO *xorriso, char *link_path,
|
||||
struct LinkiteM **link_stack, struct stat *stbuf, int flag)
|
||||
@ -4727,7 +4741,8 @@ int Xorriso_hop_link(struct XorrisO *xorriso, char *link_path,
|
||||
sprintf(xorriso->info_text,
|
||||
"Too many symbolic links in single tree branch at : %s",
|
||||
Text_shellsafe(link_path, sfe, 0));
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", flag&1);
|
||||
if(!(flag&2))
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0,"WARNING",flag&1);
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
@ -4739,7 +4754,8 @@ int Xorriso_hop_link(struct XorrisO *xorriso, char *link_path,
|
||||
sprintf(xorriso->info_text,
|
||||
"Detected symbolic link loop around : %s",
|
||||
Text_shellsafe(link_path, sfe, 0));
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", flag&1);
|
||||
if(!(flag&2))
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", flag&1);
|
||||
return(0);
|
||||
}
|
||||
ret= Linkitem_new(&litm, link_path, stbuf->st_dev, stbuf->st_ino,
|
||||
@ -5267,6 +5283,117 @@ int Xorriso_lsx_filev(struct XorrisO *xorriso, char *wd,
|
||||
}
|
||||
|
||||
|
||||
/* @param flag bit0=recursion
|
||||
*/
|
||||
int Xorriso_findx(struct XorrisO *xorriso, struct FindjoB *job,
|
||||
char *abs_dir_parm, char *dir_path,
|
||||
struct stat *dir_stbuf, int depth,
|
||||
struct LinkiteM *link_stack, int flag)
|
||||
{
|
||||
int ret,is_link, no_dive;
|
||||
struct DirseQ *dirseq= NULL;
|
||||
struct stat stbuf;
|
||||
char name[SfileadrL], path[SfileadrL], sfe[5*SfileadrL], *namept;
|
||||
char abs_dir_path_data[SfileadrL], abs_path[SfileadrL], *abs_dir_path;
|
||||
struct LinkiteM *own_link_stack;
|
||||
|
||||
own_link_stack= link_stack;
|
||||
abs_dir_path= abs_dir_parm;
|
||||
if(abs_dir_path[0]==0) {
|
||||
ret= Xorriso_make_abs_adr(xorriso, xorriso->wdx, dir_path,
|
||||
abs_dir_path_data, 1|2|8);
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
abs_dir_path= abs_dir_path_data;
|
||||
ret= lstat(abs_dir_path, dir_stbuf);
|
||||
if(ret==-1)
|
||||
{ret= 0; goto ex;}
|
||||
if(S_ISLNK(dir_stbuf->st_mode) &&
|
||||
(xorriso->do_follow_links || (xorriso->do_follow_param && !(flag&1))))
|
||||
if(stat(abs_dir_path, &stbuf)!=-1)
|
||||
if(dir_stbuf->st_dev == stbuf.st_dev ||
|
||||
(xorriso->do_follow_mount || (xorriso->do_follow_param && !(flag&1))))
|
||||
memcpy(dir_stbuf, &stbuf, sizeof(struct stat));
|
||||
|
||||
namept= strrchr(dir_path, '/');
|
||||
if(namept==NULL)
|
||||
namept= dir_path;
|
||||
else
|
||||
namept++;
|
||||
ret= Findjob_test(job, namept, NULL, dir_stbuf, depth, 0);
|
||||
if(ret<0)
|
||||
goto ex;
|
||||
if(ret>0) {
|
||||
sprintf(xorriso->result_line, "%s\n", Text_shellsafe(dir_path, sfe, 0));
|
||||
Xorriso_result(xorriso, 0);
|
||||
}
|
||||
}
|
||||
if(!S_ISDIR(dir_stbuf->st_mode))
|
||||
{ret= 2; goto ex;}
|
||||
|
||||
ret= Dirseq_new(&dirseq, abs_dir_path, 1);
|
||||
if(ret<0) {
|
||||
sprintf(xorriso->info_text, "Cannot obtain disk directory iterator");
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
||||
{ret= -1; goto ex;}
|
||||
}
|
||||
if(ret==0)
|
||||
{ret= 2; goto ex;}
|
||||
|
||||
while(!xorriso->request_to_abort) {
|
||||
Linkitem_reset_stack(&own_link_stack, link_stack, 0);
|
||||
ret= Dirseq_next_adr(dirseq,name,0);
|
||||
if(ret==0)
|
||||
break;
|
||||
if(ret<0) {
|
||||
sprintf(xorriso->info_text,"Failed to obtain next directory entry");
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
||||
{ret= -1; goto ex;}
|
||||
}
|
||||
ret= Xorriso_make_abs_adr(xorriso, abs_dir_path, name, abs_path, 1);
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
ret= Xorriso_make_abs_adr(xorriso, dir_path, name, path, 4);
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
ret= lstat(abs_path, &stbuf);
|
||||
if(ret==-1)
|
||||
continue;
|
||||
no_dive= 0;
|
||||
|
||||
is_link= S_ISLNK(stbuf.st_mode);
|
||||
if(is_link && xorriso->do_follow_links) {
|
||||
ret= Xorriso_hop_link(xorriso, abs_path, &own_link_stack, &stbuf, 2);
|
||||
if(ret<0)
|
||||
{ret= -1; goto ex;}
|
||||
if(ret!=1)
|
||||
no_dive= 1;
|
||||
}
|
||||
ret= Findjob_test(job, name, dir_stbuf, &stbuf, depth, 0);
|
||||
if(ret<0)
|
||||
goto ex;
|
||||
if(ret>0) {
|
||||
sprintf(xorriso->result_line, "%s\n", Text_shellsafe(path, sfe, 0));
|
||||
Xorriso_result(xorriso, 0);
|
||||
}
|
||||
if(!S_ISDIR(stbuf.st_mode))
|
||||
no_dive= 1;
|
||||
if(dir_stbuf->st_dev != stbuf.st_dev && !xorriso->do_follow_mount)
|
||||
no_dive= 1;
|
||||
if(!no_dive) {
|
||||
ret= Xorriso_findx(xorriso, job, abs_path, path, &stbuf, depth+1,
|
||||
own_link_stack, flag|1);
|
||||
if(ret<0)
|
||||
goto ex;
|
||||
}
|
||||
}
|
||||
|
||||
ret= 1;
|
||||
ex:;
|
||||
Dirseq_destroy(&dirseq, 0);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/* ---------------------------- Options API ------------------------ */
|
||||
|
||||
|
||||
@ -5588,7 +5715,7 @@ int Xorriso_option_cdx(struct XorrisO *xorriso, char *disk_path, int flag)
|
||||
Xorriso_option_pwdx(xorriso, 0);
|
||||
return(1);
|
||||
} else if(disk_path[0]!='/') {
|
||||
strcpy(path, xorriso->wdi);
|
||||
strcpy(path, xorriso->wdx);
|
||||
if(Sfile_add_to_path(path,disk_path,0)<=0)
|
||||
return(-1);
|
||||
} else {
|
||||
@ -6140,8 +6267,10 @@ sorry_ex:
|
||||
}
|
||||
|
||||
|
||||
/* Option -find alias -findi */
|
||||
int Xorriso_option_findi(struct XorrisO *xorriso, int argc, char **argv,
|
||||
/* Option -find alias -findi, and -findx */
|
||||
/* @param flag bit0= -findx rather than -findi
|
||||
*/
|
||||
int Xorriso_option_find(struct XorrisO *xorriso, int argc, char **argv,
|
||||
int *idx, int flag)
|
||||
{
|
||||
int ret, i, end_idx;
|
||||
@ -6150,8 +6279,8 @@ int Xorriso_option_findi(struct XorrisO *xorriso, int argc, char **argv,
|
||||
struct stat dir_stbuf;
|
||||
|
||||
end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 1);
|
||||
start_path= xorriso->wdi;
|
||||
if(end_idx > *idx)
|
||||
start_path= ".";
|
||||
if(end_idx > *idx && start_path[0]!=0)
|
||||
start_path= argv[*idx];
|
||||
ret= Findjob_new(&job, start_path, 0);
|
||||
if(ret<=0) {
|
||||
@ -6177,7 +6306,10 @@ sorry_ex:;
|
||||
{ret= 0; goto ex;}
|
||||
}
|
||||
}
|
||||
ret= Xorriso_findi(xorriso, job, NULL, start_path, &dir_stbuf, 0, 0);
|
||||
if(flag&1)
|
||||
ret= Xorriso_findx(xorriso, job, "", start_path, &dir_stbuf, 0, NULL, 0);
|
||||
else
|
||||
ret= Xorriso_findi(xorriso, job, NULL, start_path, &dir_stbuf, 0, 0);
|
||||
ex:;
|
||||
Findjob_destroy(&job, 0);
|
||||
(*idx)= end_idx;
|
||||
@ -6185,21 +6317,6 @@ ex:;
|
||||
}
|
||||
|
||||
|
||||
/* Option -findx */
|
||||
int Xorriso_option_findx(struct XorrisO *xorriso, char *pattern, int flag)
|
||||
{
|
||||
char sfe[5*SfileadrL];
|
||||
|
||||
fprintf(stderr, ">>> XORRISO : filter by pattern %s\n", pattern);
|
||||
/* >>> prepare regex */
|
||||
|
||||
fprintf(stderr, ">>> XORRISO : traverse disk tree beginning at %s\n",
|
||||
Text_shellsafe(xorriso->wdx, sfe, 0));
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
/* Option -fs */
|
||||
int Xorriso_option_fs(struct XorrisO *xorriso, char *size, int flag)
|
||||
{
|
||||
@ -6405,8 +6522,7 @@ int Xorriso_option_help(struct XorrisO *xorriso, int flag)
|
||||
" -find iso_r_path [-name pattern] lists files below the current working",
|
||||
" directory in the ISO image. If -name pattern is given",
|
||||
" then only files with matching leaf names are given out.",
|
||||
"> -findx pattern lists matching files below current working directory in",
|
||||
" the local filesystem.",
|
||||
" -findx disk_path [-name pattern] like -find but in local filesystem.",
|
||||
"",
|
||||
"General options:",
|
||||
" -help Print this text",
|
||||
@ -7621,11 +7737,10 @@ next_command:;
|
||||
ret= Xorriso_option_follow(xorriso, arg1, 0);
|
||||
|
||||
} else if(strcmp(cmd,"find")==0 || strcmp(cmd,"findi")==0) {
|
||||
ret= Xorriso_option_findi(xorriso, argc, argv, idx, 0);
|
||||
ret= Xorriso_option_find(xorriso, argc, argv, idx, 0);
|
||||
|
||||
} else if(strcmp(cmd,"findx")==0) {
|
||||
(*idx)++;
|
||||
ret= Xorriso_option_findx(xorriso, arg1, 0);
|
||||
ret= Xorriso_option_find(xorriso, argc, argv, idx, 1);
|
||||
|
||||
} else if(strcmp(cmd,"format")==0) {
|
||||
(*idx)++;
|
||||
|
@ -204,13 +204,12 @@ int Xorriso_option_iso_rr_pattern(struct XorrisO *xorriso, char *mode,
|
||||
/* Option -follow */
|
||||
int Xorriso_option_follow(struct XorrisO *xorriso, char *mode, int flag);
|
||||
|
||||
/* Option -find alias -findi */
|
||||
int Xorriso_option_findi(struct XorrisO *xorriso, int argc, char **argv,
|
||||
/* Option -find alias -findi, and -findx */
|
||||
/* @param flag bit0= -findx rather than -findi
|
||||
*/
|
||||
int Xorriso_option_find(struct XorrisO *xorriso, int argc, char **argv,
|
||||
int *idx, int flag);
|
||||
|
||||
/* Option -findx */
|
||||
int Xorriso_option_findx(struct XorrisO *xorriso, char *pattern, int flag);
|
||||
|
||||
/* Option -fs */
|
||||
int Xorriso_option_fs(struct XorrisO *xorriso, char *size, int flag);
|
||||
|
||||
|
@ -1 +1 @@
|
||||
#define Xorriso_timestamP "2007.12.21.132017"
|
||||
#define Xorriso_timestamP "2007.12.22.143803"
|
||||
|
@ -2731,7 +2731,7 @@ int Xorriso_findi(struct XorrisO *xorriso, struct FindjoB *job,
|
||||
ret= Xorriso_get_volume(xorriso, &volume, 0);
|
||||
if(ret<=0)
|
||||
{ret= -1; goto ex;}
|
||||
ret= Xorriso_make_abs_adr(xorriso, xorriso->wdi, dir_path, path, 1);
|
||||
ret= Xorriso_make_abs_adr(xorriso, xorriso->wdi, dir_path, path, 1|2|4);
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
dir_node= (struct iso_tree_node_dir *)
|
||||
@ -2740,7 +2740,7 @@ int Xorriso_findi(struct XorrisO *xorriso, struct FindjoB *job,
|
||||
{ret= 0; goto ex;}
|
||||
ret= Xorriso_fake_stbuf(xorriso, "", dir_stbuf,
|
||||
(struct iso_tree_node **) &dir_node, 1);
|
||||
if(ret<0)
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
|
||||
name= strrchr(dir_path, '/');
|
||||
|
Loading…
Reference in New Issue
Block a user