Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2068)

Unified Diff: base/file_util_mac.mm

Issue 6660001: Getting service process on Mac to handle having things moved/changed underneath it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698