Re: RFC: "-exit" option for find(1)
On Fri, Jul 16, 2004 at 12:23:41AM -0700, Alfred Perlstein wrote: > I'm up too late, this doesn't work because find returns > success whenever it successfully runs thought everything. > > Perhaps the primary change to just "-exit" which would > make find exit successfully, and if the primary is never > encountered (ie. our find logic never hits it) find would > exit with a non-zero exit status? > > Ideas? Better ideas? > > The reason I want this is to avoid extracting a tarball > over a directory that has files in it that are newer than > the tarball. > > Neither tar nor find seem to make this easy... > [ `find . -type f -newer ../src.tar.gz |head -1 |wc -l` -eq 0 ] && echo hi Cheers, -- Ruslan Ermilov [EMAIL PROTECTED] FreeBSD committer pgptKBBVmt0E5.pgp Description: PGP signature
Re: RFC: "-exit" option for find(1)
Peter Pentchev wrote: On Fri, Jul 16, 2004 at 05:28:57PM +0300, Peter Pentchev wrote: On Fri, Jul 16, 2004 at 11:58:07AM +0400, Denis Antrushin wrote: Alfred Perlstein wrote: I'm up too late, this doesn't work because find returns success whenever it successfully runs thought everything. Perhaps the primary change to just "-exit" which would make find exit successfully, and if the primary is never encountered (ie. our find logic never hits it) find would exit with a non-zero exit status? Ideas? Better ideas? The reason I want this is to avoid extracting a tarball over a directory that has files in it that are newer than the tarball. Neither tar nor find seem to make this easy... What about this: test -n "`find . -type f -newer ../src.tar.gz`" && echo hi I believe Alfred's problem with this is that it will still traverse the whole hierarchy even after a match is found. In some cases, the hierarchy may be huge, and if the match is within the first 100-200 files, well... :) I wonder if it wouldn't be a bit better to add to find(1) something like -maxmatches N, similar to Alfred's idea, but not limited to a single match? Well, I've just gone ahead and implemented it: say hello to the new -maxmatch N and -minmatch N primaries: -maxmatch n Always true; exits after printing out n matching filenames. If any -maxmatch primary is specified, it applies to the entire expression even if it would not normally be evaluated. -maxmatch 0 makes find exit immediately without performing any filesystem traversal. -minmatch n Always true; exits with a non-zero exit code if less than n matching filenames were printed out at the end of the search. If any -minmatch primary is specified, it applies to the entire expression even if it would not normally be evaluated. Thus, -maxmatch 1 would help in Alfred's case. Patch attached. I don't really like this because: a) It's global b) It is counting printed lines, while I might want to use -exec or something else c) It does not honour find(1)s [+-]n semantic How about two primaries: - -exit n, like proposed in the first post (sucess could be determined by a printed line or an -exec) - -match n, which is true when *this* primary has been matched n times so find [path] ... -match 1 -print -exit 0 will do the trick, while find [path] ... -match -10 -print will print the first 9 matches? -Oliver ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: RFC: "-exit" option for find(1)
On Fri, Jul 16, 2004 at 05:28:57PM +0300, Peter Pentchev wrote: > On Fri, Jul 16, 2004 at 11:58:07AM +0400, Denis Antrushin wrote: > > Alfred Perlstein wrote: > > >I'm up too late, this doesn't work because find returns > > >success whenever it successfully runs thought everything. > > > > > >Perhaps the primary change to just "-exit" which would > > >make find exit successfully, and if the primary is never > > >encountered (ie. our find logic never hits it) find would > > >exit with a non-zero exit status? > > > > > >Ideas? Better ideas? > > > > > >The reason I want this is to avoid extracting a tarball > > >over a directory that has files in it that are newer than > > >the tarball. > > > > > >Neither tar nor find seem to make this easy... > > What about this: > > > > test -n "`find . -type f -newer ../src.tar.gz`" && echo hi > > I believe Alfred's problem with this is that it will still traverse the > whole hierarchy even after a match is found. In some cases, the > hierarchy may be huge, and if the match is within the first 100-200 > files, well... :) > > I wonder if it wouldn't be a bit better to add to find(1) something like > -maxmatches N, similar to Alfred's idea, but not limited to a single > match? Well, I've just gone ahead and implemented it: say hello to the new -maxmatch N and -minmatch N primaries: -maxmatch n Always true; exits after printing out n matching filenames. If any -maxmatch primary is specified, it applies to the entire expression even if it would not normally be evaluated. -maxmatch 0 makes find exit immediately without performing any filesystem traversal. -minmatch n Always true; exits with a non-zero exit code if less than n matching filenames were printed out at the end of the search. If any -minmatch primary is specified, it applies to the entire expression even if it would not normally be evaluated. Thus, -maxmatch 1 would help in Alfred's case. Patch attached. G'luck, Peter -- Peter Pentchev [EMAIL PROTECTED][EMAIL PROTECTED][EMAIL PROTECTED] PGP key:http://people.FreeBSD.org/~roam/roam.key.asc Key fingerprint FDBA FD79 C26F 3C51 C95E DF9E ED18 B68D 1619 4553 I had to translate this sentence into English because I could not read the original Sanskrit. Index: src/usr.bin/find/extern.h === RCS file: /home/ncvs/src/usr.bin/find/extern.h,v retrieving revision 1.21 diff -u -r1.21 extern.h --- src/usr.bin/find/extern.h 28 May 2004 17:17:15 - 1.21 +++ src/usr.bin/find/extern.h 16 Jul 2004 15:09:49 - @@ -68,6 +68,7 @@ creat_fc_links; creat_fc_ls; creat_fc_mXXdepth; +creat_fc_mXXmatch; creat_fc_name; creat_fc_newer; creat_fc_nogroup; @@ -116,6 +117,7 @@ extern int ftsoptions, isdeprecated, isdepth, isoutput, issort, isxargs; extern int mindepth, maxdepth; +extern int minmatch, maxmatch, match; extern int regexp_flags; extern time_t now; extern int dotfd; Index: src/usr.bin/find/find.1 === RCS file: /home/ncvs/src/usr.bin/find/find.1,v retrieving revision 1.66 diff -u -r1.66 find.1 --- src/usr.bin/find/find.1 7 Jul 2004 19:57:15 - 1.66 +++ src/usr.bin/find/find.1 16 Jul 2004 15:19:36 - @@ -442,6 +442,18 @@ not normally be evaluated. .Ic -maxdepth Li 0 limits the whole search to the command line arguments. +.It Ic -maxmatch Ar n +Always true; exits after printing out +.Ar n +matching filenames. +If any +.Ic -maxmatch +primary is specified, it applies to the entire expression even if it would +not normally be evaluated. +.Ic Ic -maxmatch Li 0 +makes +.Nm +exit immediately without performing any filesystem traversal. .It Ic -mindepth Ar n Always true; do not apply any tests or actions at levels less than .Ar n . @@ -451,6 +463,14 @@ not normally be evaluated. .Ic -mindepth Li 1 processes all but the command line arguments. +.It Ic -minmatch Ar n +Always true; exits with a non-zero exit code if less than +.Ar n +matching filenames were printed out at the end of the search. +If any +.Ic -minmatch +primary is specified, it applies to the entire expression even if it would +not normally be evaluated. .It Ic -mmin Ar n True if the difference between the file last modification time and the time .Nm Index: src/usr.bin/find/find.c === RCS file: /home/ncvs/src/usr.bin/find/find.c,v retrieving revision 1.17 diff -u -r1.17 find.c --- src/usr.bin/find/find.c 28 May 2004 17:17:15 - 1.17 +++ src/usr.bin/find/find.c 16 Jul 2004 15:16:10 - @@ -181,6 +181,10 @@ PLAN *p; int rval; + if (maxmatch == 0) + return (0); + + match = 0; tree = fts_open(paths, ftsoptions, (issort ? find_compare : NULL)); if (tree == NULL) err(1
Re: RFC: "-exit" option for find(1)
On Fri, Jul 16, 2004 at 11:58:07AM +0400, Denis Antrushin wrote: > Alfred Perlstein wrote: > >I'm up too late, this doesn't work because find returns > >success whenever it successfully runs thought everything. > > > >Perhaps the primary change to just "-exit" which would > >make find exit successfully, and if the primary is never > >encountered (ie. our find logic never hits it) find would > >exit with a non-zero exit status? > > > >Ideas? Better ideas? > > > >The reason I want this is to avoid extracting a tarball > >over a directory that has files in it that are newer than > >the tarball. > > > >Neither tar nor find seem to make this easy... > What about this: > > test -n "`find . -type f -newer ../src.tar.gz`" && echo hi I believe Alfred's problem with this is that it will still traverse the whole hierarchy even after a match is found. In some cases, the hierarchy may be huge, and if the match is within the first 100-200 files, well... :) I wonder if it wouldn't be a bit better to add to find(1) something like -maxmatches N, similar to Alfred's idea, but not limited to a single match? G'luck, Peter -- Peter Pentchev [EMAIL PROTECTED][EMAIL PROTECTED][EMAIL PROTECTED] PGP key:http://people.FreeBSD.org/~roam/roam.key.asc Key fingerprint FDBA FD79 C26F 3C51 C95E DF9E ED18 B68D 1619 4553 No language can express every thought unambiguously, least of all this one. pgppRQamZIJBv.pgp Description: PGP signature
Re: RFC: "-exit" option for find(1)
Alfred Perlstein wrote: I'm up too late, this doesn't work because find returns success whenever it successfully runs thought everything. Perhaps the primary change to just "-exit" which would make find exit successfully, and if the primary is never encountered (ie. our find logic never hits it) find would exit with a non-zero exit status? Ideas? Better ideas? The reason I want this is to avoid extracting a tarball over a directory that has files in it that are newer than the tarball. Neither tar nor find seem to make this easy... What about this: test -n "`find . -type f -newer ../src.tar.gz`" && echo hi :-) * Alfred Perlstein <[EMAIL PROTECTED]> [040716 00:15] wrote: This adds a primary to find(1) "-exit ", it will cause find to exit(2) with the as the exit status. Useful for finding the first instance of something: find . -type f -newer ../src.tar.gz -exit 0 && echo hi this will make find abort with a zero exit status early upon finding a file newer than ../src.tar.gz. cvs diff: Diffing . Index: extern.h === RCS file: /home/ncvs/src/usr.bin/find/extern.h,v retrieving revision 1.21 diff -u -r1.21 extern.h --- extern.h28 May 2004 17:17:15 - 1.21 +++ extern.h16 Jul 2004 07:07:50 - @@ -58,6 +58,7 @@ creat_f c_depth; creat_f c_empty; creat_f c_exec; +creat_fc_exit; creat_f c_flags; creat_f c_follow; #if !defined(__NetBSD__) @@ -90,6 +91,7 @@ exec_f f_depth; exec_f f_empty; exec_f f_exec; +exec_f f_exit; exec_f f_expr; exec_f f_flags; exec_f f_fstype; Index: find.1 === RCS file: /home/ncvs/src/usr.bin/find/find.1,v retrieving revision 1.66 diff -u -r1.66 find.1 --- find.1 7 Jul 2004 19:57:15 - 1.66 +++ find.1 16 Jul 2004 07:12:58 - @@ -372,6 +372,10 @@ .Ar flags bits match those of .Ar notflags . +.It Ic -exit Ar exitstatus +This primary will cause the find program to exit immediately with an exit +status of +.Ar exitstatus . .It Ic -fstype Ar type True if the file is contained in a file system of type .Ar type . Index: function.c === RCS file: /home/ncvs/src/usr.bin/find/function.c,v retrieving revision 1.50 diff -u -r1.50 function.c --- function.c 28 May 2004 17:17:15 - 1.50 +++ function.c 16 Jul 2004 07:07:05 - @@ -748,6 +748,25 @@ } int +f_exit(PLAN *plan, FTSENT *entry) +{ + + exit(plan->flags); +} + +PLAN * +c_exit(OPTION *option, char ***argvp) +{ + PLAN *new; + int ex; + + ex = atoi(nextarg(option, argvp)); + new = palloc(option); + new->flags = ex; + return (new); +} + +int f_flags(PLAN *plan, FTSENT *entry) { u_long flags; Index: option.c === RCS file: /home/ncvs/src/usr.bin/find/option.c,v retrieving revision 1.22 diff -u -r1.22 option.c --- option.c28 May 2004 17:17:15 - 1.22 +++ option.c16 Jul 2004 07:06:49 - @@ -76,6 +76,7 @@ { "-empty", c_empty,f_empty,0 }, { "-exec",c_exec, f_exec, 0 }, { "-execdir", c_exec, f_exec, F_EXECDIR }, + { "-exit",c_exit, f_exit, 0 }, { "-false", c_simple, f_not, 0 }, { "-flags", c_flags,f_flags,0 }, { "-follow", c_follow, f_always_true, 0 }, -- - Alfred Perlstein - Research Engineering Development Inc. - email: [EMAIL PROTECTED] cell: 408-480-4684 ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: RFC: "-exit" option for find(1)
I'm up too late, this doesn't work because find returns success whenever it successfully runs thought everything. Perhaps the primary change to just "-exit" which would make find exit successfully, and if the primary is never encountered (ie. our find logic never hits it) find would exit with a non-zero exit status? Ideas? Better ideas? The reason I want this is to avoid extracting a tarball over a directory that has files in it that are newer than the tarball. Neither tar nor find seem to make this easy... * Alfred Perlstein <[EMAIL PROTECTED]> [040716 00:15] wrote: > This adds a primary to find(1) "-exit ", it will cause > find to exit(2) with the as the exit status. > > Useful for finding the first instance of something: > > find . -type f -newer ../src.tar.gz -exit 0 && echo hi > > this will make find abort with a zero exit status early upon > finding a file newer than ../src.tar.gz. > > cvs diff: Diffing . > Index: extern.h > === > RCS file: /home/ncvs/src/usr.bin/find/extern.h,v > retrieving revision 1.21 > diff -u -r1.21 extern.h > --- extern.h 28 May 2004 17:17:15 - 1.21 > +++ extern.h 16 Jul 2004 07:07:50 - > @@ -58,6 +58,7 @@ > creat_f c_depth; > creat_f c_empty; > creat_f c_exec; > +creat_f c_exit; > creat_f c_flags; > creat_f c_follow; > #if !defined(__NetBSD__) > @@ -90,6 +91,7 @@ > exec_f f_depth; > exec_f f_empty; > exec_f f_exec; > +exec_f f_exit; > exec_f f_expr; > exec_f f_flags; > exec_f f_fstype; > Index: find.1 > === > RCS file: /home/ncvs/src/usr.bin/find/find.1,v > retrieving revision 1.66 > diff -u -r1.66 find.1 > --- find.17 Jul 2004 19:57:15 - 1.66 > +++ find.116 Jul 2004 07:12:58 - > @@ -372,6 +372,10 @@ > .Ar flags > bits match those of > .Ar notflags . > +.It Ic -exit Ar exitstatus > +This primary will cause the find program to exit immediately with an exit > +status of > +.Ar exitstatus . > .It Ic -fstype Ar type > True if the file is contained in a file system of type > .Ar type . > Index: function.c > === > RCS file: /home/ncvs/src/usr.bin/find/function.c,v > retrieving revision 1.50 > diff -u -r1.50 function.c > --- function.c28 May 2004 17:17:15 - 1.50 > +++ function.c16 Jul 2004 07:07:05 - > @@ -748,6 +748,25 @@ > } > > int > +f_exit(PLAN *plan, FTSENT *entry) > +{ > + > + exit(plan->flags); > +} > + > +PLAN * > +c_exit(OPTION *option, char ***argvp) > +{ > + PLAN *new; > + int ex; > + > + ex = atoi(nextarg(option, argvp)); > + new = palloc(option); > + new->flags = ex; > + return (new); > +} > + > +int > f_flags(PLAN *plan, FTSENT *entry) > { > u_long flags; > Index: option.c > === > RCS file: /home/ncvs/src/usr.bin/find/option.c,v > retrieving revision 1.22 > diff -u -r1.22 option.c > --- option.c 28 May 2004 17:17:15 - 1.22 > +++ option.c 16 Jul 2004 07:06:49 - > @@ -76,6 +76,7 @@ > { "-empty", c_empty,f_empty,0 }, > { "-exec", c_exec, f_exec, 0 }, > { "-execdir", c_exec, f_exec, F_EXECDIR }, > + { "-exit", c_exit, f_exit, 0 }, > { "-false", c_simple, f_not, 0 }, > { "-flags", c_flags,f_flags,0 }, > { "-follow",c_follow, f_always_true, 0 }, > -- > - Alfred Perlstein > - Research Engineering Development Inc. > - email: [EMAIL PROTECTED] cell: 408-480-4684 -- - Alfred Perlstein - Research Engineering Development Inc. - email: [EMAIL PROTECTED] cell: 408-480-4684 ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "[EMAIL PROTECTED]"
RFC: "-exit" option for find(1)
This adds a primary to find(1) "-exit ", it will cause find to exit(2) with the as the exit status. Useful for finding the first instance of something: find . -type f -newer ../src.tar.gz -exit 0 && echo hi this will make find abort with a zero exit status early upon finding a file newer than ../src.tar.gz. cvs diff: Diffing . Index: extern.h === RCS file: /home/ncvs/src/usr.bin/find/extern.h,v retrieving revision 1.21 diff -u -r1.21 extern.h --- extern.h28 May 2004 17:17:15 - 1.21 +++ extern.h16 Jul 2004 07:07:50 - @@ -58,6 +58,7 @@ creat_fc_depth; creat_fc_empty; creat_fc_exec; +creat_fc_exit; creat_fc_flags; creat_fc_follow; #if !defined(__NetBSD__) @@ -90,6 +91,7 @@ exec_f f_depth; exec_f f_empty; exec_f f_exec; +exec_f f_exit; exec_f f_expr; exec_f f_flags; exec_f f_fstype; Index: find.1 === RCS file: /home/ncvs/src/usr.bin/find/find.1,v retrieving revision 1.66 diff -u -r1.66 find.1 --- find.1 7 Jul 2004 19:57:15 - 1.66 +++ find.1 16 Jul 2004 07:12:58 - @@ -372,6 +372,10 @@ .Ar flags bits match those of .Ar notflags . +.It Ic -exit Ar exitstatus +This primary will cause the find program to exit immediately with an exit +status of +.Ar exitstatus . .It Ic -fstype Ar type True if the file is contained in a file system of type .Ar type . Index: function.c === RCS file: /home/ncvs/src/usr.bin/find/function.c,v retrieving revision 1.50 diff -u -r1.50 function.c --- function.c 28 May 2004 17:17:15 - 1.50 +++ function.c 16 Jul 2004 07:07:05 - @@ -748,6 +748,25 @@ } int +f_exit(PLAN *plan, FTSENT *entry) +{ + + exit(plan->flags); +} + +PLAN * +c_exit(OPTION *option, char ***argvp) +{ + PLAN *new; + int ex; + + ex = atoi(nextarg(option, argvp)); + new = palloc(option); + new->flags = ex; + return (new); +} + +int f_flags(PLAN *plan, FTSENT *entry) { u_long flags; Index: option.c === RCS file: /home/ncvs/src/usr.bin/find/option.c,v retrieving revision 1.22 diff -u -r1.22 option.c --- option.c28 May 2004 17:17:15 - 1.22 +++ option.c16 Jul 2004 07:06:49 - @@ -76,6 +76,7 @@ { "-empty", c_empty,f_empty,0 }, { "-exec", c_exec, f_exec, 0 }, { "-execdir", c_exec, f_exec, F_EXECDIR }, + { "-exit", c_exit, f_exit, 0 }, { "-false", c_simple, f_not, 0 }, { "-flags", c_flags,f_flags,0 }, { "-follow",c_follow, f_always_true, 0 }, -- - Alfred Perlstein - Research Engineering Development Inc. - email: [EMAIL PROTECTED] cell: 408-480-4684 ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "[EMAIL PROTECTED]"