]> khamidou — GitHub mirrors - electron.git/commitdiff
mac: Use NSFileManager::resultingItemURL for moving file to trash
authorCheng Zhao <zcbenz@gmail.com>
Thu, 18 Jun 2015 05:09:02 +0000 (13:09 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 18 Jun 2015 05:09:02 +0000 (13:09 +0800)
This allows the deleted file to be restored, fixes #2001.

atom/common/platform_util_mac.mm

index a1f17d7c9d5c98737d390345fe406a883b2004bd..1aa75effd35bca46aeb09311934dbdba4cec76c4 100644 (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;