Unexpected NSCocoaErrorDomain 513 When Manipulating Files in Sandbox

Originator:bruno
Number:rdar://28827236 Date Originated:18-Oct-2016 08:04 PM
Status:Open Resolved:
Product:iOS Product Version:9, 10
Classification:Performance Reproducible:Unable
 
Summary:

We are fighting with the following error NSCocoaErrorDomain 513 reported by a very small number of users (~ 0.01%). Although this affects a very small number of users, this renders the app useless for them as Genius Scan is unable to create any content.
 
Unable to create directory at path /var/mobile/Containers/Data/Application/EBE2C5D8-5AEC-4D62-9393-B19CAD598FE5/Documents/documents/FF2F88FB-2C07-4FA3-988E-58AD5C21F659/9A02F8A0-74EB-4ED6-81B6-4F40653856D3. Error: Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file “9A02F8A0-74EB-4ED6-81B6-4F40653856D3” in the folder “FF2F88FB-2C07-4FA3-988E-58AD5C21F659”." UserInfo={ NSFilePath=/var/mobile/Containers/Data/Application/EBE2C5D8-5AEC-4D62-9393-B19CAD598FE5/Documents/documents/FF2F88FB-2C07-4FA3-988E-58AD5C21F659/9A02F8A0-74EB-4ED6-81B6-4F40653856D3, NSUnderlyingError=0x15e09de00 { Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied" } }
 
This error means that the directory cannot be created because of a permission error. 

The code generating this error:

NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString* documentsDirectory = [paths objectAtIndex:0]; 
NSString *directory = [documentsDirectory stringByAppendingPathComponent:documentsPathAndUUIDs]; 
NSError *error = nil; 
if (![[NSFileManager defaultManager] createDirectoryAtPath:directory withIntermediateDirectories:YES attributes:nil error:&error]) { 
  NSError(@"Unable to create directory at path %@. Error: %@", directory, error); 
}
 
A couple things worth noting:
- This path isn't saved, it's regenerated every time, so it's not as if the app container had changed between installs;
- The users seem to have available disk space;
- This affects both iOS 9 and 10


Steps to Reproduce:
We are unable to reproduce the issue. It happens to a very small number of users.

It might happen after they are updating the app.

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!