test: fix POSIX -nt and -ot when "older" is missing
These should evaluate true if the newer file exists and the older is missing or older, but it was never true if older is missing. Note: 'test X -nt Y' is identical to 'test Y -ot X' https://pubs.opengroup.org/onlinepubs/9799919799/utilities/test.html function old new delta binop 593 634 +41 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 41/0) Total: 41 bytes Signed-off-by: Avi Halachmi (:avih) <avihpit@yahoo.com> Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
1 parent
aeaa7f547c
commit
5e57539acb
2 files changed
+18
-5
No files matched your search
+5
-5
@@ -621,15 +621,15 @@ static int binop(void)
|
||||
/* if (is_file_op(op->op_num)) */
|
||||
{
|
||||
struct stat b1, b2;
|
||||
int sb1 = stat(opnd1, &b1);
|
||||
int sb2 = stat(opnd2, &b2);
|
||||
|
||||
if (stat(opnd1, &b1) || stat(opnd2, &b2))
|
||||
return 0; /* false, since at least one stat failed */
|
||||
if (op->op_num == FILNT)
|
||||
return b1.st_mtime > b2.st_mtime;
|
||||
return !sb1 && (sb2 || b1.st_mtime > b2.st_mtime);
|
||||
if (op->op_num == FILOT)
|
||||
return b1.st_mtime < b2.st_mtime;
|
||||
return !sb2 && (sb1 || b1.st_mtime < b2.st_mtime);
|
||||
/*if (op->op_num == FILEQ)*/
|
||||
return b1.st_dev == b2.st_dev && b1.st_ino == b2.st_ino;
|
||||
return !sb1 && !sb2 && b1.st_dev == b2.st_dev && b1.st_ino == b2.st_ino;
|
||||
}
|
||||
/*return 1; - NOTREACHED */
|
||||
}
|
||||
|
||||
@@ -95,5 +95,18 @@ testing "test '!' '(' = '(': should be false (1)" \
|
||||
"busybox test '!' '(' = '('; echo \$?" \
|
||||
"1\n" \
|
||||
"" ""
|
||||
mkdir -p test.tempdir
|
||||
touch test.tempdir/exists
|
||||
|
||||
testing "test exists -nt nonexistent should be true (0)" \
|
||||
"busybox test test.tempdir/exists -nt test.tempdir/nonexistent; echo \$?" \
|
||||
"0\n" \
|
||||
"" ""
|
||||
|
||||
testing "test nonexistent -ot exists should be true (0)" \
|
||||
"busybox test test.tempdir/nonexistent -ot test.tempdir/exists; echo \$?" \
|
||||
"0\n" \
|
||||
"" ""
|
||||
rm -rf test.tempdir
|
||||
|
||||
exit $FAILCOUNT
|
||||
Reference in new issue
Block a user