Synchronous chmod(2).
-### fs.stat(path, callback), fs.lstat(path, callback)
+### fs.stat(path, callback), fs.lstat(path, callback), fs.fstat(fd, callback)
-Asynchronous stat(2) or lstat(2). The callback gets two arguments `(err, stats)` where `stats` is a `fs.Stats` object. It looks like this:
+Asynchronous stat(2), lstat(2) or fstat(2). The callback gets two arguments `(err, stats)` where `stats` is a `fs.Stats` object. It looks like this:
{ dev: 2049
, ino: 305352
See the `fs.Stats` section below for more information.
-### fs.statSync(path), fs.lstatSync(path)
+### fs.statSync(path), fs.lstatSync(path), fs.fstatSync(fd)
-Synchronous stat(2) or lstat(2). Returns an instance of `fs.Stats`.
+Synchronous stat(2), lstat(2) or fstat(2). Returns an instance of `fs.Stats`.
### fs.link(srcpath, dstpath, callback)
return binding.readdir(path);
};
+fs.fstat = function (fd, callback) {
+ binding.fstat(fd, callback || noop);
+};
+
fs.lstat = function (path, callback) {
binding.lstat(path, callback || noop);
};
binding.stat(path, callback || noop);
};
+fs.fstatSync = function (fd) {
+ return binding.fstat(fd);
+};
+
fs.lstatSync = function (path) {
return binding.lstat(path);
};
case EIO_STAT:
case EIO_LSTAT:
+ case EIO_FSTAT:
{
struct stat *s = reinterpret_cast<struct stat*>(req->ptr2);
argc = 2;
}
}
+static Handle<Value> FStat(const Arguments& args) {
+ HandleScope scope;
+
+ if (args.Length() < 1 || !args[0]->IsInt32()) {
+ return THROW_BAD_ARGS;
+ }
+
+ int fd = args[0]->Int32Value();
+
+ if (args[1]->IsFunction()) {
+ ASYNC_CALL(fstat, args[1], fd)
+ } else {
+ struct stat s;
+ int ret = fstat(fd, &s);
+ if (ret != 0) return ThrowException(ErrnoException(errno));
+ return scope.Close(BuildStatsObject(&s));
+ }
+}
+
static Handle<Value> Symlink(const Arguments& args) {
HandleScope scope;
NODE_SET_METHOD(target, "readdir", ReadDir);
NODE_SET_METHOD(target, "stat", Stat);
NODE_SET_METHOD(target, "lstat", LStat);
+ NODE_SET_METHOD(target, "fstat", FStat);
NODE_SET_METHOD(target, "link", Link);
NODE_SET_METHOD(target, "symlink", Symlink);
NODE_SET_METHOD(target, "readlink", ReadLink);
}
});
+// fstat
+fs.open(".", "r", undefined, function(err, fd) {
+ assert.ok(!err);
+ assert.ok(fd);
+
+ fs.fstat(fd, function (err, stats) {
+ if (err) {
+ got_error = true;
+ } else {
+ p(stats);
+ assert.ok(stats.mtime instanceof Date);
+ success_count++;
+ fs.close(fd);
+ }
+ });
+});
+
+// fstatSync
+fs.open(".", "r", undefined, function(err, fd) {
+ var stats;
+ try {
+ stats = fs.fstatSync(fd);
+ } catch (err) {
+ got_error = true;
+ }
+ if (stats) {
+ p(stats);
+ assert.ok(stats.mtime instanceof Date);
+ success_count++;
+ }
+ fs.close(fd);
+});
+
puts("stating: " + __filename);
fs.stat(__filename, function (err, s) {
if (err) {
});
process.addListener("exit", function () {
- assert.equal(3, success_count);
+ assert.equal(5, success_count);
assert.equal(false, got_error);
});