Failure when setting file modificationDate

I properly copy a scrFile to a dstFile with

mManager = [NSFileManager defaultManager];
[mManager copyItemAtPath:srcPath toPath:dstPath error:&error];

but on "some destination disks" the dstFile gets a modificationDate with truncated milliseconds. For instance, with this format "yyyy.MM.dd - HH:mm:ss:SSS" I visualize

srcDate = 2024.11.03 - 12:42:35:772 dstDate = 2024.11.03 - 12:42:35:000

After the copyItemAtPath I even unsuccessfully tried to set the dstFile modificationDate this way

NSMutableDictionary	*dstAttrs = [NSMutableDictionary dictionaryWithDictionary:[mManager attributesOfItemAtPath:dstPath error:nil]];
    
    [dstAttrs setObject:srcDate forKey:NSFileModificationDate];
    [mManager setAttributes:dstAttrs ofItemAtPath:dstPath error:nil];

Again, the dstDate is 2024.11.03 - 12:42:35:000. I unsuccessfully tried even

FSSetCatalogInfo(&dstRef, fsInfo, &srcFsCatInfo);

No way. I noticed that the destination disk is an USB External Physical Volume, Mac OS Extended (Journaled) with "Ignore Ownership on this volume" on. Could this flag be the cause of the trouble? Shouldn't this flag regard only the files ownership?

This issue brings another trouble. Since the srcDate and the dstDate are not equal, my macOS app performing a backup, copies the srcFile to the dstFile again and again.

To workaround the trouble, I actually compare srcDate with dstDate after truncating their milliseconds. But I guess this is not a good practice.

Any idea on how to fix this trouble? Thanks.

P.S. I attach here the disk info

Answered by galad87 in 816060022

HFS+ doesn't store milliseconds, only number of seconds since midnight, January 1, 1904, GMT, so there is no way to do what you want to do.

Modification date is not super reliable, so while it could be useful to check for changes, it's not enough (even in a hypothetical world where HFS+ stores milliseconds).

Accepted Answer

HFS+ doesn't store milliseconds, only number of seconds since midnight, January 1, 1904, GMT, so there is no way to do what you want to do.

Modification date is not super reliable, so while it could be useful to check for changes, it's not enough (even in a hypothetical world where HFS+ stores milliseconds).

LeonardoDev wrote:

So now I'm curious to know which other volume formats don't store milliseconds on the modificationDates

It’s actually worse than that. FAT famously stores dates with a 2 second resolution O-:

which other volume formats don't store milliseconds

Lots of them. If you’re curious, the Wikipedia article for the most common file systems has a Date resolution field with the details.

Annoyingly, neither the range nor the resolution are exposed at the API level, so you can’t tell how trustworthy your dates are.

Also, many older volume formats store the dates on disk in local time, which making things tricky.

which other data are more reliable?

That depends on what you’re using the dates for.

ps It’s better to reply as a reply, as explained in Quinn’s Top Ten DevForums Tips.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Failure when setting file modificationDate
 
 
Q