From ecbe89cd7d4aef01de3f63033f50968f8cafe158 Mon Sep 17 00:00:00 2001 From: FranklinDM Date: Thu, 7 Apr 2022 18:11:40 +0800 Subject: Issue #1822 - Follow-up: Restore method that moves downloaded data's part file This commit fixes the issue where all downloaded files are empty/zero-byte by creating a new `_move` method, which is called in place of the removed `_checkReputationAndMove` method. In 6042fdd44c0ec532b3e33d4f4046826fa1548d13 the reputation check for downloads was removed but that same method is also being used for moving the part file of completed downloads, which consequently broke all downloads except those without a part file, and made them empty since the actual downloaded file isn't being moved. --- .../components/jsdownloads/src/DownloadCore.jsm | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/toolkit/components/jsdownloads/src/DownloadCore.jsm b/toolkit/components/jsdownloads/src/DownloadCore.jsm index da1a740fb7..4be4911a66 100644 --- a/toolkit/components/jsdownloads/src/DownloadCore.jsm +++ b/toolkit/components/jsdownloads/src/DownloadCore.jsm @@ -2167,6 +2167,7 @@ this.DownloadCopySaver.prototype = { // up the chain of objects for the download. yield deferSaveComplete.promise; + yield this._move(); } catch (ex) { // Ensure we always remove the placeholder for the final target file on // failure, independently of which code path failed. In some cases, the @@ -2188,6 +2189,23 @@ this.DownloadCopySaver.prototype = { }.bind(this)); }, + /** + * Move the downloaded data if required. + * If the download is using a part file we will move it to the target path + * since this is the final step in the saver. + * + * @return {Promise} + * @resolves When the move is complete. + */ + _move: Task.async(function* () { + let targetPath = this.download.target.path; + let partFilePath = this.download.target.partFilePath; + + if (partFilePath) { + yield OS.File.move(partFilePath, targetPath); + } + }), + /** * Implements "DownloadSaver.cancel". */ @@ -2514,6 +2532,8 @@ this.DownloadLegacySaver.prototype = { } } } + + yield this._move(); } catch (ex) { // Ensure we always remove the final target file on failure, // independently of which code path failed. In some cases, the @@ -2546,6 +2566,11 @@ this.DownloadLegacySaver.prototype = { }.bind(this)); }, + _move: function () { + return DownloadCopySaver.prototype._move + .apply(this, arguments); + }, + /** * Implements "DownloadSaver.cancel". */ -- cgit v1.2.3