Can't delete file on external disk
Can't delete file on external disk
- Subject: Can't delete file on external disk
- From: Gabriel Zachmann via Cocoa-dev <email@hidden>
- Date: Thu, 12 Mar 2020 17:55:20 +0100
In my app, I collect lists of files that reside on an external disk.
When the user opens the directory of the files, I create a security-scoped
bookmark like this:
directoryBookmark_ = [dir bookmarkDataWithOptions:
NSURLBookmarkCreationWithSecurityScope
includingResourceValuesForKeys: nil
relativeToURL: nil
error: &systemError];
Next time, the app runs, I resolve the bookmark like this:
directoryLocation_ = [NSURL URLByResolvingBookmarkData: directoryBookmark_
options:
NSURLBookmarkResolutionWithSecurityScope
relativeToURL: nil
bookmarkDataIsStale: & isStale
error: & error];
At some later point, my app wants to delete one of the files in that directory
(or sub-directory),
like this:
NSString * abs_path = [self absolutePathFor: filename_];
BOOL success = [self deleteFile: abs_path ];
This does not work. In the log, I get the error message:
Failed to delete /Volumes/.../image.jpg: “image.jpg” couldn’t be moved to the
trash because you don’t have permission to access it.!
I then try to get more info about the problem using this code:
NSURL * imgurl = [NSURL fileURLWithPath: abs_path isDirectory: NO];
NSError * error;
NSFileHandle * fileHandle = [NSFileHandle fileHandleForUpdatingURL: imgurl
error: & error];
But it always returns a valid fileHandle, i.e., there is no error.
I selected "Read/Write" in the "User Selected File" entitlement.
Of course, everything works fine when the files reside on my local disk (even
across multiple invocations of the app).
The external disk is just a hard disk connected via USB to my laptop.
Deleting the files manually on the external hard disk works, of course.
Does anyone have an idea what mistake I might be making?
Or is there a way to get the necessary permission?
Thanks a lot in advance!
Best regards, Gabriel
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden