Bug 1530615: Remove missing profiles from the profile service when showing the profile manager or about:profiles. r=Gijs
authorDave Townsend <dtownsend@oxymoronical.com>
Thu, 07 Mar 2019 18:22:29 +0000
changeset 520860 455e57b39067
parent 520859 4256ff8a181c
child 520861 529994cea769
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1530615
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1530615: Remove missing profiles from the profile service when showing the profile manager or about:profiles. r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D22146
toolkit/content/aboutProfiles.js
toolkit/profile/content/profileSelection.js
--- a/toolkit/content/aboutProfiles.js
+++ b/toolkit/content/aboutProfiles.js
@@ -326,10 +326,31 @@ function restart(safeMode) {
   if (safeMode) {
     Services.startup.restartInSafeMode(flags);
   } else {
     Services.startup.quit(flags);
   }
 }
 
 window.addEventListener("DOMContentLoaded", function() {
+  // Check if any profiles are missing on the disk and if so remove them.
+  // We cannot remove profiles while iterating the list returned from the
+  // profile service, so convert it to a new array first.
+  try {
+    let changed = false;
+    for (let profile of [...ProfileService.profiles]) {
+      if (!profile.rootDir.exists() || !profile.rootDir.isDirectory()) {
+        profile.remove(false);
+        changed = true;
+      }
+    }
+
+    if (changed) {
+      ProfileService.flush();
+    }
+  } catch (e) {
+    // There shouldn't be any failures to catch here, but just in case let the
+    // UI build itself properly.
+    Cu.reportError(e);
+  }
+
   refreshUI();
 }, {once: true});
--- a/toolkit/profile/content/profileSelection.js
+++ b/toolkit/profile/content/profileSelection.js
@@ -19,16 +19,33 @@ var gProfileService;
 
 function startup() {
   try {
     gDialogParams = window.arguments[0].
       QueryInterface(I.nsIDialogParamBlock);
 
     gProfileService = C[ToolkitProfileService].getService(I.nsIToolkitProfileService);
 
+    // Check if any profiles are missing on the disk and if so remove them.
+    // We cannot remove profiles while iterating the list returned from the
+    // profile service, so convert it to a new array first.
+    try {
+      for (let profile of [...gProfileService.profiles]) {
+        if (!profile.rootDir.exists() || !profile.rootDir.isDirectory()) {
+          profile.remove(false);
+        }
+      }
+
+      // The profile service is always flushed after this dialog completes.
+    } catch (e) {
+      // There shouldn't be any failures to catch here, but just in case let the
+      // UI build itself properly.
+      Cu.reportError(e);
+    }
+
     gProfileManagerBundle = document.getElementById("bundle_profileManager");
     gBrandBundle = document.getElementById("bundle_brand");
 
     document.documentElement.centerWindowOnScreen();
 
     var profilesElement = document.getElementById("profiles");
 
     for (let profile of gProfileService.profiles.entries(I.nsIToolkitProfile)) {