I create a NSSavePanel
using this code:
NSSavePanel *savePanel = [NSSavePanel savePanel];
savePanel.delegate = self;
savePanel.directoryURL = ...;
savePanel.nameFieldStringValue = ...;
[savePanel beginSheetModalForWindow:self.window
completionHandler:^(NSInteger returnCode) {
if (returnCode == NSFileHandlingPanelOKButton) {
// the completion handler
}
}];
If in the save panel the user select an already existing file, appears the alert box "“XXX” already exists. Do you want to replace it?".
If the user press the "Replace" button, in the completion handler the old file is removed with the removeItemAtPath:error:
method of NSFileManager
, and then the new file is created (in reality: it is created in a temporary location and then moved using moveItemAtPath:toPath:error:
method, but I think this is just an implementation detail):
if (returnCode == NSFileHandlingPanelOKButton) {
// overwrite the url, because if we are here is because the user has already
// expressed its willingness to overwrite the previous file
NSError *error = nil;
BOOL res = [[NSFileManager defaultManager] removeItemAtURL:savePanel.URL error:&error];
if (res) {
res = [[NSFileManager defaultManager] moveItemAtPath:tmpFilePath toPath:savePanel.URL error:&error];
}
// ...
}
In the past, everything has always worked properly. Today, however, I started to use the Lion's Sandbox with the "Read/Write Access" entitlement.
With the sandbox, the removeItemAtPath:error:
is successful, but the following moveItemAtPath:toPath:error:
returns an error.
It seems reasonable, because Powerbox gives me the rights to access (in reading and writing) a file. When I remove this file, the right granted to me is exhausted.
Is my guess right?
How can I solve this problem?