coreutils
[Top][All Lists]
Advanced

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

Re: [coreutils] [PATCH 2/2] stat: print timestamps to full resolution


From: Jim Meyering
Subject: Re: [coreutils] [PATCH 2/2] stat: print timestamps to full resolution
Date: Fri, 01 Oct 2010 10:21:45 +0200

Pádraig Brady wrote:

> On 01/10/10 00:32, Eric Blake wrote:
>> * src/stat.c (epoch_time): New function.
>> (print_stat): Use it for %[WXYZ].
>> * NEWS: Document this.
>> * tests/touch/60-seconds: Adjust test to match.
>> ---
>>
>> It bugs me that %x has more information than %X in 'stat --format',
>> especially, since we don't support any format modifiers for getting
>> at the additional information.  We're already incompatible with
>> BSD stat(1) format modifiers, and there is no standard for stat(1),
>> so I wasn't too worried about changing the meaning of existing
>> modifiers rather than burning new letters just for the nanosecond
>> portions.  And now that POSIX 2008 requires nanonsecond resolution
>> in stat(2), you could argue that we should always be displaying it.
>
> It looks like ext4 at least supports
> nanosecond resolution timestamps
>
> $ date --reference=/ext4/ +%s.%N
> 1285519989.081870491
> $ date --reference=/ext3/ +%s.%N
> 1266874130.000000000
>
> There is a fair chance that scripts may break
> that assume %X is an integer.
> I'd be all on for it otherwise.
> As it is I'm 60:40 for the change.

Good point.
There's at least one script in the code indexed here

  
http://codesearch.google.com/codesearch?as_q=\bstat\+%2B-.*%25[0-9.]*[WXYZ]&sbtn=Search

that might fail:

eclipseclient's src/main/java/com/sshtools/j2ssh/SftpClient.java does this:

   513:   String mtimeS = run("stat -c %Y "+localPath);
   514:   String atimeS = run("stat -c %X "+localPath);
   515:   long atime = Long.parseLong(atimeS);

Depending on how strict that parsing code is...

Thus, I'm a little leery of the change, but not enough
to require something else, since the alternative seems wasteful
and relatively short-sighted.
So go for it ;-)

>> +static char * ATTRIBUTE_WARN_UNUSED_RESULT
>> +epoch_time (struct timespec t)
>> +{
>> +  static char str[INT_STRLEN_BOUND (time_t) + sizeof ".NNNNNNNNN"];
>> +  if (TYPE_SIGNED (time_t))
>> +    sprintf (str, "%" PRIdMAX ".%09lu", (intmax_t) t.tv_sec,
>> +             (unsigned long) t.tv_nsec);
>> +  else
>> +    sprintf (str, "%" PRIuMAX ".%09lu", (uintmax_t) t.tv_sec,
>> +             (unsigned long) t.tv_nsec);
>> +  return str;
>
> time_t can be a float on weird platforms I think?

If you use nstrftime, no one can complain ;-)

Other than that, my only suggestion would be to mention what
these directives mean, so the NEWS entry stands more on its own.
I had to look them up.

  +  stat now outputs the full timestamp resolution for the %X, %Y, and
  +  %Z format directives.



reply via email to

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