Unexpected change in file modification date after copying this file on iOS devices with APFS (iOS 10.3 or later)

Originator:s.alpieiev
Number:rdar://32483489 Date Originated:May 31 2017, 12:39 PM
Status:Open Resolved:
Product:iOS+SDK Product Version:iOS 10.3.2
Classification:Other Bug Reproducible:Always
 
Summary:
Seems like standard C function fflush(...) does not always works correctly on devices with APFS, which causes unexpected change in file modification date later when some operations are performed on this file which shouldn't modify this file.

Steps to Reproduce:
1. Open file using fopen(...) function
2. Write some bytes to it using fwrite(...) function
3. Flush changes using fflush(...) function
4. Make some delay, for example using sleep(1) function (this step is not exactly necessary, but it makes modification date change more obvious (seconds instead of milliseconds))
5. Log file modification date
6. Copy file using -[NSFileManager copyItemAtPath:toPath:error:]
7. Log file modification date again
8. Modification date on steps 5 and 7 differs, but should not

Attached sample project which demonstrates this issue. (Please note that issue is reproducible only on Device with iOS 10.3 or later)

Expected Results:
Source file modification date should not change when we're copying it

Observed Results:
Source file modification date changes when we're copying it

Version:
iOS 10.3 with APFS

Notes:


Configuration:
Devices with iOS 10.3 or higher which supports APFS

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!