bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: touch v5.00


From: Paul Eggert
Subject: Re: touch v5.00
Date: 15 Dec 2003 11:27:27 -0800
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

Michael Rasmussen <address@hidden> writes:

> touch the time backwards by ARGUMENT seconds, or as the man page for that
> release said:
> 
>        -B, --backward=SECONDS
> 
>               Modify  the  time  by  going back SECONDS seconds.  For example,
>               touch -r foo -B 5 bar will make the file  bar  5  seconds  older
>               than file foo.

Which release of which operating system is this documentation from?
Can you give a URL to the documentation?

Also, what does that version of 'touch' do if -B, -a, and -m are all
specified?  For example, does "touch -a -m -r FOO -B 5 BAR" set the
modification time of BAR to be 5 seconds before the modification time
of FOO, and at the same time set the access time of BAR to be 5
seconds before the access time of FOO?

It seems to me that a more consistent way to do this with GNU touch is
to allow the -r and -d options to be specified together, e.g.:

touch -r FOO -d '-5 sec' BAR

would set the time of BAR to be the same as that of FOO, minus 5
seconds.  GNU touch's usage message already implies that this should
work.  Here's a proposed patch to do that.

2003-12-15  Paul Eggert  <address@hidden>

        * NEWS, doc/coreutils.texi: touch -r and -d can now both be specified,
        with -r specifying the origin for -d.
        * src/touch.c (flexible_date): Remove static var.
        (get_reldate): New function.
        (main): Use it, to implement this new behavior.

--- NEWS.~1.149.~       Thu Nov 27 00:18:45 2003
+++ NEWS        Mon Dec 15 11:24:19 2003
@@ -29,6 +29,11 @@ GNU coreutils NEWS                      
   (--dereference-args, aka -D) rather then the current meaning of --si.
   Now, using -H elicits a warning to that effect.
 
+  touch -r now specifies the origin for any relative times in the -d
+  operand, if both options are given.  For example, "touch -r FOO -d
+  '-5 seconds' BAR" sets BAR's modification time to be five seconds
+  before FOO's.
+
 ** Bug fixes
 
   printf, seq, tail, and sleep now parse floating-point operands
--- doc/coreutils.texi.~1.142.~ Wed Nov 26 23:58:32 2003
+++ doc/coreutils.texi  Mon Dec 15 10:38:25 2003
@@ -8076,6 +8076,11 @@ Change the modification time only.
 @opindex -r
 @opindex --reference
 Use the times of the reference @var{file} instead of the current time.
+If this option is combined with the @address@hidden
+(@option{-d @var{time}}) option, the reference @var{file}'s time is
+the origin for any relative @var{time}s given, but is otherwise ignored.
+For example, @samp{-r foo -d '-5 seconds'} specifies a time stamp
+equal to five seconds before the corresponding time stamp for @file{foo}.
 
 @item -t [[CC]YY]MMDDhhmm[.ss]
 Use the argument (optional four-digit or two-digit years, months,
--- src/touch.c.~1.117.~        Sat Oct 18 03:05:47 2003
+++ src/touch.c Mon Dec 15 10:46:00 2003
@@ -56,9 +56,6 @@ static int change_times;
 /* (-c) If nonzero, don't create if not already there. */
 static int no_create;
 
-/* (-d) If nonzero, date supplied on command line in get_date formats. */
-static int flexible_date;
-
 /* (-r) If nonzero, use times from a reference file. */
 static int use_ref;
 
@@ -112,6 +109,19 @@ static int const time_masks[] =
   CH_ATIME, CH_ATIME, CH_ATIME, CH_MTIME, CH_MTIME
 };
 
+/* Interpret FLEX_DATE as a date, relative to NOW, and return the
+   respresented time.  If NOW is null, use the current time.  FIXME:
+   add support for subsecond resolution.  */
+
+static time_t
+get_reldate (char const *flex_date, time_t const *now)
+{
+  time_t r = get_date (flex_date, now);
+  if (r == (time_t) -1)
+    error (EXIT_FAILURE, 0, _("invalid date format %s"), quote (flex_date));
+  return r;
+}
+
 /* Update the time of file FILE according to the options given.
    Return 0 if successful, 1 if an error occurs. */
 
@@ -273,6 +283,7 @@ main (int argc, char **argv)
   int c;
   int date_set = 0;
   int err = 0;
+  char const *flex_date = NULL;
 
   initialize_main (&argc, &argv);
   program_name = argv[0];
@@ -282,7 +293,7 @@ main (int argc, char **argv)
 
   atexit (close_stdout);
 
-  change_times = no_create = use_ref = posix_date = flexible_date = 0;
+  change_times = no_create = use_ref = posix_date = 0;
 
   while ((c = getopt_long (argc, argv, "acd:fmr:t:", longopts, NULL)) != -1)
     {
@@ -300,11 +311,7 @@ main (int argc, char **argv)
          break;
 
        case 'd':
-         flexible_date++;
-         newtime.tv_sec = get_date (optarg, NULL);
-         newtime.tv_nsec = 0; /* FIXME: get_date should set this.  */
-         if (newtime.tv_sec == (time_t) -1)
-           error (EXIT_FAILURE, 0, _("invalid date format %s"), quote 
(optarg));
+         flex_date = optarg;
          date_set++;
          break;
 
@@ -346,8 +353,7 @@ main (int argc, char **argv)
   if (change_times == 0)
     change_times = CH_ATIME | CH_MTIME;
 
-  if ((use_ref && (posix_date || flexible_date))
-      || (posix_date && flexible_date))
+  if (posix_date && (use_ref || flex_date))
     {
       error (0, 0, _("cannot specify times from more than one source"));
       usage (EXIT_FAILURE);
@@ -358,7 +364,22 @@ main (int argc, char **argv)
       if (stat (ref_file, &ref_stats))
        error (EXIT_FAILURE, errno,
               _("failed to get attributes of %s"), quote (ref_file));
+      if (flex_date)
+       {
+         if (change_times & CH_ATIME)
+           ref_stats.st_atime = get_reldate (flex_date, &ref_stats.st_atime);
+         if (change_times & CH_MTIME)
+           ref_stats.st_mtime = get_reldate (flex_date, &ref_stats.st_mtime);
+       }
       date_set++;
+    }
+  else
+    {
+      if (flex_date)
+       {
+         newtime.tv_sec = get_reldate (flex_date, NULL);
+         newtime.tv_nsec = 0;
+       }
     }
 
   /* The obsolete `MMDDhhmm[YY]' form is valid IFF there are




reply via email to

[Prev in Thread] Current Thread [Next in Thread]