From c8eaaaea83bec692060c131c997e1480856981fd Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 18 Jun 2015 13:09:02 +0800 Subject: [PATCH] mac: Use NSFileManager::resultingItemURL for moving file to trash This allows the deleted file to be restored, fixes #2001. --- atom/common/platform_util_mac.mm | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/atom/common/platform_util_mac.mm b/atom/common/platform_util_mac.mm index a1f17d7c9d5c..1aa75effd35b 100644 --- a/atom/common/platform_util_mac.mm +++ b/atom/common/platform_util_mac.mm @@ -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;