From 0e662993fc70208078fa630d0534e6e4fa6eba6c Mon Sep 17 00:00:00 2001 From: Cristian Tuns Date: Tue, 14 May 2024 19:15:53 -0400 Subject: [PATCH] Backed out changeset 6e2699724abd (bug 1892249) for causing marionette failures in PathUtils.cpp CLOSED TREE --- .../components/backup/BackupService.sys.mjs | 104 +----------------- .../tests/xpcshell/test_BackupService.js | 28 +---- 2 files changed, 7 insertions(+), 125 deletions(-) diff --git a/browser/components/backup/BackupService.sys.mjs b/browser/components/backup/BackupService.sys.mjs index 3d7c4d91f6c5..05634ed2c8b3 100644 --- a/browser/components/backup/BackupService.sys.mjs +++ b/browser/components/backup/BackupService.sys.mjs @@ -29,10 +29,6 @@ ChromeUtils.defineESModuleGetters(lazy, { UIState: "resource://services-sync/UIState.sys.mjs", }); -ChromeUtils.defineLazyGetter(lazy, "ZipWriter", () => - Components.Constructor("@mozilla.org/zipwriter;1", "nsIZipWriter", "open") -); - /** * The BackupService class orchestrates the scheduling and creation of profile * backups. It also does most of the heavy lifting for the restoration of a @@ -188,15 +184,6 @@ export class BackupService extends EventTarget { return response.json(); } - /** - * The level of Zip compression to use on the zipped staging folder. - * - * @type {number} - */ - static get COMPRESSION_LEVEL() { - return Ci.nsIZipWriter.COMPRESSION_BEST; - } - /** * Returns a reference to a BackupService singleton. If this is the first time * that this getter is accessed, this causes the BackupService singleton to be @@ -395,13 +382,7 @@ export class BackupService extends EventTarget { "Wrote backup to staging directory at ", renamedStagingPath ); - - let compressedStagingPath = await this.#compressStagingFolder( - renamedStagingPath, - backupDirPath - ); - - return { stagingPath: renamedStagingPath, compressedStagingPath }; + return { stagingPath: renamedStagingPath }; } finally { this.#backupInProgress = false; } @@ -430,89 +411,6 @@ export class BackupService extends EventTarget { return stagingPath; } - /** - * Compresses a staging folder into a Zip file. If a pre-existing Zip file - * for a staging folder resides in destFolderPath, it is overwritten. The - * Zip file will have the same name as the stagingPath folder, with `.zip` - * as the extension. - * - * @param {string} stagingPath - * The path to the staging folder to be compressed. - * @param {string} destFolderPath - * The parent folder to write the Zip file to. - * @returns {Promise} - * Resolves with the path to the created Zip file. - */ - async #compressStagingFolder(stagingPath, destFolderPath) { - const PR_RDWR = 0x04; - const PR_CREATE_FILE = 0x08; - const PR_TRUNCATE = 0x20; - - let archivePath = PathUtils.join( - destFolderPath, - `${PathUtils.filename(stagingPath)}.zip` - ); - let archiveFile = await IOUtils.getFile(archivePath); - - let writer = new lazy.ZipWriter( - archiveFile, - PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE - ); - - lazy.logConsole.log("Compressing staging folder to ", archivePath); - let rootPathNSIFile = await IOUtils.getDirectory(stagingPath); - await this.#compressChildren(rootPathNSIFile, stagingPath, writer); - await new Promise(resolve => { - let observer = { - onStartRequest(_request) { - lazy.logConsole.debug("Starting to write out archive file"); - }, - onStopRequest(_request, status) { - lazy.logConsole.log("Done writing archive file"); - resolve(status); - }, - }; - writer.processQueue(observer, null); - }); - writer.close(); - - return archivePath; - } - - /** - * A helper function for #compressStagingFolder that iterates through a - * directory, and adds each file to a nsIZipWriter. For each directory it - * finds, it recurses. - * - * @param {nsIFile} rootPathNSIFile - * An nsIFile pointing at the root of the folder being compressed. - * @param {string} parentPath - * The path to the folder whose children should be iterated. - * @param {nsIZipWriter} writer - * The writer to add all of the children to. - * @returns {Promise} - */ - async #compressChildren(rootPathNSIFile, parentPath, writer) { - let children = await IOUtils.getChildren(parentPath); - for (let childPath of children) { - let childState = await IOUtils.stat(childPath); - if (childState.type == "directory") { - await this.#compressChildren(rootPathNSIFile, childPath, writer); - } else { - let childFile = await IOUtils.getFile(childPath); - let pathRelativeToRoot = childFile.getRelativePath(rootPathNSIFile); - let nonNativePath = - PathUtils.splitRelative(pathRelativeToRoot).join("/"); - writer.addEntryFile( - nonNativePath, - BackupService.COMPRESSION_LEVEL, - childFile, - true - ); - } - } - } - /** * Renames the staging folder to an ISO 8601 date string with dashes replacing colons and fractional seconds stripped off. * The ISO date string should be formatted from YYYY-MM-DDTHH:mm:ss.sssZ to YYYY-MM-DDTHH-mm-ssZ diff --git a/browser/components/backup/tests/xpcshell/test_BackupService.js b/browser/components/backup/tests/xpcshell/test_BackupService.js index ea331122b2b1..33fb9fbb9939 100644 --- a/browser/components/backup/tests/xpcshell/test_BackupService.js +++ b/browser/components/backup/tests/xpcshell/test_BackupService.js @@ -114,37 +114,21 @@ async function testCreateBackupHelper(sandbox, taskFn) { let backupsFolderPath = PathUtils.join(fakeProfilePath, "backups"); let stagingPath = PathUtils.join(backupsFolderPath, "staging"); - // For now, we expect a single backup only to be saved. There should also be - // a single compressed file for the staging folder. - let backupsChildren = await IOUtils.getChildren(backupsFolderPath); + // For now, we expect a single backup only to be saved. + let backups = await IOUtils.getChildren(backupsFolderPath); Assert.equal( - backupsChildren.length, - 2, - "There should only be 2 items in the backups folder" + backups.length, + 1, + "There should only be 1 backup in the backups folder" ); - // The folder and the compressed file should have the same filename, but - // the compressed file should have a `.zip` file extension. We sort the - // list of directory children to make sure that the folder is first in - // the array. - backupsChildren.sort(); - - let renamedFilename = await PathUtils.filename(backupsChildren[0]); + let renamedFilename = await PathUtils.filename(backups[0]); let expectedFormatRegex = /^\d{4}(-\d{2}){2}T(\d{2}-){2}\d{2}Z$/; Assert.ok( renamedFilename.match(expectedFormatRegex), "Renamed staging folder should have format YYYY-MM-DDTHH-mm-ssZ" ); - // We also expect a zipped version of that same folder to exist in the - // directory, with the same name along with a .zip extension. - let archiveFilename = await PathUtils.filename(backupsChildren[1]); - Assert.equal( - archiveFilename, - `${renamedFilename}.zip`, - "Compressed staging folder exists." - ); - let stagingPathRenamed = PathUtils.join(backupsFolderPath, renamedFilename); for (let backupResourceClass of [