Browse Source

fs: uv_[fl]stat now reports subsecond resolution

While libuv supports reporting subsecond stat resolution across
platforms, to actually get that resolution your platform and filesystem
must support it (not HFS, ext[23], fat), otherwise the nsecs are 0
v0.11.0-release
Timothy J Fontaine 12 years ago
committed by Ben Noordhuis
parent
commit
51f128d64b
  1. 2
      src/node.h
  2. 22
      src/node_file.cc
  3. 4
      src/node_stat_watcher.cc
  4. 4
      src/node_stat_watcher.h

2
src/node.h

@ -149,7 +149,7 @@ NODE_EXTERN ssize_t DecodeWrite(char *buf,
v8::Handle<v8::Value>, v8::Handle<v8::Value>,
enum encoding encoding = BINARY); enum encoding encoding = BINARY);
v8::Local<v8::Object> BuildStatsObject(const uv_statbuf_t* s); v8::Local<v8::Object> BuildStatsObject(const uv_stat_t* s);
static inline v8::Persistent<v8::Function>* cb_persist( static inline v8::Persistent<v8::Function>* cb_persist(

22
src/node_file.cc

@ -151,7 +151,7 @@ static void After(uv_fs_t *req) {
case UV_FS_STAT: case UV_FS_STAT:
case UV_FS_LSTAT: case UV_FS_LSTAT:
case UV_FS_FSTAT: case UV_FS_FSTAT:
argv[1] = BuildStatsObject(static_cast<const uv_statbuf_t*>(req->ptr)); argv[1] = BuildStatsObject(static_cast<const uv_stat_t*>(req->ptr));
break; break;
case UV_FS_READLINK: case UV_FS_READLINK:
@ -274,7 +274,7 @@ static Persistent<String> atime_symbol;
static Persistent<String> mtime_symbol; static Persistent<String> mtime_symbol;
static Persistent<String> ctime_symbol; static Persistent<String> ctime_symbol;
Local<Object> BuildStatsObject(const uv_statbuf_t* s) { Local<Object> BuildStatsObject(const uv_stat_t* s) {
HandleScope scope(node_isolate); HandleScope scope(node_isolate);
if (dev_symbol.IsEmpty()) { if (dev_symbol.IsEmpty()) {
@ -339,15 +339,17 @@ Local<Object> BuildStatsObject(const uv_statbuf_t* s) {
# endif # endif
#undef X #undef X
#define X(name) \ #define X(name, rec) \
{ \ { \
Local<Value> val = NODE_UNIXTIME_V8(s->st_##name); \ double msecs = static_cast<double>(s->st_##rec.tv_sec) * 1000; \
msecs += static_cast<double>(s->st_##rec.tv_nsec / 1000000); \
Local<Value> val = v8::Date::New(msecs); \
if (val.IsEmpty()) return Local<Object>(); \ if (val.IsEmpty()) return Local<Object>(); \
stats->Set(name##_symbol, val); \ stats->Set(name##_symbol, val); \
} }
X(atime) X(atime, atim)
X(mtime) X(mtime, mtim)
X(ctime) X(ctime, ctim)
#undef X #undef X
return scope.Close(stats); return scope.Close(stats);
@ -366,7 +368,7 @@ static Handle<Value> Stat(const Arguments& args) {
} else { } else {
SYNC_CALL(stat, *path, *path) SYNC_CALL(stat, *path, *path)
return scope.Close( return scope.Close(
BuildStatsObject(static_cast<const uv_statbuf_t*>(SYNC_REQ.ptr))); BuildStatsObject(static_cast<const uv_stat_t*>(SYNC_REQ.ptr)));
} }
} }
@ -383,7 +385,7 @@ static Handle<Value> LStat(const Arguments& args) {
} else { } else {
SYNC_CALL(lstat, *path, *path) SYNC_CALL(lstat, *path, *path)
return scope.Close( return scope.Close(
BuildStatsObject(static_cast<const uv_statbuf_t*>(SYNC_REQ.ptr))); BuildStatsObject(static_cast<const uv_stat_t*>(SYNC_REQ.ptr)));
} }
} }
@ -401,7 +403,7 @@ static Handle<Value> FStat(const Arguments& args) {
} else { } else {
SYNC_CALL(fstat, 0, fd) SYNC_CALL(fstat, 0, fd)
return scope.Close( return scope.Close(
BuildStatsObject(static_cast<const uv_statbuf_t*>(SYNC_REQ.ptr))); BuildStatsObject(static_cast<const uv_stat_t*>(SYNC_REQ.ptr)));
} }
} }

4
src/node_stat_watcher.cc

@ -71,8 +71,8 @@ StatWatcher::~StatWatcher() {
void StatWatcher::Callback(uv_fs_poll_t* handle, void StatWatcher::Callback(uv_fs_poll_t* handle,
int status, int status,
const uv_statbuf_t* prev, const uv_stat_t* prev,
const uv_statbuf_t* curr) { const uv_stat_t* curr) {
StatWatcher* wrap = static_cast<StatWatcher*>(handle->data); StatWatcher* wrap = static_cast<StatWatcher*>(handle->data);
assert(wrap->watcher_ == handle); assert(wrap->watcher_ == handle);
HandleScope scope(node_isolate); HandleScope scope(node_isolate);

4
src/node_stat_watcher.h

@ -44,8 +44,8 @@ class StatWatcher : ObjectWrap {
private: private:
static void Callback(uv_fs_poll_t* handle, static void Callback(uv_fs_poll_t* handle,
int status, int status,
const uv_statbuf_t* prev, const uv_stat_t* prev,
const uv_statbuf_t* curr); const uv_stat_t* curr);
void Stop(); void Stop();
uv_fs_poll_t* watcher_; uv_fs_poll_t* watcher_;

Loading…
Cancel
Save