Backed out changeset 6e2699724abd (bug 1892249) for causing marionette failures in PathUtils.cpp CLOSED TREE
This commit is contained in:
@@ -29,10 +29,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
|
|||||||
UIState: "resource://services-sync/UIState.sys.mjs",
|
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
|
* The BackupService class orchestrates the scheduling and creation of profile
|
||||||
* backups. It also does most of the heavy lifting for the restoration of a
|
* 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();
|
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
|
* 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
|
* 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 ",
|
"Wrote backup to staging directory at ",
|
||||||
renamedStagingPath
|
renamedStagingPath
|
||||||
);
|
);
|
||||||
|
return { stagingPath: renamedStagingPath };
|
||||||
let compressedStagingPath = await this.#compressStagingFolder(
|
|
||||||
renamedStagingPath,
|
|
||||||
backupDirPath
|
|
||||||
);
|
|
||||||
|
|
||||||
return { stagingPath: renamedStagingPath, compressedStagingPath };
|
|
||||||
} finally {
|
} finally {
|
||||||
this.#backupInProgress = false;
|
this.#backupInProgress = false;
|
||||||
}
|
}
|
||||||
@@ -430,89 +411,6 @@ export class BackupService extends EventTarget {
|
|||||||
return stagingPath;
|
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<string>}
|
|
||||||
* 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<undefined>}
|
|
||||||
*/
|
|
||||||
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.
|
* 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
|
* The ISO date string should be formatted from YYYY-MM-DDTHH:mm:ss.sssZ to YYYY-MM-DDTHH-mm-ssZ
|
||||||
|
|||||||
@@ -114,37 +114,21 @@ async function testCreateBackupHelper(sandbox, taskFn) {
|
|||||||
let backupsFolderPath = PathUtils.join(fakeProfilePath, "backups");
|
let backupsFolderPath = PathUtils.join(fakeProfilePath, "backups");
|
||||||
let stagingPath = PathUtils.join(backupsFolderPath, "staging");
|
let stagingPath = PathUtils.join(backupsFolderPath, "staging");
|
||||||
|
|
||||||
// For now, we expect a single backup only to be saved. There should also be
|
// For now, we expect a single backup only to be saved.
|
||||||
// a single compressed file for the staging folder.
|
let backups = await IOUtils.getChildren(backupsFolderPath);
|
||||||
let backupsChildren = await IOUtils.getChildren(backupsFolderPath);
|
|
||||||
Assert.equal(
|
Assert.equal(
|
||||||
backupsChildren.length,
|
backups.length,
|
||||||
2,
|
1,
|
||||||
"There should only be 2 items in the backups folder"
|
"There should only be 1 backup in the backups folder"
|
||||||
);
|
);
|
||||||
|
|
||||||
// The folder and the compressed file should have the same filename, but
|
let renamedFilename = await PathUtils.filename(backups[0]);
|
||||||
// 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 expectedFormatRegex = /^\d{4}(-\d{2}){2}T(\d{2}-){2}\d{2}Z$/;
|
let expectedFormatRegex = /^\d{4}(-\d{2}){2}T(\d{2}-){2}\d{2}Z$/;
|
||||||
Assert.ok(
|
Assert.ok(
|
||||||
renamedFilename.match(expectedFormatRegex),
|
renamedFilename.match(expectedFormatRegex),
|
||||||
"Renamed staging folder should have format YYYY-MM-DDTHH-mm-ssZ"
|
"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);
|
let stagingPathRenamed = PathUtils.join(backupsFolderPath, renamedFilename);
|
||||||
|
|
||||||
for (let backupResourceClass of [
|
for (let backupResourceClass of [
|
||||||
|
|||||||
Reference in New Issue
Block a user