Bug 1402581 - P2: Ensure the temporary file exists when failure happens. r=bkelly
authorTom Tung <shes050117@gmail.com>
Tue, 03 Oct 2017 18:44:56 +0800
changeset 384548 d95beed1ed189333fd85094f3995c59f06aab3a0
parent 384547 af0092aac7a11c77a64b51144a0f7fb65c46e914
child 384549 bafdf2e14d4ed9d72f86c7716d5b9f797ebf9e87
push id95807
push userttung@mozilla.com
push dateThu, 05 Oct 2017 03:03:58 +0000
treeherdermozilla-inbound@d95beed1ed18 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1402581
milestone58.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 1402581 - P2: Ensure the temporary file exists when failure happens. r=bkelly There are three changes in this patch: 1. Make sure deleting padding file before the temporary padding file. 2. Not deleting temporary file when failure happens. 3. Endure failure happens after the transaction commit.
dom/cache/FileUtils.cpp
dom/cache/QuotaClient.cpp
--- a/dom/cache/FileUtils.cpp
+++ b/dom/cache/FileUtils.cpp
@@ -870,20 +870,20 @@ LockedDirectoryPaddingFinalizeWrite(nsIF
 nsresult
 LockedDirectoryPaddingRestore(nsIFile* aBaseDir, mozIStorageConnection* aConn)
 {
   MOZ_DIAGNOSTIC_ASSERT(aBaseDir);
   MOZ_DIAGNOSTIC_ASSERT(aConn);
 
   // The content of padding file is untrusted, so remove it here.
   nsresult rv = LockedDirectoryPaddingDeleteFile(aBaseDir,
-                                                 DirPaddingFile::TMP_FILE);
+                                                 DirPaddingFile::FILE);
   if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
 
-  rv = LockedDirectoryPaddingDeleteFile(aBaseDir, DirPaddingFile::FILE);
+  rv = LockedDirectoryPaddingDeleteFile(aBaseDir, DirPaddingFile::TMP_FILE);
   if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
 
   int64_t paddingSize = 0;
   rv = db::FindOverallPaddingSize(aConn, &paddingSize);
   if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
 
   MOZ_DIAGNOSTIC_ASSERT(paddingSize >= 0);
 
--- a/dom/cache/QuotaClient.cpp
+++ b/dom/cache/QuotaClient.cpp
@@ -324,33 +324,44 @@ public:
     {
       MutexAutoLock lock(mDirPaddingFileMutex);
       rv =
         mozilla::dom::cache::
         LockedUpdateDirectoryPaddingFile(aBaseDir, aConn, aIncreaseSize,
                                          aDecreaseSize,
                                          temporaryPaddingFileExist);
       if (NS_WARN_IF(NS_FAILED(rv))) {
-        mozilla::dom::cache::
-        LockedDirectoryPaddingDeleteFile(aBaseDir, DirPaddingFile::TMP_FILE);
+        // Don't delete the temporary padding file here to force the next action
+        // recalculate the padding size.
         return rv;
       }
 
       rv = aCommitHook();
       if (NS_WARN_IF(NS_FAILED(rv))) {
-        mozilla::dom::cache::
-        LockedDirectoryPaddingDeleteFile(aBaseDir, DirPaddingFile::TMP_FILE);
+        // Don't delete the temporary padding file here to force the next action
+        // recalculate the padding size.
         return rv;
       }
 
       rv = mozilla::dom::cache::LockedDirectoryPaddingFinalizeWrite(aBaseDir);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         // Force restore file next time.
-        mozilla::dom::cache::
-        LockedDirectoryPaddingDeleteFile(aBaseDir, DirPaddingFile::FILE);
+        Unused << mozilla::dom::cache::
+                  LockedDirectoryPaddingDeleteFile(aBaseDir,
+                                                   DirPaddingFile::FILE);
+
+        // Ensure that we are able to force the padding file to be restored.
+        MOZ_ASSERT(
+          mozilla::dom::cache::
+          DirectoryPaddingFileExists(aBaseDir, DirPaddingFile::TMP_FILE));
+
+        // Since both the body file and header have been stored in the
+        // file-system, just make the action be resolve and let the padding file
+        // be restored in the next action.
+        rv = NS_OK;
       }
     }
 
     return rv;
   }
 
   // static
   nsresult