Documents Inbox directory cannot be removed

Originator:matej
Number:rdar://27968875 Date Originated:23-Aug-2016 06:33 PM
Status:Open Resolved:
Product:iOS Product Version:10.0b7
Classification:Other Bug Reproducible:Always
 
Summary:

When using the “Open In…” feature, the system creates an “Inbox” directory in the app’s Documents directory. That directory is not writable by the app, so documents usually need to be immediately moved outside of the Inbox directory. This leads to an empty Inbox directory in the app’s Documents directory. The Inbox directory itself is protected and cannot be removed by the app after it has been created.

Our application shows the content of the Documents directory to the user. Since the user cannot interact with that empty directory we need to explicitly filter it out in our UI. The application also utilizes iTunes file sharing, which exposes the contents of the Documents directory to our users using iTunes. We have no way to hide the Inbox directory in the iTunes UI. 

The directory was debatable before iOS 9. Being simply able to delete the directory would make this whole process much simpler and solve the iTunes file sharing issue. 

Steps to Reproduce:

Using the following code to clean up an existing Inbox directory (created using the Open In… feature of an app that supports it). 

- (void)cleanUpInbox {
    NSFileManager *fileManager = [NSFileManager defaultFileManager];
	NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
    NSString *inbox = [documentsPath stringByAppendingPathComponent:@"Inbox"];
    BOOL isDirectory;
    if ([fileManager fileExistsAtPath:inbox isDirectory:&isDirectory] && isDirectory) {
        NSError *error;
        if (![fileManager removeItemAtPath:inbox error:&error]) {
            NSLog("Could not remove the documents Inbox directory. Error: %@", error);
        }
    }
}

Expected Results:

The Inbox directory would be app-deletable, or moved outside of the Documents directory, so it does not interfere with iTunes file sharing and the app file management. 

Actual Results:

The delete operation fails with the following error.

Printing description of error:
Error Domain=NSCocoaErrorDomain Code=513 "“Inbox” couldn’t be removed because you don’t have permission to access it." UserInfo={NSFilePath=/var/mobile/Containers/Data/Application/9410A118-CE6F-4D95-82FD-2E8604EC3406/Documents/Inbox, NSUserStringVariant=(
    Remove
), NSUnderlyingError=0x17044e5b0 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}

Regression:

Verified on iOS 9 and iOS 10. Might not be the case on older systems. 

Notes:

https://forums.developer.apple.com/message/47582#47582 mentions the change in behavior after iOS 9. 

> As an aside, in iOS 8 you were able to delete the whole Documents/Inbox folder. Seems like iOS 9 prevents deletion of that folder. And if you try to delete it using something like -[NSFileManager removeItemAtURL:...] it will delete the contents and then leave the folder. Seems like that might be good info to have.

http://stackoverflow.com/questions/15707874/good-way-to-manage-the-documents-inbox-folder-in-an-ios-app also mentions mentions the behavior already changed with iOS 7

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!