Bug 1469348 - Fix the problem of download file failed on Mac. r=paolo, a=IanN CLOSED TREE DONTBUILD SEAMONKEY_2_49_ESR_RELBRANCH
authorAlphan Chen <alchen@mozilla.com>
Fri, 17 Aug 2018 16:40:02 +0000
branchSEAMONKEY_2_49_ESR_RELBRANCH
changeset 357542 d9407a1c48594c6ed20e7cbb4f8c24854afe0484
parent 357541 14da0f87d12c12f6ef9f8e82128d6ce500a2bba2
child 357543 9fa9839606c350c4654b8b9b4a4c67ec24a42fb0
push id7834
push userfrgrahl@gmx.net
push dateSun, 13 Jan 2019 12:17:02 +0000
treeherdermozilla-esr52@6e4ad8a8f2e8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspaolo, IanN
bugs1469348
milestone52.9.1
Bug 1469348 - Fix the problem of download file failed on Mac. r=paolo, a=IanN CLOSED TREE DONTBUILD mozilla-esr52 SEAMONKEY_2_49_ESR_RELBRANCH In this bug, we will focus on the problem of cannot download PDF file from google drawing successfully on MAC. After investigating, I found that "SetTarget()" is called twice with two different addresses. However, they both point to the same file. We will assign the first target to "mInitialTarget" and the second one to "mRenamedTarget". This problem happened when doing the second "SetTarget()". After canceling the existing AsyncCopy, we will schedule a new AsyncCopy. However, we only assign the mActualTarget with mRenamedTarget when they point to different files. In this case, the two different addresses point to the same file. So the mActualTarget is still the same as mInitialTarget. After completion of the AsyncCopy, we try to do "CheckCompletion". But it will always return false due to "mRenamedTarget exists" and "mActualTarget" is not the same as "mRenamedTarget". The solution is quite easy. We should always update mActualTarget with renameTarget, even if they point to the same file.
netwerk/base/BackgroundFileSaver.cpp
--- a/netwerk/base/BackgroundFileSaver.cpp
+++ b/netwerk/base/BackgroundFileSaver.cpp
@@ -499,20 +499,26 @@ BackgroundFileSaver::ProcessStateChange(
         // Move the file.  If this fails, we still reference the original file
         // in mActualTarget, so that it is deleted if requested.  If this
         // succeeds, the nsIFile instance referenced by mActualTarget mutates
         // and starts pointing to the new file, but we'll discard the reference.
         rv = mActualTarget->MoveTo(renamedTargetParentDir, renamedTargetName);
         NS_ENSURE_SUCCESS(rv, rv);
       }
 
-      // Now we can update the actual target file name.
-      mActualTarget = renamedTarget;
-      mActualTargetKeepPartial = renamedTargetKeepPartial;
+      // We should not only update the mActualTarget with renameTarget when
+      // they point to the different files.
+      // In this way, if mActualTarget and renamedTarget point to the same file
+      // with different addresses, "CheckCompletion()" will return false forever.
     }
+
+    // Update mActualTarget with renameTarget,
+    // even if they point to the same file.
+    mActualTarget = renamedTarget;
+    mActualTargetKeepPartial = renamedTargetKeepPartial;
   }
 
   // Notify if the target file name actually changed.
   if (!equalToCurrent) {
     // We must clone the nsIFile instance because mActualTarget is not
     // immutable, it may change if the target is renamed later.
     nsCOMPtr<nsIFile> actualTargetToNotify;
     rv = mActualTarget->Clone(getter_AddRefs(actualTargetToNotify));