Add path mtime (#9057)

This can be used to print the modification time, like `stat` with some
options.

The reason is that `stat` has caused us a number of portability
headaches:

1. It's not available everywhere by default
2. The versions are quite different

For instance, with GNU stat it's `stat -c '%Y'`, with macOS it's `stat
-f %m`.

So now checking a cache file can be done just with builtins.
This commit is contained in:
Fabian Boehm
2022-07-18 20:39:01 +02:00
committed by GitHub
parent d9ee5d3863
commit 5dfb64b547
10 changed files with 115 additions and 26 deletions

View File

@@ -198,3 +198,21 @@ test (path resolve link) = (pwd -P)/link
and echo link resolves to link
# CHECK: link resolves to link
# path mtime
# These tests deal with *time*, so we have to account
# for slow systems (like CI).
# So we should only test with a lot of slack.
echo bananana >> foo
test (math abs (date +%s) - (path mtime foo)) -lt 20
or echo MTIME IS BOGUS
sleep 2
set -l mtime (path mtime --relative foo)
test $mtime -ge 1
or echo mtime is too small
test $mtime -lt 20
or echo mtime is too large