Bug 1028983 - Set file permissions using OS.File. r=marco
authorSunny <indiasuny000@gmail.com>
Tue, 14 Oct 2014 13:10:00 +0200
changeset 210595 400b8c7a7f0157290be1064f7ae1f3df459f936b
parent 210594 42a182f0431fb873eeba2bde9ec240db78680cbe
child 210596 683d12c284ff968611f7a1d7609330ae5970cb80
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersmarco
bugs1028983
milestone36.0a1
Bug 1028983 - Set file permissions using OS.File. r=marco
toolkit/webapps/LinuxNativeApp.js
toolkit/webapps/MacNativeApp.js
toolkit/webapps/tests/head.js
toolkit/webapps/tests/test_hosted.xul
toolkit/webapps/tests/test_packaged.xul
--- a/toolkit/webapps/LinuxNativeApp.js
+++ b/toolkit/webapps/LinuxNativeApp.js
@@ -161,17 +161,17 @@ NativeApp.prototype = {
       yield OS.File.removeDir(backupDir, { ignoreAbsent: true });
       yield OS.File.removeDir(updateDir, { ignoreAbsent: true });
     }
   }),
 
   _applyTempInstallation: Task.async(function*(aTmpDir, aInstallDir) {
     yield moveDirectory(aTmpDir, aInstallDir);
 
-    this._createSystemFiles(aInstallDir);
+    yield this._createSystemFiles(aInstallDir);
   }),
 
   _removeInstallation: function(keepProfile, aInstallDir) {
     let filesToRemove = [this.desktopINI];
 
     if (keepProfile) {
       for (let filePath of this.backupFiles) {
         filesToRemove.push(OS.Path.join(aInstallDir, filePath));
@@ -268,17 +268,17 @@ NativeApp.prototype = {
     writer.setString("Webapp", "UninstallMsg",
                      webappsBundle.formatStringFromName("uninstall.notification",
                                                         [this.appLocalizedName],
                                                         1));
     writer.setString("WebappRT", "InstallDir", this.runtimeFolder);
     writer.writeFile();
   },
 
-  _createSystemFiles: function(aInstallDir) {
+  _createSystemFiles: Task.async(function*(aInstallDir) {
     let webappsBundle = Services.strings.createBundle("chrome://global/locale/webapps.properties");
 
     let webapprtPath = OS.Path.join(aInstallDir, this.webapprt);
 
     // $XDG_DATA_HOME/applications/owa-<webappuniquename>.desktop
     let desktopINIfile = getFile(this.desktopINI);
     if (desktopINIfile.parent && !desktopINIfile.parent.exists()) {
       desktopINIfile.parent.create(Ci.nsIFile.DIRECTORY_TYPE, PERMS_DIRECTORY);
@@ -301,18 +301,18 @@ NativeApp.prototype = {
       writer.setString("Desktop Entry", "Categories", categories);
 
     writer.setString("Desktop Entry", "Actions", "Uninstall;");
     writer.setString("Desktop Action Uninstall", "Name", webappsBundle.GetStringFromName("uninstall.label"));
     writer.setString("Desktop Action Uninstall", "Exec", webapprtPath + " -remove");
 
     writer.writeFile();
 
-    desktopINIfile.permissions = PERMS_FILE | OS.Constants.libc.S_IXUSR;
-  },
+    yield OS.File.setPermissions(desktopINIfile.path, { unixMode: PERMS_FILE | OS.Constants.libc.S_IXUSR });
+  }),
 
   /**
    * Process the icon from the imageStream as retrieved from
    * the URL by getIconForApp().
    *
    * @param aMimeType     ahe icon mimetype
    * @param aImageStream  the stream for the image data
    * @param aDir          the directory where the icon should be stored
--- a/toolkit/webapps/MacNativeApp.js
+++ b/toolkit/webapps/MacNativeApp.js
@@ -236,17 +236,17 @@ NativeApp.prototype = {
 
     let writer = Cc["@mozilla.org/xpcom/ini-processor-factory;1"].
                  getService(Ci.nsIINIParserFactory).
                  createINIParser(applicationINI).
                  QueryInterface(Ci.nsIINIParserWriter);
     writer.setString("Webapp", "Name", this.appLocalizedName);
     writer.setString("Webapp", "Profile", this.uniqueName);
     writer.writeFile();
-    applicationINI.permissions = PERMS_FILE;
+    yield OS.File.setPermissions(applicationINI.path, { unixMode: PERMS_FILE });
 
     // ${InstallDir}/Contents/Info.plist
     let infoPListContent = '<?xml version="1.0" encoding="UTF-8"?>\n\
 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n\
 <plist version="1.0">\n\
   <dict>\n\
     <key>CFBundleDevelopmentRegion</key>\n\
     <string>English</string>\n\
--- a/toolkit/webapps/tests/head.js
+++ b/toolkit/webapps/tests/head.js
@@ -160,36 +160,36 @@ function TestAppInfo(aApp, aIsPackaged) 
 
     let xdg_data_home = Cc["@mozilla.org/process/environment;1"].
                         getService(Ci.nsIEnvironment).
                         get("XDG_DATA_HOME");
     if (!xdg_data_home) {
       xdg_data_home = OS.Path.join(OS.Constants.Path.homeDir, ".local", "share");
     }
 
-    let desktopINI = OS.Path.join(xdg_data_home, "applications",
+    this.desktopINI = OS.Path.join(xdg_data_home, "applications",
                                   "owa-" + this.uniqueName + ".desktop");
 
     this.installedFiles = [
       OS.Path.join(this.installPath, "webapp.json"),
       this.webappINI,
       this.iconFile,
       this.exePath,
-      desktopINI,
+      this.desktopINI,
     ];
     this.tempUpdatedFiles = [
       OS.Path.join(this.installPath, "update", "icon.png"),
       OS.Path.join(this.installPath, "update", "webapp.json"),
       OS.Path.join(this.installPath, "update", "webapp.ini"),
     ];
     this.updatedFiles = [
       OS.Path.join(this.installPath, "webapp.json"),
       this.webappINI,
       this.iconFile,
-      desktopINI,
+      this.desktopINI,
     ];
 
     if (this.isPackaged) {
       let appZipPath = OS.Path.join(this.installPath, "application.zip");
       this.installedFiles.push(appZipPath);
       this.tempUpdatedFiles.push(appZipPath);
       this.updatedFiles.push(appZipPath);
     }
@@ -204,17 +204,17 @@ function TestAppInfo(aApp, aIsPackaged) 
       }
 
       yield OS.File.removeDir(this.cacheRoot, { ignoreAbsent: true });
 
       yield OS.File.removeDir(this.profileRoot, { ignoreAbsent: true });
 
       yield OS.File.removeDir(this.installPath, { ignoreAbsent: true });
 
-      yield OS.File.remove(desktopINI, { ignoreAbsent: true });
+      yield OS.File.remove(this.desktopINI, { ignoreAbsent: true });
     });
   } else if (WIN) {
     this.installPath = OS.Path.join(OS.Constants.Path.winAppDataDir,
                                     this.uniqueName);
     this.exePath = OS.Path.join(this.installPath, aApp.name + ".exe");
 
     this.iconFile = OS.Path.join(this.installPath, "chrome", "icons", "default", "default.ico");
 
--- a/toolkit/webapps/tests/test_hosted.xul
+++ b/toolkit/webapps/tests/test_hosted.xul
@@ -101,16 +101,25 @@ let runTest = Task.async(function*() {
   ok((yield checkFiles(testAppInfo.installedFiles)), "Installation not corrupted");
   ok((yield checkFiles(testAppInfo.tempUpdatedFiles)), "Files correctly written in the update subdirectory");
 
   yield nativeApp.applyUpdate(app);
   while (!WebappOSUtils.isLaunchable(app)) {
     yield wait(1000);
   }
   ok(true, "App launchable");
+
+  if (MAC) {
+    stat = yield OS.File.stat(testAppInfo.webappINI);
+    is(stat.unixMode, 0o644, "Configuration file permissions correct");
+  } else if (LINUX) {
+    stat = yield OS.File.stat(testAppInfo.desktopINI);
+    is(stat.unixMode, 0o744, "Configuration file permissions correct");
+  }
+
   ok((yield checkFiles(testAppInfo.installedFiles)), "Installation not corrupted");
   ok(!(yield OS.File.exists(OS.Path.join(testAppInfo.installPath, "update"))), "Update directory removed");
   ok((yield checkDateHigherThan(testAppInfo.updatedFiles, installTime)), "Modification date higher");
 
   stat = yield OS.File.stat(testAppInfo.installPath);
   installTime = stat.lastModificationDate;
 
   // Wait one second, otherwise the last modification date is the same.
--- a/toolkit/webapps/tests/test_packaged.xul
+++ b/toolkit/webapps/tests/test_packaged.xul
@@ -114,16 +114,25 @@ let runTest = Task.async(function*() {
   ok((yield checkFiles(testAppInfo.installedFiles)), "Installation not corrupted");
   ok((yield checkFiles(testAppInfo.tempUpdatedFiles)), "Files correctly written in the update subdirectory");
 
   yield nativeApp.applyUpdate(app);
   while (!WebappOSUtils.isLaunchable(app)) {
     yield wait(1000);
   }
   ok(true, "App launchable");
+
+  if (MAC) {
+    stat = yield OS.File.stat(testAppInfo.webappINI);
+    is(stat.unixMode, 0o644, "Configuration file permissions correct");
+  } else if (LINUX) {
+    stat = yield OS.File.stat(testAppInfo.desktopINI);
+    is(stat.unixMode, 0o744, "Configuration file permissions correct");
+  }
+
   ok((yield checkFiles(testAppInfo.installedFiles)), "Installation not corrupted");
   ok(!(yield OS.File.exists(OS.Path.join(testAppInfo.installPath, "update"))), "Update directory removed");
   ok((yield checkDateHigherThan(testAppInfo.updatedFiles, installTime)), "Modification date higher");
 
   stat = yield OS.File.stat(testAppInfo.installPath);
   installTime = stat.lastModificationDate;
 
   // Wait one second, otherwise the last modification date is the same.