Bug 761138 - Create/remove directories (Unix version). r=froydnj
authorDavid Rajchenbach-Teller <dteller@mozilla.com>
Fri, 24 Aug 2012 16:18:15 -0400
changeset 103339 f9b8fb3c9395aaadd36be46e36d8036d2bd0a216
parent 103338 62f13ac39e4c9c1fd2a24b0fbc6a83f460c64b1a
child 103340 d94e6c20c4dc9e1b6df52c73e723fda55948be70
push id13945
push userryanvm@gmail.com
push dateFri, 24 Aug 2012 20:18:14 +0000
treeherdermozilla-inbound@b3c861bd1e2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs761138
milestone17.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 761138 - Create/remove directories (Unix version). r=froydnj
toolkit/components/osfile/osfile_unix_allthreads.jsm
toolkit/components/osfile/osfile_unix_front.jsm
--- a/toolkit/components/osfile/osfile_unix_allthreads.jsm
+++ b/toolkit/components/osfile/osfile_unix_allthreads.jsm
@@ -104,30 +104,40 @@ if (typeof Components != "undefined") {
   };
 
   /**
    * |true| if the error was raised because a file or directory
    * already exists, |false| otherwise.
    */
   Object.defineProperty(OSError.prototype, "becauseExists", {
     get: function becauseExists() {
-      return this.unixErrno == OS.Constants.libc.EEXISTS;
+      return this.unixErrno == OS.Constants.libc.EEXIST;
     }
   });
   /**
    * |true| if the error was raised because a file or directory
    * does not exist, |false| otherwise.
    */
   Object.defineProperty(OSError.prototype, "becauseNoSuchFile", {
     get: function becauseNoSuchFile() {
       return this.unixErrno == OS.Constants.libc.ENOENT;
     }
   });
 
   /**
+   * |true| if the error was raised because a directory is not empty
+   * does not exist, |false| otherwise.
+   */
+   Object.defineProperty(OSError.prototype, "becauseNotEmpty", {
+     get: function becauseNotEmpty() {
+       return this.unixErrno == OS.Constants.libc.ENOTEMPTY;
+     }
+   });
+
+  /**
    * Serialize an instance of OSError to something that can be
    * transmitted across threads (not necessarily a string).
    */
   OSError.toMsg = function toMsg(error) {
     return {
       operation: error.operation,
       unixErrno: error.unixErrno
     };
--- a/toolkit/components/osfile/osfile_unix_front.jsm
+++ b/toolkit/components/osfile/osfile_unix_front.jsm
@@ -264,16 +264,59 @@
       */
      File.remove = function remove(path) {
        throw_on_negative("remove",
          UnixFile.unlink(path)
        );
      };
 
      /**
+      * Remove an empty directory.
+      *
+      * @param {string} path The name of the directory to remove.
+      * @param {*=} options Additional options.
+      *   - {bool} ignoreAbsent If |true|, do not fail if the
+      *     directory does not exist yet.
+      */
+     File.removeEmptyDir = function removeEmptyDir(path, options) {
+       options = options || noOptions;
+       let result = UnixFile.rmdir(path);
+       if (result == -1) {
+         if (options.ignoreAbsent && ctypes.errno == Const.ENOENT) {
+           return;
+         }
+         throw new File.Error("removeEmptyDir");
+       }
+     };
+
+     /**
+      * Default mode for opening directories.
+      */
+     const DEFAULT_UNIX_MODE_DIR = Const.S_IRWXU;
+
+     /**
+      * Create a directory.
+      *
+      * @param {string} path The name of the directory.
+      * @param {*=} options Additional options. This
+      * implementation interprets the following fields:
+      *
+      * - {number} unixMode If specified, a file creation mode,
+      * as per libc function |mkdir|. If unspecified, dirs are
+      * created with a default mode of 0700 (dir is private to
+      * the user, the user can read, write and execute).
+      */
+     File.makeDir = function makeDir(path, options) {
+       options = options || noOptions;
+       let omode = options.unixMode || DEFAULT_UNIX_MODE_DIR;
+       throw_on_negative("makeDir",
+         UnixFile.mkdir(path, omode));
+     };
+
+     /**
       * Copy a file to a destination.
       *
       * @param {string} sourcePath The platform-specific path at which
       * the file may currently be found.
       * @param {string} destPath The platform-specific path at which the
       * file should be copied.
       * @param {*=} options An object which may contain the following fields:
       *