Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move the Stat structure functions to node_file.cc

from node.cc, so we can convert fs to a module.
  • Loading branch information...
commit ace2be8aa60ba5f902823d915460012d877ea4da 1 parent 82daa46
@pquerna pquerna authored ry committed
View
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);
View
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)
View
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);
View
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_
Please sign in to comment.
Something went wrong with that request. Please try again.