Bug 39163

Summary: -nt/-ot in test(1) does not detect if tv_nsec are different
Product: Base System Reporter: hburch <hburch>
Component: binAssignee: dwmalone
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 5.0-CURRENT   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description hburch 2002-06-11 20:00:08 UTC
Because newerf only checks st_mtime, if the files have the same value for
st_mtimespec.tv_sec but not for st_mtimespec.tv_nsec, test will improperly
say that the files have the same modification time.

This may be required for POSIX conformance, but that seems unlikely.

Fix: Add code to newerf to check both st_mtimespec.tv_sec and
st_mtimespec.tv_nsec.  The old way was using the st_mtime hook, so
switched it to st_mtimespec.tv_sec for consistency.  Change olderf
to just a call to newerf with the parameters reversed to reduce
code duplication.

Diff from current head (src/bin/test/test.c 1.47)
How-To-Repeat:  $ touch a ; echo pass time; touch b
Expect: pass time
Received: pass time
 $ test b -nt a && echo NEWER
Expect: NEWER
Received: [blank] (if the second does not increment, which is ~99.7%
                   of the time on my system)
Comment 1 dwmalone freebsd_committer freebsd_triage 2002-06-14 23:22:55 UTC
Responsible Changed
From-To: freebsd-bugs->dwmalone

Patch looks sensible - I'll have a look at it.
Comment 2 dwmalone freebsd_committer freebsd_triage 2002-08-11 14:40:53 UTC
State Changed
From-To: open->closed

Patch applied to -current and -stable. Thanks.