Bug 983334 - Missing yield when calling writeToFile. r=myk
authorMarco Castelluccio <mar.castelluccio@studenti.unina.it>
Thu, 13 Mar 2014 16:22:04 -0700
changeset 173509 e220d12f5d8d472c72622cf84ca45a26772d0599
parent 173508 905e547383b8c4fe573fdd12a3eb40d302c6a12e
child 173510 8bedaf29d461909a38112091a15d3b0097814571
push id26407
push usercbook@mozilla.com
push dateFri, 14 Mar 2014 11:34:21 +0000
treeherdermozilla-central@0a5ec8ab99a2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmyk
bugs983334
milestone30.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 983334 - Missing yield when calling writeToFile. r=myk
toolkit/webapps/WebappsInstaller.jsm
--- a/toolkit/webapps/WebappsInstaller.jsm
+++ b/toolkit/webapps/WebappsInstaller.jsm
@@ -340,17 +340,17 @@ WinNativeApp.prototype = {
    */
   install: function(aZipPath) {
     return Task.spawn(function() {
       yield this._getInstallDir();
 
       try {
         yield this._createDirectoryStructure();
         yield this._copyPrebuiltFiles();
-        this._createConfigFiles();
+        yield this._createConfigFiles();
 
         if (aZipPath) {
           yield OS.File.move(aZipPath, OS.Path.join(this.tmpInstallDir,
                                                     "application.zip"));
         }
 
         yield this.getIcon();
 
@@ -474,18 +474,18 @@ WinNativeApp.prototype = {
                        OS.Path.join(this.tmpInstallDir, this.uninstallerFile));
   },
 
   /**
    * Creates the configuration files into their destination folders.
    */
   _createConfigFiles: function() {
     // ${InstallDir}/webapp.json
-    writeToFile(OS.Path.join(this.tmpInstallDir, this.configJson),
-                JSON.stringify(this.webappJson));
+    yield writeToFile(OS.Path.join(this.tmpInstallDir, this.configJson),
+                      JSON.stringify(this.webappJson));
 
     let factory = Cc["@mozilla.org/xpcom/ini-processor-factory;1"]
                     .getService(Ci.nsIINIParserFactory);
 
     // ${InstallDir}/webapp.ini
     let webappINIfile = getFile(this.tmpInstallDir, this.webappINI);
 
     let writer = factory.createINIParser(webappINIfile)
@@ -510,19 +510,19 @@ WinNativeApp.prototype = {
       "File: \\webapp.ini\r\n" +
       "File: \\webapp.json\r\n" +
       "File: \\webapprt.old\r\n" +
       "File: \\chrome\\icons\\default\\default.ico";
     if (this.isPackaged) {
       uninstallContent += "\r\nFile: \\application.zip";
     }
 
-    writeToFile(OS.Path.join(this.tmpInstallDir, this.uninstallDir,
-                             "uninstall.log"),
-                uninstallContent);
+    yield writeToFile(OS.Path.join(this.tmpInstallDir, this.uninstallDir,
+                                   "uninstall.log"),
+                      uninstallContent);
   },
 
   /**
    * Writes the keys to the system registry that are necessary for the app operation
    * and uninstall process.
    */
   _writeSystemKeys: function() {
     let parentKey;
@@ -670,17 +670,17 @@ MacNativeApp.prototype = {
 
   install: function(aZipPath) {
     return Task.spawn(function() {
       yield this._getInstallDir();
 
       try {
         yield this._createDirectoryStructure();
         this._copyPrebuiltFiles();
-        this._createConfigFiles();
+        yield this._createConfigFiles();
 
         if (aZipPath) {
           yield OS.File.move(aZipPath, OS.Path.join(this.tmpInstallDir,
                                                     "application.zip"));
         }
 
         yield this.getIcon();
 
@@ -756,18 +756,18 @@ MacNativeApp.prototype = {
   _copyPrebuiltFiles: function() {
     let destDir = getFile(this.tmpInstallDir, this.macOSDir);
     let stub = getFile(this.runtimeFolder, "webapprt-stub");
     stub.copyTo(destDir, "webapprt");
   },
 
   _createConfigFiles: function() {
     // ${ProfileDir}/webapp.json
-    writeToFile(OS.Path.join(this.appProfileDir, "webapp.json"),
-                JSON.stringify(this.webappJson));
+    yield writeToFile(OS.Path.join(this.appProfileDir, "webapp.json"),
+                      JSON.stringify(this.webappJson));
 
     // ${InstallDir}/Contents/MacOS/webapp.ini
     let applicationINI = getFile(this.tmpInstallDir, this.macOSDir, "webapp.ini");
 
     let writer = Cc["@mozilla.org/xpcom/ini-processor-factory;1"]
                    .getService(Ci.nsIINIParserFactory)
                    .createINIParser(applicationINI)
                    .QueryInterface(Ci.nsIINIParserWriter);
@@ -803,18 +803,18 @@ MacNativeApp.prototype = {
     <true/>\n\
     <key>NSPrincipalClass</key>\n\
     <string>GeckoNSApplication</string>\n\
     <key>FirefoxBinary</key>\n\
 #expand     <string>__MOZ_MACBUNDLE_ID__</string>\n\
   </dict>\n\
 </plist>';
 
-    writeToFile(OS.Path.join(this.tmpInstallDir, this.contentsDir, "Info.plist"),
-                infoPListContent);
+    yield writeToFile(OS.Path.join(this.tmpInstallDir, this.contentsDir, "Info.plist"),
+                      infoPListContent);
   },
 
   /**
    * Process the icon from the imageStream as retrieved from
    * the URL by getIconForApp(). This will bundle the icon to the
    * app package at Contents/Resources/appicon.icns.
    *
    * @param aMimeType     the icon mimetype
@@ -874,17 +874,17 @@ LinuxNativeApp.prototype = {
 
   install: function(aZipPath) {
     return Task.spawn(function() {
       this._getInstallDir();
 
       try {
         this._createDirectoryStructure();
         this._copyPrebuiltFiles();
-        this._createConfigFiles();
+        yield this._createConfigFiles();
 
         if (aZipPath) {
           yield OS.File.move(aZipPath, OS.Path.join(this.tmpInstallDir,
                                                     "application.zip"));
         }
 
         yield this.getIcon();
 
@@ -990,18 +990,18 @@ LinuxNativeApp.prototype = {
       }
     }
 
     return categories;
   },
 
   _createConfigFiles: function() {
     // ${InstallDir}/webapp.json
-    writeToFile(OS.Path.join(this.tmpInstallDir, this.configJson),
-                JSON.stringify(this.webappJson));
+    yield writeToFile(OS.Path.join(this.tmpInstallDir, this.configJson),
+                      JSON.stringify(this.webappJson));
 
     let webappsBundle = Services.strings.createBundle("chrome://global/locale/webapps.properties");
 
     // ${InstallDir}/webapp.ini
     let webappINIfile = getFile(this.tmpInstallDir, this.webappINI);
 
     let writer = Cc["@mozilla.org/xpcom/ini-processor-factory;1"]
                    .getService(Ci.nsIINIParserFactory)
@@ -1085,19 +1085,25 @@ LinuxNativeApp.prototype = {
  * Async write a data string into a file
  *
  * @param aPath     the path to the file to write to
  * @param aData     a string with the data to be written
  */
 function writeToFile(aPath, aData) {
   return Task.spawn(function() {
     let data = new TextEncoder().encode(aData);
-    let file = yield OS.File.open(aPath, { truncate: true }, { unixMode: PERMS_FILE });
-    yield file.write(data);
-    yield file.close();
+
+    let file;
+    try {
+      file = yield OS.File.open(aPath, { truncate: true, write: true },
+                                { unixMode: PERMS_FILE });
+      yield file.write(data);
+    } finally {
+      yield file.close();
+    }
   });
 }
 
 /**
  * Removes unprintable characters from a string.
  */
 function sanitize(aStr) {
   let unprintableRE = new RegExp("[\\x00-\\x1F\\x7F]" ,"gi");