Bug 1469348 - Fix the problem of download file failed on Mac. r=paolo

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.

Differential Revision: https://phabricator.services.mozilla.com/D3400

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alphan Chen 2018-08-17 16:40:02 +00:00
parent 3a260706b3
commit 4b85350209

View File

@ -490,10 +490,16 @@ BackgroundFileSaver::ProcessStateChange()
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.