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 _______________________________________________ svn-src-head@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"