Browse Source

Move the Stat structure functions to node_file.cc

from node.cc, so we can convert fs to a module.
v0.7.4-release
Paul Querna 14 years ago
committed by Ryan Dahl
parent
commit
ace2be8aa6
  1. 92
      src/node.cc
  2. 1
      src/node_extensions.h
  3. 95
      src/node_file.cc
  4. 2
      src/node_file.h

92
src/node.cc

@ -59,20 +59,6 @@ static Persistent<String> errno_symbol;
static Persistent<String> syscall_symbol;
static Persistent<String> errpath_symbol;
static Persistent<String> dev_symbol;
static Persistent<String> ino_symbol;
static Persistent<String> mode_symbol;
static Persistent<String> nlink_symbol;
static Persistent<String> uid_symbol;
static Persistent<String> gid_symbol;
static Persistent<String> rdev_symbol;
static Persistent<String> size_symbol;
static Persistent<String> blksize_symbol;
static Persistent<String> blocks_symbol;
static Persistent<String> atime_symbol;
static Persistent<String> mtime_symbol;
static Persistent<String> ctime_symbol;
static Persistent<String> rss_symbol;
static Persistent<String> vsize_symbol;
static Persistent<String> heap_total_symbol;
@ -907,73 +893,6 @@ ssize_t DecodeWrite(char *buf,
return buflen;
}
static Persistent<FunctionTemplate> stats_constructor_template;
Local<Object> BuildStatsObject(struct stat * s) {
HandleScope scope;
if (dev_symbol.IsEmpty()) {
dev_symbol = NODE_PSYMBOL("dev");
ino_symbol = NODE_PSYMBOL("ino");
mode_symbol = NODE_PSYMBOL("mode");
nlink_symbol = NODE_PSYMBOL("nlink");
uid_symbol = NODE_PSYMBOL("uid");
gid_symbol = NODE_PSYMBOL("gid");
rdev_symbol = NODE_PSYMBOL("rdev");
size_symbol = NODE_PSYMBOL("size");
blksize_symbol = NODE_PSYMBOL("blksize");
blocks_symbol = NODE_PSYMBOL("blocks");
atime_symbol = NODE_PSYMBOL("atime");
mtime_symbol = NODE_PSYMBOL("mtime");
ctime_symbol = NODE_PSYMBOL("ctime");
}
Local<Object> stats =
stats_constructor_template->GetFunction()->NewInstance();
/* ID of device containing file */
stats->Set(dev_symbol, Integer::New(s->st_dev));
/* inode number */
stats->Set(ino_symbol, Integer::New(s->st_ino));
/* protection */
stats->Set(mode_symbol, Integer::New(s->st_mode));
/* number of hard links */
stats->Set(nlink_symbol, Integer::New(s->st_nlink));
/* user ID of owner */
stats->Set(uid_symbol, Integer::New(s->st_uid));
/* group ID of owner */
stats->Set(gid_symbol, Integer::New(s->st_gid));
/* device ID (if special file) */
stats->Set(rdev_symbol, Integer::New(s->st_rdev));
/* total size, in bytes */
stats->Set(size_symbol, Number::New(s->st_size));
/* blocksize for filesystem I/O */
stats->Set(blksize_symbol, Integer::New(s->st_blksize));
/* number of blocks allocated */
stats->Set(blocks_symbol, Integer::New(s->st_blocks));
/* time of last access */
stats->Set(atime_symbol, NODE_UNIXTIME_V8(s->st_atime));
/* time of last modification */
stats->Set(mtime_symbol, NODE_UNIXTIME_V8(s->st_mtime));
/* time of last status change */
stats->Set(ctime_symbol, NODE_UNIXTIME_V8(s->st_ctime));
return scope.Close(stats);
}
// Extracts a C str from a V8 Utf8Value.
const char* ToCString(const v8::String::Utf8Value& value) {
return *value ? *value : "<str conversion failed>";
@ -1586,17 +1505,6 @@ static Handle<Value> Binding(const Arguments& args) {
exports = Object::New();
modp->register_func(exports);
binding_cache->Set(module, exports);
} else if (!strcmp(*module_v, "fs")) {
exports = Object::New();
// Initialize the stats object
Local<FunctionTemplate> stat_templ = FunctionTemplate::New();
stats_constructor_template = Persistent<FunctionTemplate>::New(stat_templ);
exports->Set(String::NewSymbol("Stats"),
stats_constructor_template->GetFunction());
StatWatcher::Initialize(exports);
File::Initialize(exports);
binding_cache->Set(module, exports);
} else if (!strcmp(*module_v, "evals")) {
exports = Object::New();
node::Context::Initialize(exports);

1
src/node_extensions.h

@ -6,6 +6,7 @@ NODE_EXT_LIST_ITEM(node_child_process)
#ifdef HAVE_OPENSSL
NODE_EXT_LIST_ITEM(node_crypto)
#endif
NODE_EXT_LIST_ITEM(node_fs)
NODE_EXT_LIST_ITEM(node_net)
NODE_EXT_LIST_ITEM(node_http_parser)
NODE_EXT_LIST_ITEM(node_signal_watcher)

95
src/node_file.cc

@ -2,6 +2,7 @@
#include <node.h>
#include <node_file.h>
#include <node_buffer.h>
#include <node_stat_watcher.h>
#include <sys/types.h>
#include <sys/stat.h>
@ -188,6 +189,87 @@ static Handle<Value> Close(const Arguments& args) {
}
}
static Persistent<FunctionTemplate> stats_constructor_template;
static Persistent<String> dev_symbol;
static Persistent<String> ino_symbol;
static Persistent<String> mode_symbol;
static Persistent<String> nlink_symbol;
static Persistent<String> uid_symbol;
static Persistent<String> gid_symbol;
static Persistent<String> rdev_symbol;
static Persistent<String> size_symbol;
static Persistent<String> blksize_symbol;
static Persistent<String> blocks_symbol;
static Persistent<String> atime_symbol;
static Persistent<String> mtime_symbol;
static Persistent<String> ctime_symbol;
Local<Object> BuildStatsObject(struct stat * s) {
HandleScope scope;
if (dev_symbol.IsEmpty()) {
dev_symbol = NODE_PSYMBOL("dev");
ino_symbol = NODE_PSYMBOL("ino");
mode_symbol = NODE_PSYMBOL("mode");
nlink_symbol = NODE_PSYMBOL("nlink");
uid_symbol = NODE_PSYMBOL("uid");
gid_symbol = NODE_PSYMBOL("gid");
rdev_symbol = NODE_PSYMBOL("rdev");
size_symbol = NODE_PSYMBOL("size");
blksize_symbol = NODE_PSYMBOL("blksize");
blocks_symbol = NODE_PSYMBOL("blocks");
atime_symbol = NODE_PSYMBOL("atime");
mtime_symbol = NODE_PSYMBOL("mtime");
ctime_symbol = NODE_PSYMBOL("ctime");
}
Local<Object> stats =
stats_constructor_template->GetFunction()->NewInstance();
/* ID of device containing file */
stats->Set(dev_symbol, Integer::New(s->st_dev));
/* inode number */
stats->Set(ino_symbol, Integer::New(s->st_ino));
/* protection */
stats->Set(mode_symbol, Integer::New(s->st_mode));
/* number of hard links */
stats->Set(nlink_symbol, Integer::New(s->st_nlink));
/* user ID of owner */
stats->Set(uid_symbol, Integer::New(s->st_uid));
/* group ID of owner */
stats->Set(gid_symbol, Integer::New(s->st_gid));
/* device ID (if special file) */
stats->Set(rdev_symbol, Integer::New(s->st_rdev));
/* total size, in bytes */
stats->Set(size_symbol, Number::New(s->st_size));
/* blocksize for filesystem I/O */
stats->Set(blksize_symbol, Integer::New(s->st_blksize));
/* number of blocks allocated */
stats->Set(blocks_symbol, Integer::New(s->st_blocks));
/* time of last access */
stats->Set(atime_symbol, NODE_UNIXTIME_V8(s->st_atime));
/* time of last modification */
stats->Set(mtime_symbol, NODE_UNIXTIME_V8(s->st_mtime));
/* time of last status change */
stats->Set(ctime_symbol, NODE_UNIXTIME_V8(s->st_ctime));
return scope.Close(stats);
}
static Handle<Value> Stat(const Arguments& args) {
HandleScope scope;
@ -719,4 +801,17 @@ void File::Initialize(Handle<Object> target) {
encoding_symbol = NODE_PSYMBOL("node:encoding");
}
void InitFs(Handle<Object> target) {
HandleScope scope;
// Initialize the stats object
Local<FunctionTemplate> stat_templ = FunctionTemplate::New();
stats_constructor_template = Persistent<FunctionTemplate>::New(stat_templ);
target->Set(String::NewSymbol("Stats"),
stats_constructor_template->GetFunction());
StatWatcher::Initialize(target);
File::Initialize(target);
}
} // end namespace node
NODE_MODULE(node_fs, node::InitFs);

2
src/node_file.h

@ -13,5 +13,7 @@ class File {
static void Initialize(v8::Handle<v8::Object> target);
};
void InitFs(v8::Handle<v8::Object> target);
} // namespace node
#endif // SRC_FILE_H_

Loading…
Cancel
Save