TAKAI Kousuke <[EMAIL PROTECTED]> wrote:
> I have found a bug in `touch' command from fileutils 4.1.8
> that `touch -c' wrongly reports an error for non-existent file.
> (At least) SUSv2 seems to say `touch -c FILE' should not write any
> diagnostic messages when FILE does not exist.
>
>   % touch --version
>   touch (fileutils) 4.1.8
>   [...]
>   % touch --no-create non-existent-file
>   touch: setting times of `non-existent-file': No such file or directory
>   %
>
> Fileutils-3.16 and 4.0's `touch' appear to behave as SUSv2 says,
> but 4.1 and later version have this problem.
>
> Here is a correction I made.
>
> 2002-04-16  TAKAI Kousuke  <[EMAIL PROTECTED]>
>
>       * src/touch.c (touch): Don't report an error when --no-create
>         is in effect and error was ENOENT.

Thank you very much for the report and patch!

I've made the following slightly different change.
The additional (first) part is necessary to prevent this improper failure:

  $ touch -cm no-file
  touch: failed to get attributes of `no-file': No such file or directory

Now, it works like this:

  $ ./touch -c no-file || echo fail
  $ ./touch -cm no-file || echo fail
  $

Index: src/touch.c
===================================================================
RCS file: /fetish/fileutils/src/touch.c,v
retrieving revision 1.101
diff -u -p -u -p -r1.101 touch.c
--- src/touch.c 2002/02/20 16:06:20     1.101
+++ src/touch.c 2002/04/17 08:37:31
@@ -163,7 +163,12 @@ touch (const char *file)
          if (open_errno)
            error (0, open_errno, _("creating %s"), quote (file));
          else
-           error (0, errno, _("failed to get attributes of %s"), quote (file));
+           {
+             if (no_create && errno == ENOENT)
+               return 0;
+             error (0, errno, _("failed to get attributes of %s"),
+                    quote (file));
+           }
          close (fd);
          return 1;
        }
@@ -211,7 +216,11 @@ touch (const char *file)
       if (open_errno)
        error (0, open_errno, _("creating %s"), quote (file));
       else
-       error (0, errno, _("setting times of %s"), quote (file));
+       {
+         if (no_create && errno == ENOENT)
+           return 0;
+         error (0, errno, _("setting times of %s"), quote (file));
+       }
       return 1;
     }
 

_______________________________________________
Bug-fileutils mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/bug-fileutils

Reply via email to