mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-29 14:21:24 -03:00
builtin test: Implement -ot, -nt, -ef
These are non-POSIX extensions other test(1) utilities implement, which compares the modification time of two files as proposed for fish in #3589: testing if one file is newer than another file. -ef is a common extension to test(1) which checks if two paths refer to the same file, by comparing the dev and inode numbers.
This commit is contained in:
@@ -868,6 +868,22 @@ static int compare(T a, T b) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// \return true if \param rhs has higher mtime seconds than this file_id_t.
|
||||
/// If identical, nanoseconds are compared.
|
||||
bool file_id_t::older_than(const file_id_t &rhs) const {
|
||||
int ret = compare(mod_seconds, rhs.mod_seconds);
|
||||
if (!ret) ret = compare(mod_nanoseconds, rhs.mod_nanoseconds);
|
||||
switch (ret) {
|
||||
case -1:
|
||||
return true;
|
||||
case 1:
|
||||
case 0:
|
||||
return false;
|
||||
default:
|
||||
DIE("unreachable");
|
||||
}
|
||||
}
|
||||
|
||||
int file_id_t::compare_file_id(const file_id_t &rhs) const {
|
||||
// Compare each field, stopping when we get to a non-equal field.
|
||||
int ret = 0;
|
||||
|
||||
Reference in New Issue
Block a user