From owner-svn-src-head@FreeBSD.ORG Tue Feb 26 00:02:31 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 18D315C3; Tue, 26 Feb 2013 00:02:31 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (relay02.stack.nl [IPv6:2001:610:1108:5010::104]) by mx1.freebsd.org (Postfix) with ESMTP id D2CD3F8E; Tue, 26 Feb 2013 00:02:30 +0000 (UTC) Received: from snail.stack.nl (snail.stack.nl [IPv6:2001:610:1108:5010::131]) by mx1.stack.nl (Postfix) with ESMTP id 17F5D358C5D; Tue, 26 Feb 2013 01:02:28 +0100 (CET) Received: by snail.stack.nl (Postfix, from userid 1677) id 02AD52848C; Tue, 26 Feb 2013 01:02:27 +0100 (CET) Date: Tue, 26 Feb 2013 01:02:27 +0100 From: Jilles Tjoelker To: Peter Jeremy Subject: Re: svn commit: r247274 - in head: bin/test tools/regression/bin/test Message-ID: <20130226000227.GA80718@stack.nl> References: <201302251905.r1PJ5fKF085179@svn.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201302251905.r1PJ5fKF085179@svn.freebsd.org> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Feb 2013 00:02:31 -0000 On Mon, Feb 25, 2013 at 07:05:41PM +0000, Peter Jeremy wrote: > Author: peterj > Date: Mon Feb 25 19:05:40 2013 > New Revision: 247274 > URL: http://svnweb.freebsd.org/changeset/base/247274 > Log: > Enhance test(1) by adding provision to compare any combination of the > access, birth, change and modify times of two files, instead of only > being able to compare modify times. The builtin test in sh(1) will > automagically acquire the same expansion. > Approved by: grog > MFC after: 2 weeks What do you need this for? If it is not needed very often, this test can be done more portably (older FreeBSD and GNU) as [ -n "$(find -L FILE1 -prune -newerXY FILE2 2>/dev/null)" ] (If FILE1 is certainly not a directory, -prune can be omitted; if FILE1 is certainly not a symlink or should not be followed, -L can be omitted; the 2>/dev/null silences error messages about nonexistent files that test(1) does not generate.) I have generally been rather reluctant in adding things to sh(1) and even more so if they are completely new. Someone proposed something rather similar (except that it added a time string parser -- even more code) in PR bin/57054 and I rejected it in 2009. The -ef, -nt and -ot primaries are not in POSIX but they should remain anyway. They have existed for years and are (almost) compatible to features in most other shells. (Sadly, it was noticed rather late that pdksh's -nt and -ot give results not matching real ksh for nonexistent files.) > Modified: > head/bin/test/test.1 > head/bin/test/test.c > head/tools/regression/bin/test/regress.sh > [snip] > Modified: head/tools/regression/bin/test/regress.sh > ============================================================================== > --- head/tools/regression/bin/test/regress.sh Mon Feb 25 18:07:20 2013 (r247273) > +++ head/tools/regression/bin/test/regress.sh Mon Feb 25 19:05:40 2013 (r247274) > @@ -52,7 +52,7 @@ t () > [snip] > +a=/tmp/test$$.1 > +b=/tmp/test$$.2 Please use mktemp(1). Using $$ for temporary files is insecure on multiuser systems. > +trap "rm -f $a $b" EXIT > + > +# Tests 131-164 > +s 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 $a $b > + > +touch $a > +# Tests 165-198 > +s 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 $a $b > + > +sleep 2 # Ensure $b is newer than $a > +touch $b Please use touch -t instead of sleeping. I'm impatient while running tests :) > +# Tests 199-232 > +s 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 $a $b > + > +sleep 2 > +echo >$b # Updates mtime & ctime You can probably do this with touch -m -t. > +sleep 2 > +touch -A 01 -a $b > + > +# $b now has ctime > mtime > atime > btime > +# Tests 233-266 > +s 1 1 0 1 1 1 1 1 1 0 0 1 0 0 0 1 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 1 $b $b The ctime cannot be manipulated explicitly but the other times can be set in the future so both relations with the ctime can be tested. The touch -a is indeed required because file reads do not set the atime if the filesystem is mounted noatime. -- Jilles Tjoelker