mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-31 12:21:19 -03:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user