bug-fileutils
[Top][All Lists]
Advanced

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

Re: bug in `touch -c'


From: Jim Meyering
Subject: Re: bug in `touch -c'
Date: Wed, 17 Apr 2002 10:43:09 +0200
User-agent: Gnus/5.090006 (Oort Gnus v0.06) Emacs/21.2.50 (i686-pc-linux-gnu)

TAKAI Kousuke <address@hidden> 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  <address@hidden>
>
>       * 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;
     }
 



reply via email to

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