Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 16 Jul 2004 11:58:07 +0400
From:      Denis Antrushin <DAntrushin@mail.ru>
To:        Alfred Perlstein <alfred@freebsd.org>
Cc:        hackers@freebsd.org
Subject:   Re: RFC: "-exit" option for find(1)
Message-ID:  <40F78A8F.2010502@mail.ru>
In-Reply-To: <20040716072341.GX95729@elvis.mu.org>
References:  <20040716071545.GW95729@elvis.mu.org> <20040716072341.GX95729@elvis.mu.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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 <alfred@freebsd.org> [040716 00:15] wrote:
> 
>>This adds a primary to find(1) "-exit <arg>", it will cause
>>find to exit(2) with the <arg> 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 -0000	1.21
>>+++ extern.h	16 Jul 2004 07:07:50 -0000
>>@@ -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.1	7 Jul 2004 19:57:15 -0000	1.66
>>+++ find.1	16 Jul 2004 07:12:58 -0000
>>@@ -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 -0000	1.50
>>+++ function.c	16 Jul 2004 07:07:05 -0000
>>@@ -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 -0000	1.22
>>+++ option.c	16 Jul 2004 07:06:49 -0000
>>@@ -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: bright@mu.org cell: 408-480-4684
> 
> 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?40F78A8F.2010502>