Skip to content

Commit

Permalink
Bug 1838432 - Only check for read permissions on Safari files when th…
Browse files Browse the repository at this point in the history
…e files exist. r=mstriemer

Differential Revision: https://phabricator.services.mozilla.com/D183538
  • Loading branch information
mikeconley committed Jul 25, 2023
1 parent 81e1964 commit 929f4a5
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions browser/components/migration/SafariProfileMigrator.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,8 @@ export class SafariProfileMigrator extends MigratorBase {
if (this._hasPermissions) {
return true;
}
// Check if we have access to both bookmarks and favicons:
// Check if we have access to some key files, but only if they exist.
let historyTarget = FileUtils.getDir("ULibDir", ["Safari", "History.db"]);
let bookmarkTarget = FileUtils.getDir("ULibDir", [
"Safari",
"Bookmarks.plist",
Expand All @@ -599,10 +600,21 @@ export class SafariProfileMigrator extends MigratorBase {
"favicons.db",
]);
try {
// 'stat' is always allowed, but reading is somehow not, if the user hasn't
// allowed it:
await IOUtils.read(bookmarkTarget.path, { maxBytes: 1 });
await IOUtils.read(faviconTarget.path, { maxBytes: 1 });
let historyExists = await IOUtils.exists(historyTarget.path);
let bookmarksExists = await IOUtils.exists(bookmarkTarget.path);
let faviconsExists = await IOUtils.exists(faviconTarget.path);
// We now know which files exist, which is always allowed.
// To determine if we have read permissions, try to read a single byte
// from each file that exists, which will throw if we need permissions.
if (historyExists) {
await IOUtils.read(historyTarget.path, { maxBytes: 1 });
}
if (bookmarksExists) {
await IOUtils.read(bookmarkTarget.path, { maxBytes: 1 });
}
if (faviconsExists) {
await IOUtils.read(faviconTarget.path, { maxBytes: 1 });
}
this._hasPermissions = true;
return true;
} catch (ex) {
Expand Down

0 comments on commit 929f4a5

Please sign in to comment.