Skip to content

ls: Should print timestamp for dates far in the future #8355

@drinkcat

Description

@drinkcat

Steps to repro (might need to use tmpfs for this, e.g. my local ext4 does not like such large timestamps)

$ touch -d @9223372036854775807 /tmp/future
$ LC_ALL=C TZ=UTC0 ls -l /tmp/future
-rw-r--r-- 1 drinkcat drinkcat 0 9223372036854775807 /tmp/future
$ LC_ALL=C TZ=UTC0 cargo run ls -l /tmp/future
-rw-r--r-- 1 drinkcat drinkcat 0 ??? /tmp/future

The cutoff is at 67768036191676799/67768036191676800 (basically when the year doesn't fit in signed 32-bit anymore, the timezone does play a role here):

touch -d @67768036191676799 /tmp/future && LC_ALL=C TZ=UTC0 ls -l /tmp/future
-rw-r--r-- 1 drinkcat drinkcat 0 Dec 31  2147485547 /tmp/future
touch -d @67768036191676800 /tmp/future && LC_ALL=C TZ=UTC0 ls -l /tmp/future
-rw-r--r-- 1 drinkcat drinkcat 0 67768036191676800 /tmp/future

Also, ls is unhappy about times much less far in the future (and prints ???):

$ touch -d @677680361916 /tmp/future
$ LC_ALL=C TZ=UTC0 cargo run ls -l /tmp/future
-rw-r--r-- 1 drinkcat drinkcat 0 ??? /tmp/future
$ LC_ALL=C TZ=UTC0 ls -l /tmp/future 
-rw-r--r-- 1 drinkcat drinkcat 0 Nov  1  23444 /tmp/future

This causes tests/du/bigtime to be skipped:

util/run-gnu-test.sh tests/du/bigtime
bigtime.sh: skipped test: file system or localtime mishandles big timestamps: -rw-r--r-- 1 drinkcat drinkcat 0 May 10 22:38 future

What the code does is:

export LC_ALL=C
export TZ=UTC0
# 2**63 - 1
bignum=9223372036854775807

touch -d @$bignum future 2>/dev/null &&
future_time=$(ls -l future) &&
...

With GNU coreutils, I also hit this issue on my ext4 filesystem:

$ LC_ALL=C TZ=UTC0 touch -d @9223372036854775807 future
$ LC_ALL=C TZ=UTC0 ls -l future
-rw-r--r-- 1 drinkcat drinkcat 0 May 10  2446 future

But tmpfs is fine:

$ LC_ALL=C TZ=UTC0 touch -d @9223372036854775807 /tmp/future
$ LC_ALL=C TZ=UTC0 ls -l /tmp/future
-rw-r--r-- 1 drinkcat drinkcat 0 9223372036854775807 /tmp/future

Back to uutils/coreutils:

$ LC_ALL=C TZ=UTC0 cargo run touch -d @9223372036854775807 /tmp/future
$ LC_ALL=C TZ=UTC0 ls -l /tmp/future
-rw-r--r-- 1 drinkcat drinkcat 0 9223372036854775807 /tmp/future
$ LC_ALL=C TZ=UTC0 cargo run ls -l /tmp/future
-rw-r--r-- 1 drinkcat drinkcat 0 ??? /tmp/future

touch is fine, ls -l is not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions