commit c27941def7c3819c60701d08663ba4a652601d58
parent 38c28eb272347ebb952f495c80694485e4bae91c
Author: Nicholas Rishel <nrishel@mozilla.com>
Date: Tue, 28 Oct 2025 00:21:15 +0000
Bug 1993732 - Exceptions from deleting the last backup should not prevent the backup location from changing. r=sthompson
Differential Revision: https://phabricator.services.mozilla.com/D269910
Diffstat:
2 files changed, 65 insertions(+), 1 deletion(-)
diff --git a/browser/components/backup/BackupService.sys.mjs b/browser/components/backup/BackupService.sys.mjs
@@ -4367,7 +4367,14 @@ export class BackupService extends EventTarget {
}
// If the location changed, delete the last backup there if one exists.
- await this.deleteLastBackup();
+ try {
+ await this.deleteLastBackup();
+ } catch {
+ lazy.logConsole.error(
+ "Error deleting last backup while editing the backup location."
+ );
+ // Fall through so the new backup directory is set.
+ }
this.setParentDirPath(path);
}
diff --git a/browser/components/backup/tests/xpcshell/test_BackupService.js b/browser/components/backup/tests/xpcshell/test_BackupService.js
@@ -807,6 +807,63 @@ add_task(
);
/**
+ * Tests that failure to delete the prior backup doesn't prevent the backup
+ * location from being edited.
+ */
+add_task(
+ async function test_editBackupLocation_robustToDeleteLastBackupException() {
+ const backupLocationPref = "browser.backup.location";
+ const resetLocation = Services.prefs.getStringPref(backupLocationPref);
+
+ const exceptionBackupLocation = await IOUtils.createUniqueDirectory(
+ PathUtils.tempDir,
+ "exceptionBackupLocation"
+ );
+ Services.prefs.setStringPref(backupLocationPref, exceptionBackupLocation);
+
+ const newBackupLocation = await IOUtils.createUniqueDirectory(
+ PathUtils.tempDir,
+ "newBackupLocation"
+ );
+
+ let pickerDir = await IOUtils.getDirectory(newBackupLocation);
+ const reg = MockRegistrar.register("@mozilla.org/filepicker;1", {
+ init() {},
+ open(cb) {
+ cb.done(Ci.nsIFilePicker.returnOK);
+ },
+ displayDirectory: null,
+ file: pickerDir,
+ QueryInterface: ChromeUtils.generateQI(["nsIFilePicker"]),
+ });
+
+ const backupService = new BackupService({});
+
+ const sandbox = sinon.createSandbox();
+ sandbox
+ .stub(backupService, "deleteLastBackup")
+ .rejects(new Error("Exception while deleting backup"));
+
+ await backupService.editBackupLocation({ browsingContext: null });
+
+ pickerDir.append("Restore Firefox");
+ Assert.equal(
+ Services.prefs.getStringPref(backupLocationPref),
+ pickerDir.path,
+ "Backup location pref should have updated to the new directory."
+ );
+
+ Services.prefs.setStringPref(backupLocationPref, resetLocation);
+ sinon.restore();
+ MockRegistrar.unregister(reg);
+ await Promise.all([
+ IOUtils.remove(exceptionBackupLocation, { recursive: true }),
+ IOUtils.remove(newBackupLocation, { recursive: true }),
+ ]);
+ }
+);
+
+/**
* Tests that if there's a post-recovery.json file in the profile directory
* when checkForPostRecovery() is called, that it is processed, and the
* postRecovery methods on the associated BackupResources are called with the