| Index: base/file_util_mac.mm
|
| diff --git a/base/file_util_mac.mm b/base/file_util_mac.mm
|
| index 95d4f25722a9d9859ff4dd169bf23bef6a248db1..e7eaaf5513c9498a8d16fa51209e81882d15f613 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,40 @@ 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);
|
| + if (err != noErr) {
|
| + LOG(ERROR) << "Unable to determine if " << path.value()
|
| + << "is in trash (" << err << ")";
|
| + result = false;
|
| + }
|
| + return 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
|
|
|