Ruby mtime not working correctly on APFS

Originator:kuehn.karl
Number:rdar://33734892 Date Originated:8/4/2017
Status:Open Resolved:
Product:macOS + SDK Product Version:10.13 Beta (17A315i)
Classification:Other Bug Reproducible:Always
 
Something is wrong with the `mtime` handling of Ruby on AFPS, and it looks like a float precision error as the deltas are usually around 4e-7 seconds.

Steps to Reproduce:
1. Download the attached script to a APFS volume
2. Run it using the Ruby interpreter (e.g.: `ruby ruby-mtime-test.rb`)

Expected Results:
The output should be "All good"

Observed Results:
A message like "The timestamps were 2.15e-07 seconds off"

Notes:
The script creates the two temp files it uses (and subsequently deletes) in the same folder as it is placed.

Configuration:
If the script (and thus the temp files it create) is on a HFS+ volume (e.g.: a mounted HFS+ disk image) then the test passes. If it is on APFS then it fails.

===== Script

#!/usr/bin/env ruby

require 'tempfile'

this_dir     = File.dirname(__FILE__)

# create a file
source_file  = Tempfile.new('source', this_dir)
sleep(1)
target_file  = Tempfile.new('target', this_dir)
source_mtime = File.mtime(source_file)

# make sure the MTimes are different
raise 'The timestamps were somehow the same' unless source_mtime != File.mtime(target_file)

# set the file times
File.utime(source_mtime, source_mtime, target_file)
target_mtime = File.mtime(target_file)

# check if they are equal
if target_mtime == source_mtime
  print "All good"
else
  STDERR.puts "The timestamps were #{(target_mtime - source_mtime).abs} seconds off"
  exit 1
end

Comments


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!