Index: base/file_util_mac.mm |
diff --git a/base/file_util_mac.mm b/base/file_util_mac.mm |
index 95d4f25722a9d9859ff4dd169bf23bef6a248db1..51d129e0d05262a105dfec7f11f9b1b700a5e4a5 100644 |
--- a/base/file_util_mac.mm |
+++ b/base/file_util_mac.mm |
@@ -4,11 +4,14 @@ |
#include "base/file_util.h" |
+#include <CoreServices/CoreServices.h> |
#import <Foundation/Foundation.h> |
#include <copyfile.h> |
#include "base/basictypes.h" |
#include "base/file_path.h" |
+#include "base/logging.h" |
+#include "base/mac/mac_util.h" |
#include "base/string_util.h" |
#include "base/threading/thread_restrictions.h" |
@@ -32,4 +35,37 @@ bool CopyFile(const FilePath& from_path, const FilePath& to_path) { |
to_path.value().c_str(), NULL, COPYFILE_ALL) == 0); |
} |
+bool IsInTrash(const FilePath& path) { |
+ FSRef ref; |
+ if (!base::mac::FSRefFromPath(path.value(), &ref)) { |
+ LOG(ERROR) << "Unable to get FSRef for " << path.value(); |
+ return false; |
+ } |
+ Boolean result = false; |
+ OSStatus err = FSDetermineIfRefIsEnclosedByFolder( |
+ kOnAppropriateDisk, kTrashFolderType, &ref, &result); |
+ // See http://lists.apple.com/archives/filesystem-dev/2009/Sep/msg00008.html |
+ // for why this is required. |
+ return err == noErr && result; |
+} |
+ |
+bool MoveToTrash(const FilePath& path, FilePath* new_path) { |
+ FSRef path_ref; |
+ FSRef new_path_ref; |
+ if (!base::mac::FSRefFromPath(path.value(), &path_ref)) { |
+ LOG(ERROR) << "Unable to get FSREf for " << path.value(); |
+ return false; |
+ } |
+ OSStatus status = FSMoveObjectToTrashSync(&path_ref, &new_path_ref, |
+ kFSFileOperationDefaultOptions); |
+ if (status != noErr) { |
+ LOG(ERROR) << "MoveToTrash " << status; |
+ return false; |
+ } |
+ if (new_path) { |
+ *new_path = FilePath(base::mac::PathFromFSRef(new_path_ref)); |
+ } |
+ return true; |
+} |
+ |
} // namespace |