New -find tests -maxdepth and -mindepth

This commit is contained in:
Thomas Schmitt 2016-11-19 18:23:10 +01:00
parent 3da2ac249f
commit 7371115b25
9 changed files with 110 additions and 44 deletions

View File

@ -1275,6 +1275,8 @@ int Xorriso_findx(struct XorrisO *xorriso, struct FindjoB *job,
char *name= NULL, *path= NULL, *sfe= NULL; char *name= NULL, *path= NULL, *sfe= NULL;
char *abs_dir_path_data= NULL, *abs_path= NULL; char *abs_dir_path_data= NULL, *abs_path= NULL;
job->depth= depth;
if(xorriso->request_to_abort) if(xorriso->request_to_abort)
{ret= 0; goto ex;} {ret= 0; goto ex;}
@ -1342,6 +1344,7 @@ int Xorriso_findx(struct XorrisO *xorriso, struct FindjoB *job,
if(ret==0) if(ret==0)
{ret= 2; goto ex;} {ret= 2; goto ex;}
job->depth++;
while(!xorriso->request_to_abort) { while(!xorriso->request_to_abort) {
Linkitem_reset_stack(&own_link_stack, link_stack, 0); Linkitem_reset_stack(&own_link_stack, link_stack, 0);
ret= Dirseq_next_adr(dirseq,name,0); ret= Dirseq_next_adr(dirseq,name,0);
@ -1403,6 +1406,7 @@ int Xorriso_findx(struct XorrisO *xorriso, struct FindjoB *job,
ret= 1; ret= 1;
ex:; ex:;
job->depth= depth;
Xorriso_free_meM(sfe); Xorriso_free_meM(sfe);
Xorriso_free_meM(name); Xorriso_free_meM(name);
Xorriso_free_meM(path); Xorriso_free_meM(path);

View File

@ -384,6 +384,7 @@ int Findjob_new(struct FindjoB **o, char *start_path, int flag)
m->errmsg[0]= 0; m->errmsg[0]= 0;
m->errn= 0; m->errn= 0;
m->match_count= 0; m->match_count= 0;
m->depth= 0;
ret= Exprnode_new(&(m->test_tree), m, NULL, "-find", (m->use_shortcuts)<<1); ret= Exprnode_new(&(m->test_tree), m, NULL, "-find", (m->use_shortcuts)<<1);
if(ret<=0) if(ret<=0)

View File

@ -53,6 +53,8 @@ struct ExprtesT {
22= -use_pattern char *arg1 ("on" [or "ls"], "off") 22= -use_pattern char *arg1 ("on" [or "ls"], "off")
23= -or_use_pattern char *arg1 ("on" [or "ls"], "off") 23= -or_use_pattern char *arg1 ("on" [or "ls"], "off")
24= -name_limit_blocker int *arg1 24= -name_limit_blocker int *arg1
25= -maxdepth int *arg1
26= -mindepth int *arg1
*/ */
int test_type; int test_type;
@ -217,6 +219,9 @@ struct FindjoB {
/* Counts the test matches */ /* Counts the test matches */
unsigned long match_count; unsigned long match_count;
/* Current depth of tree walking. Relative to start path. */
int depth;
}; };

View File

@ -2984,7 +2984,12 @@ return:
arg2= ftest->arg2; arg2= ftest->arg2;
if(node == NULL) { if(node == NULL) {
if(ftest->test_type > 2 && ftest->test_type != 4) { switch(ftest->test_type) {
case 0: case 1: case 2: case 4: case 11: case 12: case 13:
case 22: case 23: case 25: case 26:
/* Tests which need no node parameter */
break;
default:
value= 0; value= 0;
goto ex; goto ex;
} }
@ -3214,6 +3219,12 @@ return:
1 | 4); 1 | 4);
value= (ret == 0); value= (ret == 0);
break; case 25: /* -maxdepth */
value= (ftest->boss->depth <= *((int *) arg1));
break; case 26: /* -mindepth */
value= (ftest->boss->depth >= *((int *) arg1));
break; default: break; default:
/* >>> complain about unknown test type */; /* >>> complain about unknown test type */;
@ -3296,6 +3307,8 @@ int Xorriso_findi(struct XorrisO *xorriso, struct FindjoB *job,
int node_count= 0, node_idx; int node_count= 0, node_idx;
char *path= NULL, *abs_path= NULL; char *path= NULL, *abs_path= NULL;
job->depth= depth;
if(xorriso->request_to_abort) if(xorriso->request_to_abort)
{ret= 0; goto ex;} {ret= 0; goto ex;}
@ -3393,6 +3406,7 @@ int Xorriso_findi(struct XorrisO *xorriso, struct FindjoB *job,
&node, hflag); &node, hflag);
if(ret<=0) if(ret<=0)
goto ex; goto ex;
job->depth++;
while(1) { while(1) {
ret= Xorriso_findi_iter(xorriso, dir_node, &mem, &iter, ret= Xorriso_findi_iter(xorriso, dir_node, &mem, &iter,
&node_array, &node_count, &node_idx, &node, 0); &node_array, &node_count, &node_idx, &node, 0);
@ -3472,6 +3486,7 @@ int Xorriso_findi(struct XorrisO *xorriso, struct FindjoB *job,
ret= 1; ret= 1;
ex:; ex:;
job->depth= depth;
if(path!=NULL) if(path!=NULL)
free(path); free(path);
if(abs_path!=NULL) if(abs_path!=NULL)

View File

@ -1032,6 +1032,23 @@ not_enough_arguments:;
ret= Findjob_set_num_filter(job, 24, count, 0, 0); ret= Findjob_set_num_filter(job, 24, count, 0, 0);
if(ret <= 0) if(ret <= 0)
goto ex; goto ex;
} else if(strcmp(argv[i], "-maxdepth") == 0 ||
strcmp(argv[i], "-mindepth") == 0) {
if(i + 1 >= end_idx)
goto not_enough_arguments;
i++;
count= -1;
sscanf(argv[i], "%d", &count);
if(count < 0) {
sprintf(xorriso->info_text,
"-findi: wrong length with %s [>= 0]", argv[i - 1]);
goto sorry_ex;
}
ret= Findjob_set_num_filter(job,
25 + (strcmp(argv[i - 1], "-mindepth") == 0),
count, 0, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-exec")==0) { } else if(strcmp(argv[i], "-exec")==0) {
if(i+1>=end_idx) { if(i+1>=end_idx) {
not_enough_exec_arguments:; not_enough_exec_arguments:;
@ -2030,7 +2047,7 @@ int Xorriso_option_help(struct XorrisO *xorriso, int flag)
" -lba_range start count, -damaged, -has_acl, -has_xattr,", " -lba_range start count, -damaged, -has_acl, -has_xattr,",
" -has_aaip, -has_filter, -has_md5, -has_any_xattr,", " -has_aaip, -has_filter, -has_md5, -has_any_xattr,",
" -has_hfs_crtp, -has_hfs_bless, -bad_outname,", " -has_hfs_crtp, -has_hfs_bless, -bad_outname,",
" -name_limit_blocker", " -name_limit_blocker, -maxdepth, -mindepth,",
" -prune, -decision yes|no, -true, -false", " -prune, -decision yes|no, -true, -false",
" Operators: -not, -or, -and, -sub, (, -subend, ),", " Operators: -not, -or, -and, -sub, (, -subend, ),",
" -if, -then, -elseif, -else, -endif", " -if, -then, -elseif, -else, -endif",

View File

@ -9,7 +9,7 @@
.\" First parameter, NAME, should be all caps .\" First parameter, NAME, should be all caps
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
.\" other parameters are allowed: see man(7), man(1) .\" other parameters are allowed: see man(7), man(1)
.TH XORRISO 1 "Version 1.4.7, Nov 13, 2016" .TH XORRISO 1 "Version 1.4.7, Nov 19, 2016"
.\" Please adjust this date whenever revising the manpage. .\" Please adjust this date whenever revising the manpage.
.\" .\"
.\" Some roff macros, for reference: .\" Some roff macros, for reference:
@ -1868,6 +1868,14 @@ and "Xotic" which matches what is not matched by the other types.
.br .br
Only the first letter is interpreted. E.g.: \-find / \-type d Only the first letter is interpreted. E.g.: \-find / \-type d
.br .br
\fB\-maxdepth\fR number :
Matches only files which are at most at the given depth level relative to
the iso_rr_path where \-find starts. That path itself is at depth 0, its
directory children are at 1, their directory children at 2, and so on.
.br
\fB\-mindepth\fR number :
Matches only files which are at least at the given depth level.
.br
\fB\-damaged\fR : \fB\-damaged\fR :
Matches files which use data blocks marked as damaged by a previous Matches files which use data blocks marked as damaged by a previous
run of \-check_media. The damage info vanishes when a new ISO image gets run of \-check_media. The damage info vanishes when a new ISO image gets

View File

@ -1608,6 +1608,14 @@ File: xorriso.info, Node: CmdFind, Next: Filter, Prev: Manip, Up: Commands
"pipe", "file", "link", "socket", "eltorito", and "Xotic" "pipe", "file", "link", "socket", "eltorito", and "Xotic"
which matches what is not matched by the other types. which matches what is not matched by the other types.
Only the first letter is interpreted. E.g.: -find / -type d Only the first letter is interpreted. E.g.: -find / -type d
-maxdepth number :
Matches only files which are at most at the given depth level
relative to the iso_rr_path where -find starts. That path
itself is at depth 0, its directory children are at 1, their
directory children at 2, and so on.
-mindepth number :
Matches only files which are at least at the given depth
level.
-damaged : -damaged :
Matches files which use data blocks marked as damaged by a Matches files which use data blocks marked as damaged by a
previous run of -check_media. The damage info vanishes when a previous run of -check_media. The damage info vanishes when a
@ -5740,44 +5748,44 @@ Node: Insert52745
Node: SetInsert63329 Node: SetInsert63329
Node: Manip72648 Node: Manip72648
Node: CmdFind82607 Node: CmdFind82607
Node: Filter100989 Node: Filter101379
Node: Writing105611 Node: Writing106001
Node: SetWrite115767 Node: SetWrite116157
Node: Bootable140526 Node: Bootable140916
Node: Jigdo166026 Node: Jigdo166416
Node: Charset170285 Node: Charset170675
Node: Exception173614 Node: Exception174004
Node: DialogCtl179743 Node: DialogCtl180133
Node: Inquiry182345 Node: Inquiry182735
Node: Navigate191133 Node: Navigate191523
Node: Verify199428 Node: Verify199818
Node: Restore209306 Node: Restore209696
Node: Emulation217919 Node: Emulation218309
Node: Scripting228378 Node: Scripting228768
Node: Frontend236161 Node: Frontend236551
Node: Examples245787 Node: Examples246177
Node: ExDevices246965 Node: ExDevices247355
Node: ExCreate247626 Node: ExCreate248016
Node: ExDialog248926 Node: ExDialog249316
Node: ExGrowing250197 Node: ExGrowing250587
Node: ExModifying251006 Node: ExModifying251396
Node: ExBootable251516 Node: ExBootable251906
Node: ExCharset252071 Node: ExCharset252461
Node: ExPseudo252967 Node: ExPseudo253357
Node: ExCdrecord253894 Node: ExCdrecord254284
Node: ExMkisofs254214 Node: ExMkisofs254604
Node: ExGrowisofs255571 Node: ExGrowisofs255961
Node: ExException256725 Node: ExException257115
Node: ExTime257183 Node: ExTime257573
Node: ExIncBackup257641 Node: ExIncBackup258031
Node: ExRestore261667 Node: ExRestore262057
Node: ExRecovery262613 Node: ExRecovery263003
Node: Files263185 Node: Files263575
Node: Environ264519 Node: Environ264909
Node: Seealso265225 Node: Seealso265615
Node: Bugreport265942 Node: Bugreport266332
Node: Legal266533 Node: Legal266923
Node: CommandIdx267545 Node: CommandIdx267935
Node: ConceptIdx284733 Node: ConceptIdx285123
 
End Tag Table End Tag Table

View File

@ -50,7 +50,7 @@
@c man .\" First parameter, NAME, should be all caps @c man .\" First parameter, NAME, should be all caps
@c man .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection @c man .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
@c man .\" other parameters are allowed: see man(7), man(1) @c man .\" other parameters are allowed: see man(7), man(1)
@c man .TH XORRISO 1 "Version 1.4.7, Nov 13, 2016" @c man .TH XORRISO 1 "Version 1.4.7, Nov 19, 2016"
@c man .\" Please adjust this date whenever revising the manpage. @c man .\" Please adjust this date whenever revising the manpage.
@c man .\" @c man .\"
@c man .\" Some roff macros, for reference: @c man .\" Some roff macros, for reference:
@ -2258,6 +2258,14 @@ and "Xotic" which matches what is not matched by the other types.
@* @*
Only the first letter is interpreted. E.g.: -find / -type d Only the first letter is interpreted. E.g.: -find / -type d
@* @*
@item -maxdepth number :
Matches only files which are at most at the given depth level relative to
the iso_rr_path where -find starts. That path itself is at depth 0, its
directory children are at 1, their directory children at 2, and so on.
@*
@item -mindepth number :
Matches only files which are at least at the given depth level.
@*
@item -damaged : @item -damaged :
Matches files which use data blocks marked as damaged by a previous Matches files which use data blocks marked as damaged by a previous
run of -check_media. The damage info vanishes when a new ISO image gets run of -check_media. The damage info vanishes when a new ISO image gets

View File

@ -1 +1 @@
#define Xorriso_timestamP "2016.11.18.173658" #define Xorriso_timestamP "2016.11.19.172243"