diff --git a/toolkit/components/osfile/osfile_unix_back.jsm b/toolkit/components/osfile/osfile_unix_back.jsm index 40d462d8c24..f2e34241dc5 100644 --- a/toolkit/components/osfile/osfile_unix_back.jsm +++ b/toolkit/components/osfile/osfile_unix_back.jsm @@ -2,23 +2,6 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -/** - * This file can be used in the following contexts: - * - * 1. included from a non-osfile worker thread using importScript - * (it serves to define a synchronous API for that worker thread) - * (bug 707679) - * - * 2. included from the main thread using Components.utils.import - * (it serves to define the asynchronous API, whose implementation - * resides in the worker thread) - * (bug 729057) - * - * 3. included from the osfile worker thread using importScript - * (it serves to define the implementation of the asynchronous API) - * (bug 729057) - */ - { if (typeof Components != "undefined") { // We do not wish osfile_unix_back.jsm to be used directly as a main thread @@ -28,7 +11,8 @@ throw new Error("osfile_unix_back.jsm cannot be used from the main thread yet"); } - importScripts("resource://gre/modules/osfile/osfile_shared.jsm"); + importScripts("resource://gre/modules/osfile/osfile_shared_allthreads.jsm"); + importScripts("resource://gre/modules/osfile/osfile_unix_allthreads.jsm"); (function(exports) { "use strict"; if (!exports.OS) { @@ -42,36 +26,21 @@ } exports.OS.Unix.File = {}; - let LOG = OS.Shared.LOG.bind(OS.Shared, "Unix"); - - // Open libc - let libc; - let libc_candidates = [ "libsystem.B.dylib", - "libc.so.6", - "libc.so" ]; - for (let i = 0; i < libc_candidates.length; ++i) { - try { - libc = ctypes.open(libc_candidates[i]); - break; - } catch (x) { - LOG("Could not open libc "+libc_candidates[i]); - } - } - if (!libc) { - throw new Error("Could not open any libc."); - } + let LOG = exports.OS.Shared.LOG.bind(OS.Shared, "Unix", "back"); + let libc = exports.OS.Shared.Unix.libc; /** * Initialize the Unix module. * * @param {function=} declareFFI */ + // FIXME: Both |init| and |aDeclareFFI| are deprecated, we should remove them let init = function init(aDeclareFFI) { let declareFFI; if (aDeclareFFI) { declareFFI = aDeclareFFI.bind(null, libc); } else { - declareFFI = OS.Shared.declareFFI.bind(null, libc); + declareFFI = exports.OS.Shared.Unix.declareFFI; } // Shorthands @@ -468,11 +437,6 @@ /*len*/ Types.size_t, /*flags*/ Types.unsigned_int); // Linux/Android-specific - UnixFile.strerror = - declareFFI("strerror", ctypes.default_abi, - /*return*/ Types.null_or_string, - /*errnum*/ Types.int); - UnixFile.symlink = declareFFI("symlink", ctypes.default_abi, /*return*/ Types.negativeone_or_nothing, @@ -594,12 +558,6 @@ array[1] = ctypes.CDataFinalizer(_pipebuf[1], _close); return result; }; - - // Export useful stuff for extensibility - - exports.OS.Unix.libc = libc; - exports.OS.Unix.declareFFI = declareFFI; - }; exports.OS.Unix.File._init = init; })(this); diff --git a/toolkit/components/osfile/osfile_unix_front.jsm b/toolkit/components/osfile/osfile_unix_front.jsm index a1232f0a130..33feb6da227 100644 --- a/toolkit/components/osfile/osfile_unix_front.jsm +++ b/toolkit/components/osfile/osfile_unix_front.jsm @@ -16,7 +16,6 @@ throw new Error("osfile_unix_front.jsm cannot be used from the main thread yet"); } - importScripts("resource://gre/modules/osfile/osfile_shared.jsm"); importScripts("resource://gre/modules/osfile/osfile_unix_back.jsm"); importScripts("resource://gre/modules/osfile/ospath_unix_back.jsm"); (function(exports) { @@ -173,59 +172,6 @@ } }; - /** - * A File-related error. - * - * To obtain a human-readable error message, use method |toString|. - * To determine the cause of the error, use the various |becauseX| - * getters. To determine the operation that failed, use field - * |operation|. - * - * Additionally, this implementation offers a field - * |unixErrno|, which holds the OS-specific error - * constant. If you need this level of detail, you may match the value - * of this field against the error constants of |OS.Constants.libc|. - * - * @param {string=} operation The operation that failed. If unspecified, - * the name of the calling function is taken to be the operation that - * failed. - * @param {number=} lastError The OS-specific constant detailing the - * reason of the error. If unspecified, this is fetched from the system - * status. - * - * @constructor - * @extends {OS.Shared.Error} - */ - File.Error = function(operation, errno) { - operation = operation || "unknown operation"; - OS.Shared.Error.call(this, operation); - this.unixErrno = errno || ctypes.errno; - }; - File.Error.prototype = new OS.Shared.Error(); - File.Error.prototype.toString = function toString() { - return "Unix error " + this.unixErrno + - " during operation " + this.operation + - " (" + UnixFile.strerror(this.unixErrno).readString() + ")"; - }; - - /** - * |true| if the error was raised because a file or directory - * already exists, |false| otherwise. - */ - Object.defineProperty(File.Error.prototype, "becauseExists", { - get: function becauseExists() { - return this.unixErrno == OS.Constants.libc.EEXISTS; - } - }); - /** - * |true| if the error was raised because a file or directory - * does not exist, |false| otherwise. - */ - Object.defineProperty(File.Error.prototype, "becauseNoSuchFile", { - get: function becauseNoSuchFile() { - return this.unixErrno == OS.Constants.libc.ENOENT; - } - }); // Constant used to normalize options. const noOptions = {}; @@ -886,6 +832,8 @@ File.POS_END = exports.OS.Constants.libc.SEEK_END; File.Unix = exports.OS.Unix.File; + File.Error = exports.OS.Shared.Unix.Error; exports.OS.File = File; + })(this); } diff --git a/toolkit/components/osfile/ospath_unix_back.jsm b/toolkit/components/osfile/ospath_unix_back.jsm index 522e39bc8a6..318171233a2 100644 --- a/toolkit/components/osfile/ospath_unix_back.jsm +++ b/toolkit/components/osfile/ospath_unix_back.jsm @@ -14,6 +14,10 @@ * parse (see later); * - all path concatenations go through function |join|. */ +if (typeof Components != "undefined") { + var EXPORTED_SYMBOLS = ["OS"]; + Components.utils.import("resource://gre/modules/osfile/osfile_unix_allthreads.jsm"); +} (function(exports) { "use strict"; if (!exports.OS) {