The filesystem is lying to me, and I can’t fix it. A tale of woe and incompetence.
My problem is that the tag utility I use to write metadata tags to my files in my scripts will report that the operation has been completed but on my external APFS spinning platter drive (yes I know not my brightest idea ever) if I immediately afterwards do a query it won’t always be the case. I assume from experience with file systems on Linux that this is due to design decisions in APFS which mean anything you really want to make sure is on disk now needs to be manually synced.
Investigating the sadly dormant codebase for the tagging tool, the saving operation seems to be handled by this function.
So how do you tell NSURL setResourceValue that it needs to apply the hammer?
Since according to the documentation is returns yes when things are written to disk then it should already do that but evidence indicates that this is not the case. developer.apple.com/documenta…
There also doesn’t seem to be a flag on NSURL to mark the object as critical and needing an fsync performed.
I suppose I could try something truly hideous like looping over the above operation a few times to ensure that the message got through.
What I ended up doing was inserting sleep 5 after every interaction with the tagging tool in my scripts to ensure that some time had passed to allow things to have settled on disk.
This makes me feel incompetent and thus remains my tale of woe.