id now supports specifying multiple users.
+ test now supports the '-N FILE' unary operator (like e.g. bash) to check
+ whether FILE exists and has been modified since it was last read.
+
* Noteworthy changes in release 8.30 (2018-07-01) [stable]
True if @var{file1} and @var{file2} have the same device and inode
numbers, i.e., if they are hard links to each other.
+@item -N @var{file}
+@opindex -N
+@cindex mtime-greater-atime file check
+True if @var{file} exists and has been modified (mtime) since it was
+last read (atime).
+
@end table
unary_advance ();
return euidaccess (argv[pos - 1], X_OK) == 0;
+ case 'N': /* File exists and has been modified since it was last read? */
+ {
+ unary_advance ();
+ if (stat (argv[pos - 1], &stat_buf) != 0)
+ return false;
+ struct timespec atime = get_stat_atime (&stat_buf);
+ struct timespec mtime = get_stat_mtime (&stat_buf);
+ return (timespec_cmp (mtime, atime) > 0);
+ }
+
case 'O': /* File is owned by you? */
{
unary_advance ();
"), stdout);
fputs (_("\
-L FILE FILE exists and is a symbolic link (same as -h)\n\
+ -N FILE FILE exists and has been modified since it was last read\n\
-O FILE FILE exists and is owned by the effective user ID\n\
-p FILE FILE exists and is a named pipe\n\
-r FILE FILE exists and read permission is granted\n\
--- /dev/null
+#!/bin/sh
+# Test 'test -N file'.
+
+# Copyright (C) 2018 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_ test
+
+# For a freshly touched file, atime should equal mtime: 'test -N' returns 1.
+touch file || framework_failure_
+stat file
+returns_ 1 env test -N file || fail=1
+
+# Set access time to 2 days ago: 'test -N' returns 0.
+touch -a -d "12:00 today -2 days" file || framework_failure_
+stat file
+env test -N file || fail=1
+
+# Set mtime to 2 days before atime: 'test -N' returns 1;
+touch -m -d "12:00 today -4 days" file || framework_failure_
+stat file
+returns_ 1 env test -N file || fail=1
+
+# Now modify the file: 'test -N' returns 0.
+> file || framework_failure_
+stat file
+env test -N file || fail=1
+
+Exit $fail