svn commit: r247274 - in head: bin/test tools/regression/bin/test

Peter Jeremy peter at rulingia.com
Wed Feb 27 08:25:59 UTC 2013


On 2013-Feb-26 01:02:27 +0100, Jilles Tjoelker <jilles at stack.nl> wrote:
>>   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.
>
>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)" ]

In my case I needed to compare the ctime on one set of files with the
mtime in another set.  I had a think about using find(1) and gave it
away as too ugly.  That expression needs serious thought to understand
and about ½ the tokens in the find(1) are to handle special cases -
which is a further indication that it isn't ideal.

>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.

Time parsing is a large can of worms - getting it right is messy (that
patch includes 1KLOC of new code and still isn't locale aware).  And
the work-around of touching a dummy file to the wanted age isn't too
horrrible.  This is a much smaller patch and there's no equally clean
work-around.

>> +a=/tmp/test$$.1
>> +b=/tmp/test$$.2
>
>Please use mktemp(1). Using $$ for temporary files is insecure on
>multiuser systems.

In this case, I want filenames that don't exist.  I will look at using
mktemp(1) to create a temporary directory.

>> +sleep 2    # Ensure $b is newer than $a
>> +touch $b
>
>Please use touch -t instead of sleeping. I'm impatient while running
>tests :)

In this case, I want all the timestamps on $b to be later than $a.  I
initially tried without the sleep but that failed with the builtin
test(1) because the FS timestamps weren't sufficiently granular to
report the difference.  I could create one of the files much earlier
during the test and then use a conditional test to only sleep if the
timestamps were indistinguishable (this probably needs to use the
above find(1) horror to avoid using test(1) to test itself).

I agree the other sleep(1)s should be able to be replaced with
touch(1) but I ran into problems with my initial efforts to do
everything using touch(1).  I will revisit it.

-- 
Peter Jeremy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/svn-src-head/attachments/20130227/1e3a8561/attachment.sig>


More information about the svn-src-head mailing list