--- a/addon-sdk/source/lib/sdk/io/fs.js
+++ b/addon-sdk/source/lib/sdk/io/fs.js
@@ -13,17 +13,17 @@ lazyRequire(this, "../timers", "setTimeo
lazyRequire(this, "./stream", "Stream", "InputStream", "OutputStream");
lazyRequire(this, "../event/core", "emit", "on");
lazyRequire(this, "./buffer", "Buffer");
const { ns } = require("../core/namespace");
const { Class } = require("../core/heritage");
-const nsIFile = CC("@mozilla.org/file/local;1", "nsIFile",
+const LocalFile = CC("@mozilla.org/file/local;1", "nsIFile",
"initWithPath");
const FileOutputStream = CC("@mozilla.org/network/file-output-stream;1",
"nsIFileOutputStream", "init");
const FileInputStream = CC("@mozilla.org/network/file-input-stream;1",
"nsIFileInputStream", "init");
const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1",
"nsIBinaryInputStream", "setInputStream");
const BinaryOutputStream = CC("@mozilla.org/binaryoutputstream;1",
@@ -105,17 +105,17 @@ function toArray(enumerator) {
}
function getFileName(file) {
return file.QueryInterface(Ci.nsIFile).leafName;
}
function remove(path, recursive) {
- let fd = new nsIFile(path)
+ let fd = new LocalFile(path)
if (fd.exists()) {
fd.remove(recursive || false);
}
else {
throw FSError("remove", "ENOENT", 34, path);
}
}
@@ -251,17 +251,17 @@ const WriteStream = Class({
});
exports.WriteStream = WriteStream;
exports.createWriteStream = function createWriteStream(path, options) {
return new WriteStream(path, options);
};
const Stats = Class({
initialize: function initialize(path) {
- let file = new nsIFile(path);
+ let file = new LocalFile(path);
if (!file.exists()) throw FSError("stat", "ENOENT", 34, path);
nsIFile(this, file);
},
isDirectory: function() {
return nsIFile(this).isDirectory();
},
isFile: function() {
return nsIFile(this).isFile();
@@ -353,35 +353,35 @@ function Async(wrapped) {
}
}
/**
* Synchronous rename(2)
*/
function renameSync(oldPath, newPath) {
- let source = new nsIFile(oldPath);
- let target = new nsIFile(newPath);
+ let source = new LocalFile(oldPath);
+ let target = new LocalFile(newPath);
if (!source.exists()) throw FSError("rename", "ENOENT", 34, oldPath);
return source.moveTo(target.parent, target.leafName);
};
exports.renameSync = renameSync;
/**
* Asynchronous rename(2). No arguments other than a possible exception are
* given to the completion callback.
*/
var rename = Async(renameSync);
exports.rename = rename;
/**
* Test whether or not the given path exists by checking with the file system.
*/
function existsSync(path) {
- return new nsIFile(path).exists();
+ return new LocalFile(path).exists();
}
exports.existsSync = existsSync;
var exists = Async(existsSync);
exports.exists = exists;
/**
* Synchronous ftruncate(2).
@@ -442,17 +442,17 @@ var lchown = Async(lchown);
exports.lchown = lchown;
/**
* Synchronous chmod(2).
*/
function chmodSync (path, mode) {
let file;
try {
- file = new nsIFile(path);
+ file = new LocalFile(path);
} catch(e) {
throw FSError("chmod", "ENOENT", 34, path);
}
file.permissions = Mode(mode);
}
exports.chmodSync = chmodSync;
/**
@@ -553,32 +553,32 @@ exports.symlinkSync = symlinkSync;
*/
var symlink = Async(symlinkSync);
exports.symlink = symlink;
/**
* Synchronous readlink(2). Returns the resolved path.
*/
function readlinkSync(path) {
- return new nsIFile(path).target;
+ return new LocalFile(path).target;
};
exports.readlinkSync = readlinkSync;
/**
* Asynchronous readlink(2). The callback gets two arguments
* `(error, resolvedPath)`.
*/
var readlink = Async(readlinkSync);
exports.readlink = readlink;
/**
* Synchronous realpath(2). Returns the resolved path.
*/
function realpathSync(path) {
- return new nsIFile(path).path;
+ return new LocalFile(path).path;
};
exports.realpathSync = realpathSync;
/**
* Asynchronous realpath(2). The callback gets two arguments
* `(err, resolvedPath)`.
*/
var realpath = Async(realpathSync);
@@ -610,17 +610,17 @@ exports.rmdirSync = rmdirSync;
var rmdir = Async(rmdirSync);
exports.rmdir = rmdir;
/**
* Synchronous mkdir(2).
*/
function mkdirSync(path, mode) {
try {
- return nsIFile(path).create(DIRECTORY_TYPE, Mode(mode));
+ return LocalFile(path).create(DIRECTORY_TYPE, Mode(mode));
} catch (error) {
// Adjust exception thorw to match ones thrown by node.
if (error.name === "NS_ERROR_FILE_ALREADY_EXISTS") {
let { fileName, lineNumber } = error;
error = FSError("mkdir", "EEXIST", 47, path, fileName, lineNumber);
}
throw error;
}
@@ -635,17 +635,17 @@ var mkdir = Async(mkdirSync);
exports.mkdir = mkdir;
/**
* Synchronous readdir(3). Returns an array of filenames excluding `"."` and
* `".."`.
*/
function readdirSync(path) {
try {
- return toArray(new nsIFile(path).directoryEntries).map(getFileName);
+ return toArray(new LocalFile(path).directoryEntries).map(getFileName);
}
catch (error) {
// Adjust exception thorw to match ones thrown by node.
if (error.name === "NS_ERROR_FILE_TARGET_DOES_NOT_EXIST" ||
error.name === "NS_ERROR_FILE_NOT_FOUND")
{
let { fileName, lineNumber } = error;
error = FSError("readdir", "ENOENT", 34, path, fileName, lineNumber);
@@ -689,17 +689,17 @@ exports.closeSync = closeSync;
var close = Async(closeSync);
exports.close = close;
/**
* Synchronous open(2).
*/
function openSync(aPath, aFlag, aMode) {
let [ fd, flags, mode, file ] =
- [ { path: aPath }, Flags(aFlag), Mode(aMode), nsIFile(aPath) ];
+ [ { path: aPath }, Flags(aFlag), Mode(aMode), LocalFile(aPath) ];
nsIFile(fd, file);
// If trying to open file for just read that does not exists
// need to throw exception as node does.
if (!file.exists() && !isWritable(flags))
throw FSError("open", "ENOENT", 34, aPath);