tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 677297fdcfb5edc12be0ee588810a988b06e7949
parent 8f931cc8aa6dcd2a5769ac87d9b61587ef5d1d80
Author: Duncan McIntosh <dmcintosh@mozilla.com>
Date:   Wed,  5 Nov 2025 22:08:37 +0000

Bug 1992286 - Don't add BACKUP_DIR_NAME to the backup location if it's already there. r=kpatenio,cdupuis

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

Diffstat:
Mbrowser/components/backup/BackupService.sys.mjs | 15+++++++++------
Abrowser/components/backup/tests/xpcshell/test_BackupService_setParentDirPath.js | 42++++++++++++++++++++++++++++++++++++++++++
Mbrowser/components/backup/tests/xpcshell/xpcshell.toml | 2++
3 files changed, 53 insertions(+), 6 deletions(-)

diff --git a/browser/components/backup/BackupService.sys.mjs b/browser/components/backup/BackupService.sys.mjs @@ -3369,17 +3369,20 @@ export class BackupService extends EventTarget { */ setParentDirPath(parentDirPath) { try { - if (!parentDirPath || !PathUtils.filename(parentDirPath)) { + let filename = parentDirPath ? PathUtils.filename(parentDirPath) : null; + if (!filename) { throw new BackupError( "Parent directory path is invalid.", ERRORS.FILE_SYSTEM_ERROR ); } - // Recreate the backups path with the new parent directory. - let fullPath = PathUtils.join( - parentDirPath, - BackupService.BACKUP_DIR_NAME - ); + + let fullPath = parentDirPath; + if (filename != BackupService.BACKUP_DIR_NAME) { + // Recreate the backups path with the new parent directory. + fullPath = PathUtils.join(parentDirPath, BackupService.BACKUP_DIR_NAME); + } + Services.prefs.setStringPref(BACKUP_DIR_PREF_NAME, fullPath); } catch (e) { lazy.logConsole.error( diff --git a/browser/components/backup/tests/xpcshell/test_BackupService_setParentDirPath.js b/browser/components/backup/tests/xpcshell/test_BackupService_setParentDirPath.js @@ -0,0 +1,42 @@ +/* Any copyright is dedicated to the Public Domain. +https://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +ChromeUtils.defineESModuleGetters(this, { + AppConstants: "resource://gre/modules/AppConstants.sys.mjs", + BackupError: "resource:///modules/backup/BackupError.mjs", +}); + +add_task(function test_empty() { + let bs = new BackupService(); + Assert.throws( + () => bs.setParentDirPath(""), + BackupError, + "empty string is rejected" + ); +}); + +add_task(function test_typical() { + let bs = new BackupService(); + let name = "setParentDirPath_typical"; + let path = PathUtils.join(do_get_profile().path, name); + bs.setParentDirPath(path); + Assert.equal( + Services.prefs.getStringPref("browser.backup.location"), + PathUtils.join(path, "Restore Firefox"), + "Path with 'Restore Firefox' appended is used" + ); +}); + +add_task(function test_already_decorated() { + let bs = new BackupService(); + let name = "setParentDirPath_already_decorated"; + let path = PathUtils.join(do_get_profile().path, name, "Restore Firefox"); + bs.setParentDirPath(path); + Assert.equal( + Services.prefs.getStringPref("browser.backup.location"), + path, + "No duplicate 'Restore Firefox' is appended" + ); +}); diff --git a/browser/components/backup/tests/xpcshell/xpcshell.toml b/browser/components/backup/tests/xpcshell/xpcshell.toml @@ -64,6 +64,8 @@ run-sequentially = ["true"] # Mock Windows registry interferes with normal opera ["test_BackupService_schema_versions.js"] +["test_BackupService_setParentDirPath.js"] + ["test_BackupService_takeMeasurements.js"] ["test_BackupService_telemetry.js"]