Date: Wed, 27 Feb 2013 19:25:48 +1100 From: Peter Jeremy <peter@rulingia.com> To: Jilles Tjoelker <jilles@stack.nl> Cc: svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org Subject: Re: svn commit: r247274 - in head: bin/test tools/regression/bin/test Message-ID: <20130227082548.GF99210@server.rulingia.com> In-Reply-To: <20130226000227.GA80718@stack.nl> References: <201302251905.r1PJ5fKF085179@svn.freebsd.org> <20130226000227.GA80718@stack.nl>
next in thread | previous in thread | raw e-mail | index | archive | help
--EP0wieDxd4TSJjHq Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2013-Feb-26 01:02:27 +0100, Jilles Tjoelker <jilles@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 =BD 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=3D/tmp/test$$.1 >> +b=3D/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. --=20 Peter Jeremy --EP0wieDxd4TSJjHq Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (FreeBSD) iEYEARECAAYFAlEtwwwACgkQ/opHv/APuIeFvACeOgfECr+1cchOoV4s8MgvPapO HyYAoJz+idnfLYUcklexj343j62LFYI7 =qmM8 -----END PGP SIGNATURE----- --EP0wieDxd4TSJjHq--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130227082548.GF99210>