coreutils
[Top][All Lists]
Advanced

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

Re: [coreutils] [PATCH 1/2] stat: support printing birthtime


From: Eric Blake
Subject: Re: [coreutils] [PATCH 1/2] stat: support printing birthtime
Date: Fri, 01 Oct 2010 08:34:25 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20100921 Fedora/3.1.4-1.fc13 Mnenhy/0.8.3 Thunderbird/3.1.4

On 10/01/2010 03:18 AM, Jim Meyering wrote:

As Pádraig mentioned, s/%x/%w/ and s/%X/%W/

Fixed.


Regarding whether to print " Birth: -" in the default output when
no information is available, I have a slight preference to print it.
First, it should be fine, since no one should be parsing that default
output, so we can change it without fear of breaking client scripts.
Second, seeing that empty line there may encourage users and developers
of lagging file systems and/or kernels to add support (yeah, right).

OK, I'm keeping it in.

Here's the test I'm squashing in (plus a cleanup in patch 2/2, when %X is taught sub-second resolution).

diff --git c/doc/coreutils.texi i/doc/coreutils.texi
index c5dda4f..12f103a 100644
--- c/doc/coreutils.texi
+++ i/doc/coreutils.texi
@@ -10697,7 +10697,7 @@ stat invocation
 @item %u - User ID of owner
 @item %U - User name of owner
 @item %w - Time of file birth, or @samp{-} if unknown
-@item %W - Time of last birth as seconds since Epoch, or @samp{-}
+@item %W - Time of file birth as seconds since Epoch, or @samp{-}
 @item %x - Time of last access
 @item %X - Time of last access as seconds since Epoch
 @item %y - Time of last modification
diff --git c/src/stat.c i/src/stat.c
index c465e77..2b4a048 100644
--- c/src/stat.c
+++ i/src/stat.c
@@ -1150,8 +1150,8 @@ The valid format sequences for files (without --file-system):\n\
       fputs (_("\
   %u   User ID of owner\n\
   %U   User name of owner\n\
-  %x   Time of file birth, or - if unknown\n\
-  %X   Time of file birth as seconds since Epoch, or - if unknown\n\
+  %w   Time of file birth, or - if unknown\n\
+  %W   Time of file birth as seconds since Epoch, or - if unknown\n\
   %x   Time of last access\n\
   %X   Time of last access as seconds since Epoch\n\
   %y   Time of last modification\n\
diff --git c/tests/Makefile.am i/tests/Makefile.am
index 3236637..a6a0594 100644
--- c/tests/Makefile.am
+++ i/tests/Makefile.am
@@ -239,6 +239,7 @@ TESTS =                                             \
   misc/split-a                                 \
   misc/split-fail                              \
   misc/split-l                                 \
+  misc/stat-birthtime                          \
   misc/stat-fmt                                        \
   misc/stat-hyphen                             \
   misc/stat-mount                              \
diff --git c/tests/misc/stat-birthtime i/tests/misc/stat-birthtime
new file mode 100755
index 0000000..d4f372e
--- /dev/null
+++ i/tests/misc/stat-birthtime
@@ -0,0 +1,46 @@
+#!/bin/sh
+# ensure that stat attempts birthtime access
+
+# Copyright (C) 2010 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+if test "$VERBOSE" = yes; then
+  set -x
+  stat --version
+fi
+
+. $srcdir/test-lib.sh
+
+# Whether birthtime is supported or not, it better not change even when
+# [acm]time are modified.  :)
+touch a || fail=1
+btime=$(stat --format %W a) || fail=1
+atime=$(stat --format %X a) || fail=1
+mtime=$(stat --format %Y a) || fail=1
+ctime=$(stat --format %Z a) || fail=1
+
+case $(stat --format %x a) in
+  *.000000000*) sleep 2;; # worst case file system is FAT
+  *) # FIXME: sleep .1 would be sufficient if %X showed nanoseconds
+ sleep 1;; # should be adequate for any system with subsecond resolution
+esac
+
+touch a || fail=1
+test "x$btime" = x$(stat --format %W a) || fail=1
+test "x$atime" != x$(stat --format %X a) || fail=1
+test "x$mtime" != x$(stat --format %Y a) || fail=1
+test "x$ctime" != x$(stat --format %Z a) || fail=1
+
+Exit $fail


--
Eric Blake   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org



reply via email to

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