[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bash "test" -nt and -ot operators mishandle nonpositive timestamps
From: |
Paul Eggert |
Subject: |
bash "test" -nt and -ot operators mishandle nonpositive timestamps |
Date: |
Tue, 26 Feb 2002 15:51:50 -0800 (PST) |
Configuration Information [Automatically generated, do not change]:
Machine: sparc
OS: solaris2.8
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='sparc'
-DCONF_OSTYPE='solaris2.8' -DCONF_MACHTYPE='sparc-sun-solaris2.8'
-DCONF_VENDOR='sun' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib -g
-O2 -Wall -W -Wno-sign-compare -Wpointer-arith -Wstrict-prototypes
-Wmissing-prototypes -Wmissing-noreturn -Wmissing-format-attribute
uname output: SunOS sic.twinsun.com 5.8 Generic_108528-13 sun4u sparc
SUNW,UltraSPARC-IIi-Engine
Machine Type: sparc-sun-solaris2.8
Bash Version: 2.05a
Patch Level: 0
Release Status: release
Description:
The "-ot" and "-nt" operators of the "test" command mishandle
the case where one file has a nonpositive timestamp and the
other file does not exist. Files that do not exist should
always be considered to be older than files that do exist.
Repeat-By:
$ touch -m -t 196001010000 /var/tmp/foo
$ ls -l /var/tmp/foo
-rw-rw-r-- 1 eggert eggert 0 Jan 1 1960 /var/tmp/foo
$ test /no/such/file -nt /var/tmp/foo && echo bug
bug
Fix:
2002-02-26 Paul Eggert <eggert@twinsun.com>
* test.c (filecomp): Fix bug when one file has a nonpositive
timestamp and the other file does not exist.
===================================================================
RCS file: test.c,v
retrieving revision 2.5.1.4.0.1
retrieving revision 2.5.1.4.0.2
diff -pu -r2.5.1.4.0.1 -r2.5.1.4.0.2
--- test.c 2001/11/19 06:25:18 2.5.1.4.0.1
+++ test.c 2002/02/26 23:42:34 2.5.1.4.0.2
@@ -395,25 +395,24 @@ filecomp (s, t, op)
char *s, *t;
int op;
{
+ int r1, r2;
struct stat st1, st2;
- if (test_stat (s, &st1) < 0)
+ if ((r1 = test_stat (s, &st1)) < 0)
{
- st1.st_mtime = 0;
if (op == EF)
return (FALSE);
}
- if (test_stat (t, &st2) < 0)
+ if ((r2 = test_stat (t, &st2)) < 0)
{
- st2.st_mtime = 0;
if (op == EF)
return (FALSE);
}
switch (op)
{
- case OT: return (st1.st_mtime < st2.st_mtime);
- case NT: return (st1.st_mtime > st2.st_mtime);
+ case OT: return (r1 < r2 || (r2 == 0 && st1.st_mtime < st2.st_mtime));
+ case NT: return (r1 > r2 || (r1 == 0 && st1.st_mtime > st2.st_mtime));
case EF: return ((st1.st_dev == st2.st_dev) && (st1.st_ino == st2.st_ino));
}
return (FALSE);
- bash "test" -nt and -ot operators mishandle nonpositive timestamps,
Paul Eggert <=