bug 526821: 1.4rc1 Undo a Personas Change cause Error in the Error Console client-1.4
authorJose E. Bolanos<jose@appcoast.com>
Tue, 10 Nov 2009 16:17:10 -0800
branchclient-1.4
changeset 1220 3736efdff34af3fc06e0c33aa1fc62728aa570dc
parent 1219 bdc99d5b6d606413cfab649c8b01739b38a8f4cb
child 1221 2c226b9a603fceb6639a3a42a201eaade6e6f46b
push id778
push usermyk@mozilla.com
push dateWed, 11 Nov 2009 00:19:44 +0000
bugs526821
bug 526821: 1.4rc1 Undo a Personas Change cause Error in the Error Console
client/modules/service.js
--- a/client/modules/service.js
+++ b/client/modules/service.js
@@ -632,17 +632,17 @@ let PersonaService = {
     // Show the notification if the selected persona is not in the favorite or
     // recent lists.
     if (!inRecent && !inFavorites)
       this._showPersonaChangeNotification();
   },
 
   /**
    * Reverts the current persona to the previously selected persona, if
-   * available                                    
+   * available
    */
   revertToPreviousPersona : function() {
     let previousPersona = this._prefs.get("lastselected1");
     if (previousPersona) {
       this.currentPersona = JSON.parse(previousPersona);
       this._revertRecent();
       this.selected = "current";
       this.resetPersona();
@@ -651,17 +651,17 @@ let PersonaService = {
 
   /**
    * Shows a notification displaying the currently selected persona and button
    * to revert the changes.
    */
   _showPersonaChangeNotification : function() {
     // Obtain most recent window and its notification box
     let wm =
-      Cc["@mozilla.org/appshell/window-mediator;1"].  
+      Cc["@mozilla.org/appshell/window-mediator;1"].
         getService(Ci.nsIWindowMediator);
     let window = wm.getMostRecentWindow("navigator:browser");
     let notificationBox = window.getBrowser().getNotificationBox();
 
     let message = this._strings.get(
       "notification.personaSelected", [this.currentPersona.name,
                                        (this.currentPersona.display_username ? this.currentPersona.display_username : this.currentPersona.author)]);
 
@@ -953,30 +953,32 @@ let PersonaService = {
 
     // Create directory for the given persona
     let personaDir = FileUtils.getDirectory(cacheDirectory, aPersona.id);
 
     // Save header
     let headerURI = URI.get(aPersona.headerURL, null, URI.get(this.dataURL));
     let headerCallback = function(aEvent) {
       let request = aEvent.target;
-      if (request.status == 200) {
+      // Save only if the folder still exists (Could have been deleted already)
+      if (request.status == 200 && personaDir.exists()) {
         FileUtils.writeBinaryFile(
           personaDir.clone(),
           "header" + FileUtils.getFileExtension(aPersona.headerURL),
           request.responseText);
       }
     };
     this._makeRequest(headerURI.spec, headerCallback, null, true);
 
     // Save footer
     let footerURI = URI.get(aPersona.footerURL, null, URI.get(this.dataURL));
     let footerCallback = function(aEvent) {
       let request = aEvent.target;
-      if (request.status == 200) {
+      // Save only if the folder still exists (Could have been deleted already)
+      if (request.status == 200 && personaDir.exists()) {
         FileUtils.writeBinaryFile(
           personaDir.clone(),
           "footer" + FileUtils.getFileExtension(aPersona.footerURL),
           request.responseText);
       }
     };
     this._makeRequest(footerURI.spec, footerCallback, null, true);
   },