`cp -p` doesn't correctly copy mtime

Originator:thakis
Number:rdar://8957219 Date Originated:2020 Dec 30
Status: Resolved:
Product:macos Product Version:11.0.1
Classification: Reproducible:
 
1. Create a file with a high-res timestamp. On 11.0, `touch file1` works, on 10.15.7 and earlier `python -c 'open("file1", "w")'` works. Use `stat -f %Fm file` to verify that the file has non-zero nanoseconds in its mtimestamp:

  % touch file1
  % stat -f %Fm file1
  1609344354.172814338

2. Copy the file with `cp -p file1 file2` and check the timestamp of file2:

  % cp -p file1 file2
  % stat -f %Fm file2
  1609344354.172814000

Expected: The full timestamp is copied.
Actual: Most of the timestamp is copied, but nanoseconds get zeroed out.

This is a problem for mtime-based build systems. They'll think that the output of the copy has an older timestamp than the input and will re-run the copy on every build. Ninja 1.9+ (https://ninja-build.org/) is an example of a build system that reads high-resolution timestamps and that gets confused by this.

See https://github.com/nico/hack/blob/master/notes/copydir.md for some background around this bug report.

This reproduces on macOS 10.15.7 and macOS 11.0.1.

Comments

This was fixed at some point.

Not reproducible in 11.3.

(FB8957219)


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!