Bug 782352 - Followup -- Harden Remove() such that it doesn't post events for failures. r=khuey
authorDoug Turner <dougt@dougt.org>
Tue, 28 Aug 2012 16:42:40 -0700
changeset 110028 87a187376b3c95a18d4e7dc47a5de2b77dde9a17
parent 110027 ce700bebd73c4853358b61257c2af2afbed2f2ca
child 110029 7b3af36ea9cf41e84c5a1033761035a2880cc7b6
push id1708
push userakeybl@mozilla.com
push dateMon, 19 Nov 2012 21:10:21 +0000
treeherdermozilla-beta@27b14fe50103 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs782352
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 782352 - Followup -- Harden Remove() such that it doesn't post events for failures. r=khuey
dom/devicestorage/nsDeviceStorage.cpp
--- a/dom/devicestorage/nsDeviceStorage.cpp
+++ b/dom/devicestorage/nsDeviceStorage.cpp
@@ -259,19 +259,35 @@ DeviceStorageFile::Write(InfallibleTArra
     return NS_ERROR_FAILURE;
   }
   return NS_OK;
 }
 
 nsresult
 DeviceStorageFile::Remove()
 {
-  mFile->Remove(true);
+  NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
+
+  bool check;
+  nsresult rv = mFile->Exists(&check);
+  if (NS_FAILED(rv)) {
+    return rv;
+  }
+  
+  if (!check) {
+    return NS_OK;
+  }
+
+  rv = mFile->Remove(true);
+  if (NS_FAILED(rv)) {
+    return rv;
+  }
+
   nsCOMPtr<IOEventComplete> iocomplete = new IOEventComplete(mFile, "deleted");
-  NS_DispatchToMainThread(iocomplete);    
+  NS_DispatchToMainThread(iocomplete);
   return NS_OK;
 }
 
 void
 DeviceStorageFile::CollectFiles(nsTArray<nsRefPtr<DeviceStorageFile> > &aFiles,
                                 uint64_t aSince)
 {
   nsString rootPath;
@@ -1091,17 +1107,16 @@ public:
   ~DeleteFileEvent() {}
 
   NS_IMETHOD Run()
   {
     NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
     mFile->Remove();
 
     nsRefPtr<nsRunnable> r;
-
     bool check = false;
     mFile->mFile->Exists(&check);
     if (check) {
       r = new PostErrorEvent(mRequest, POST_ERROR_EVENT_FILE_DOES_NOT_EXIST, mFile);
     }
     else {
       r = new PostResultEvent(mRequest, mFile->mPath);
     }