mac: Use NSFileManager::resultingItemURL for moving file to trash

This allows the deleted file to be restored, fixes #2001.
This commit is contained in:
Cheng Zhao 2015-06-18 13:09:02 +08:00
parent beb2853bbf
commit c8eaaaea83

View file

@ -140,17 +140,12 @@ bool OpenExternal(const GURL& url) {
}
bool MoveItemToTrash(const base::FilePath& full_path) {
DCHECK([NSThread isMainThread]);
NSString* path_string = base::SysUTF8ToNSString(full_path.value());
NSArray* file_array =
[NSArray arrayWithObject:[path_string lastPathComponent]];
BOOL status = [[NSWorkspace sharedWorkspace]
performFileOperation:NSWorkspaceRecycleOperation
source:[path_string stringByDeletingLastPathComponent]
destination:@""
files:file_array
tag:nil];
if (!path_string || !file_array || !status)
BOOL status = [[NSFileManager defaultManager]
trashItemAtURL:[NSURL fileURLWithPath:path_string]
resultingItemURL:nil
error:nil];
if (!path_string || !status)
LOG(WARNING) << "NSWorkspace failed to move file " << full_path.value()
<< " to trash";
return status;