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

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: fixed up phajdan's comments, got things working properly 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..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

Powered by Google App Engine
This is Rietveld 408576698