ls: support --time=creation to show/sort birth time

* src/ls.c (usage): Reorganize help for --time,
and add description for --time=birth.
(do_statx): Store btime in mtime if available.
(get_stat_btime): A new function to read the creation time
from the appropriate stat structure member.
(cmp_btime): A new function to compare birth time.
(print_long_format): Output '?' when birth time unavailable.
* doc/coreutils.texi: Document --time={birth,creation}.
* tests/local.mk: Reference the new test.
* tests/ls/birthtime.sh: Add a new test.
* NEWS: Mention the new feature.
This commit is contained in:
Pádraig Brady
2020-01-02 16:20:13 +00:00
parent dda53d75a8
commit 2cecc3cc99
5 changed files with 116 additions and 14 deletions

27
tests/ls/birthtime.sh Executable file
View File

@@ -0,0 +1,27 @@
#!/bin/sh
# ensure that ls attempts birthtime access
# Copyright (C) 2020 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 <https://www.gnu.org/licenses/>.
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
print_ver_ ls
# ls should not fail, even if birth time not available
touch a || framework_failure_
ls --time=birth -l a || fail=1
ls --time=creation -t a || fail=1
Exit $fail