cvs commit: src/usr.bin/touch touch.1 touch.c

Brian Somers brian at FreeBSD.org
Mon Apr 9 09:48:40 UTC 2007


On Mon,  9 Apr 2007 02:19:42 +0000 (UTC) Greg Lehey <grog at FreeBSD.ORG> wrote:
> grog        2007-04-09 02:19:37 UTC
> 
>   FreeBSD src repository
> 
>   Modified files:
>     usr.bin/touch        touch.1 touch.c 
>   Log:
>   Add -A flag to adjust existing time stamps.
>   Print name by which program was started in usage() message.

This has got to be one of the strangest commits I've
ever seen...  see below.

>   MFC after:  2 weeks
>   
>   Revision  Changes    Path
>   1.15      +78 -13    src/usr.bin/touch/touch.1
>   1.22      +52 -10    src/usr.bin/touch/touch.c
> _______________________________________________
> cvs-all at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/cvs-all
> To unsubscribe, send any mail to "cvs-all-unsubscribe at freebsd.org"
> 
> 
> Index: src/usr.bin/touch/touch.1
> diff -u src/usr.bin/touch/touch.1:1.14 src/usr.bin/touch/touch.1:1.15
> --- src/usr.bin/touch/touch.1:1.14	Sun Feb 13 22:25:24 2005
> +++ src/usr.bin/touch/touch.1	Mon Apr  9 02:19:37 2007
> @@ -43,6 +43,7 @@
>  .Nd change file access and modification times
>  .Sh SYNOPSIS
>  .Nm
> +.Op Fl A Ar [-][[hh]mm]SS
>  .Op Fl acfhm
>  .Op Fl r Ar file
>  .Op Fl t Ar [[CC]YY]MMDDhhmm[.SS]
> @@ -50,17 +51,79 @@
>  .Sh DESCRIPTION
>  The
>  .Nm
> -utility sets the modification and access times of files to the
> -current time of day.
> -If the file does not exist, it is created with default permissions.
> +utility sets the modification and access times of files.
> +If any file does not exist, it is created with default permissions.
> +.Pp
> +By default,
> +.Nm 
> +changes both modification and access times.  The
> +.Fl a
> +and 
> +.Fl m
> +flags may be used to select the access time or the modification time
> +individually.
> +Selecting both is equivalent to the default.
> +The base times for the modification are both set to the current time.
> +The 
> +.Fl t
> +flag explicitly specifies a single time for both values, and the
> +.Fl r
> +flag specifies to set the times from those of a different file.
> +The 
> +.Fl A
> +flag adjusts the values by a specified amount.
> +This adjustment is done after first establishing the base times.
>  .Pp
>  The following options are available:
>  .Bl -tag -width Ds
> +.It Fl A 
> +Adjust the access and modification time stamps for the file by the
> +specified value.
> +This flag is intended for use in modifying files with a time stamp
> +relative to an incorrect time zone.

I don't understand what this means.  File times are
in UTC aren't they?

> +It always modifies both the access time and the modification time.
> +.Pp
> +The argument is of the form
> +.Dq [-][[hh]mm]SS
> +where each pair of letters represents the following:
> +.Pp
> +.Bl -tag -width Ds -compact -offset indent
> +.It Ar -
> +Make the adjustment negative: the new time stamp is set to be before
> +the old one.
> +.It Ar hh
> +The hour of the day, from 00 to 23.
> +.It Ar mm
> +The minute of the hour, from 00 to 59.
> +.It Ar SS
> +The second of the minute, from 00 to 59.
> +.El

Why this format?  My guess is that the delta is
expected to be a DST difference, but if it is,
I'm even more confused.

> +.Pp
> +When used in conjunction with the
> +.Fl a
> +flag only, the modification time is adjusted by the time specified as
> +argument to the
> +.Fl A
> +flag, while the access time is modified from the base time described
> +above.

Wow.  So -A changes both times in addition to the
access-only time change.  This is really unintuitive
to me.  I'd expect ``-A 000001 -a' to adjust the access
time only (as -a previously meant).  I wouldn't expect
the modification time to be bumped by a second and the
access time to be set to one second in the future.

But again, I don't know why you'd want to do this...

> +Similarly, when used in conjunction with the
> +.Fl m
> +flag only, the access time is adjusted by the time specified as
> +argument to the
> +.Fl A
> +flag, while the access time is modified from the base time described
> +above.

Errum, you mean the modification time?

> +.Pp
> +If the file does not exist, and creation is allowed,
> +.Fl A
> +does not change its time stamps.

So if I ``touch -A 000001 something'' where ``something''
doesn't already exist, the file is created and the time
is left at now?  That's also confusing.

[.....]

> Index: src/usr.bin/touch/touch.c
> diff -u src/usr.bin/touch/touch.c:1.21 src/usr.bin/touch/touch.c:1.22
> --- src/usr.bin/touch/touch.c:1.21	Tue Jan 31 02:21:18 2006
> +++ src/usr.bin/touch/touch.c	Mon Apr  9 02:19:37 2007
> @@ -62,7 +62,8 @@
>  void	stime_arg1(char *, struct timeval *);
>  void	stime_arg2(char *, int, struct timeval *);
>  void	stime_file(char *, struct timeval *);
> -void	usage(void);
> +int	timeoffset(char *);
> +void	usage(char *);
>  
>  int
>  main(int argc, char *argv[])
> @@ -71,17 +72,22 @@
>  	struct timeval tv[2];
>  	int (*stat_f)(const char *, struct stat *);
>  	int (*utimes_f)(const char *, const struct timeval *);
> -	int aflag, cflag, fflag, mflag, ch, fd, len, rval, timeset;
> +	int Aflag, aflag, cflag, fflag, mflag, ch, fd, len, rval, timeset;
>  	char *p;
> +	char *myname;
>  
> -	aflag = cflag = fflag = mflag = timeset = 0;
> +	myname = argv[0];

myname should be set to the base name, not the
full argv[0].

[.....]

I personally think this option is a mistake.  I would
think that something like this would be better:

[-A adjust] - adjust the updated time(s) by the given
``adjust'' number of seconds.

I would imagine this to be useful in (say) a test script
that wanted to set up a bunch of files with time stamps
set to specific relative values.

But I'm clearly missing the point here...?

-- 
Brian Somers                                          <brian at Awfulhak.org>
Don't _EVER_ lose your sense of humour !               <brian at FreeBSD.org>


More information about the cvs-src mailing list