Sandbox issue when accessing renamed temporary file on external FAT32 thumb drives

I'm developing a macOS app where users load files from all kinds of internal and external volumes for editing. Whenever the user loads a folder, I'm keeping a secure bookmark internally and use this is combination with

startAccessingSecurityScopedResource() and stopAccessingSecurityScopedResource()

This works fine most of the time. However, there is one situation where it doesn't work as expected and this is when the following conditions are met:
  1. The file in question is on an external FAT32 thumb drive

  2. The editing process requires a temporary file

Writing to the temporary file works without problems, as well as atomically replacing the original file via POSIX rename() (this is from C++). However, each subsequent read access to the file fails due to a sandboxing error:

Code Block
NSUnderlyingError=0x600003cf1e00 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}
System Policy: deny(1) file-read-data /Volumes/...


The sandboxd metadata shows "storage-class":"TemporaryItems" which might be related.

Any help is much appreciated!
Do you see the same problem with a Apple-formatted external volume (APFS or HFS Plus)?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
No, I don't see the same problem with a Apple-formatted external volume.

If I re-format the same external drive as Mac OS Extended (HFS+) via Disk Utility the same operation involving the temporary file works without problems.

If I re-format the external drive back to FAT32, the issue re-appears. I've also tried with different external drives and have various users reporting the issue.

Thanks for your reply!

No, I don't see the same problem with a Apple-formatted external
volume.

Interesting. That suggests that the problem isn’t with your code but with the way that the sandbox infrastructure handle’s volumes, like FAT32, that don’t support Mac semantics. Regardless of what else you do I encourage you to file a bug about this. It would help if you attached a small test project that demonstrates the issue.

Please post your bug number, just for the record.

As to a workaround, I’ve not got any immediate suggestions. My advice is that you open a DTS tech support incident a discuss this with our expert in this area.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
Thank you for the reply. It's really great that you're taking the time to also investigate such seemingly obscure issues and I found many of your post here really helpful!

I've used the past couple of hours creating the an example project and filed a bug with all the details. I really hope that someone can make sense of it.

I've filed it as FB9047017.
Sandbox issue when accessing renamed temporary file on external FAT32 thumb drives
 
 
Q