createDirectoryAtPath returning NO for existing directories despite withIntermediateDirectories:YES
| Originator: | RichWChan | ||
| Number: | rdar://16349920 | Date Originated: | 2014-03-17 |
| Status: | Open | Resolved: | |
| Product: | iOS SDK | Product Version: | 7.1 |
| Classification: | Serious Bug | Reproducible: | Always |
# Title createDirectoryAtPath returning NO for existing directories despite withIntermediateDirectories:YES # Description An app calling `createDirectoryAtPath:path withIntermediateDirectories:YES` on multiple threads for the same path sometimes result in one of them returning NO. According to the specs for `-NSFileManager createDirectoryAtPath:`, it is supposed to return "YES if createIntermediates is set and the directory already exists". However, there seems to be possible races if it is called from multiple threads at the same time, which would result in it returning NO instead. According to the documentation stating "the methods of the shared NSFileManager object can be called from multiple threads safely", this should not happen. * referencing documentation on: https://developer.apple.com/library/mac/documentation/cocoa/reference/foundation/classes/nsfilemanager_class/reference/reference.html#//apple_ref/occ/instm/NSFileManager/createDirectoryAtPath:withIntermediateDirectories:attributes:error: # Steps to reproduce 1. Create a project with lots of threads creating the same folder (e.g. /Library/Caches/Foo/Bar) 2. Add an assertion for the returned value being YES. 3. Run 4. Quite frequently, one of the threads will hit a case where the returned value is NO. (not necessarily every time, but happens pretty frequently on my setup in both simulator and device) # Expected Results All calls should return YES since they all either created the folder or the folder already exists.
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!