[PATCH v2] touch: switch to using utimensat() and futimens()

Denys Vlasenko vda.linux at googlemail.com
Tue Apr 13 22:34:40 UTC 2021


On Tue, Apr 13, 2021 at 11:08 PM Xabier Oneca -- xOneca
<xoneca at gmail.com> wrote:
>
> Hi Denys,
>
> > Applied, thank you
>
> You over-shrunk the code and omitted what seems to be a fundamental
> part of the logic of the applet. Now 'touch -am file' does not update
> times.
>
> Here's the merged hunk where the bug is:
>
> -    if ((opts & (OPT_a | OPT_m)) && !newtime) {
> -        time(&timebuf[0].tv_sec);
> -        timebuf[1].tv_sec = timebuf[0].tv_sec;
> -        newtime = timebuf;
> +    if (opts & OPT_a) {
> +        timebuf[1].tv_nsec = UTIME_OMIT;
> +    }
> +    if (opts & OPT_m) {
> +        timebuf[0].tv_nsec = UTIME_OMIT;
>      }
>
> From https://pubs.opengroup.org/onlinepubs/007904975/utilities/touch.html:
>
>    -a  Change the access time of file. Do not change the modification
> time unless -m is also specified.
>    -m  Change the modification time of file. Do not change the access
> time unless -a is also specified.

IOW, -am should be the same as "neither -a nor -m" ?


More information about the busybox mailing list