From 51f128d64b250dfeb128aab5117b5bbcd2cc51b5 Mon Sep 17 00:00:00 2001 From: Timothy J Fontaine Date: Fri, 22 Mar 2013 13:51:11 -0700 Subject: [PATCH] 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 --- src/node.h | 2 +- src/node_file.cc | 22 ++++++++++++---------- src/node_stat_watcher.cc | 4 ++-- src/node_stat_watcher.h | 4 ++-- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/node.h b/src/node.h index 9984faef5b..ded8b78536 100644 --- a/src/node.h +++ b/src/node.h @@ -149,7 +149,7 @@ NODE_EXTERN ssize_t DecodeWrite(char *buf, v8::Handle, enum encoding encoding = BINARY); -v8::Local BuildStatsObject(const uv_statbuf_t* s); +v8::Local BuildStatsObject(const uv_stat_t* s); static inline v8::Persistent* cb_persist( diff --git a/src/node_file.cc b/src/node_file.cc index 684044401d..69b76736c3 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -151,7 +151,7 @@ static void After(uv_fs_t *req) { case UV_FS_STAT: case UV_FS_LSTAT: case UV_FS_FSTAT: - argv[1] = BuildStatsObject(static_cast(req->ptr)); + argv[1] = BuildStatsObject(static_cast(req->ptr)); break; case UV_FS_READLINK: @@ -274,7 +274,7 @@ static Persistent atime_symbol; static Persistent mtime_symbol; static Persistent ctime_symbol; -Local BuildStatsObject(const uv_statbuf_t* s) { +Local BuildStatsObject(const uv_stat_t* s) { HandleScope scope(node_isolate); if (dev_symbol.IsEmpty()) { @@ -339,15 +339,17 @@ Local BuildStatsObject(const uv_statbuf_t* s) { # endif #undef X -#define X(name) \ +#define X(name, rec) \ { \ - Local val = NODE_UNIXTIME_V8(s->st_##name); \ + double msecs = static_cast(s->st_##rec.tv_sec) * 1000; \ + msecs += static_cast(s->st_##rec.tv_nsec / 1000000); \ + Local val = v8::Date::New(msecs); \ if (val.IsEmpty()) return Local(); \ stats->Set(name##_symbol, val); \ } - X(atime) - X(mtime) - X(ctime) + X(atime, atim) + X(mtime, mtim) + X(ctime, ctim) #undef X return scope.Close(stats); @@ -366,7 +368,7 @@ static Handle Stat(const Arguments& args) { } else { SYNC_CALL(stat, *path, *path) return scope.Close( - BuildStatsObject(static_cast(SYNC_REQ.ptr))); + BuildStatsObject(static_cast(SYNC_REQ.ptr))); } } @@ -383,7 +385,7 @@ static Handle LStat(const Arguments& args) { } else { SYNC_CALL(lstat, *path, *path) return scope.Close( - BuildStatsObject(static_cast(SYNC_REQ.ptr))); + BuildStatsObject(static_cast(SYNC_REQ.ptr))); } } @@ -401,7 +403,7 @@ static Handle FStat(const Arguments& args) { } else { SYNC_CALL(fstat, 0, fd) return scope.Close( - BuildStatsObject(static_cast(SYNC_REQ.ptr))); + BuildStatsObject(static_cast(SYNC_REQ.ptr))); } } diff --git a/src/node_stat_watcher.cc b/src/node_stat_watcher.cc index fb3d0a9ad6..582c50c70f 100644 --- a/src/node_stat_watcher.cc +++ b/src/node_stat_watcher.cc @@ -71,8 +71,8 @@ StatWatcher::~StatWatcher() { void StatWatcher::Callback(uv_fs_poll_t* handle, int status, - const uv_statbuf_t* prev, - const uv_statbuf_t* curr) { + const uv_stat_t* prev, + const uv_stat_t* curr) { StatWatcher* wrap = static_cast(handle->data); assert(wrap->watcher_ == handle); HandleScope scope(node_isolate); diff --git a/src/node_stat_watcher.h b/src/node_stat_watcher.h index 18afa79944..94ed10a0ee 100644 --- a/src/node_stat_watcher.h +++ b/src/node_stat_watcher.h @@ -44,8 +44,8 @@ class StatWatcher : ObjectWrap { private: static void Callback(uv_fs_poll_t* handle, int status, - const uv_statbuf_t* prev, - const uv_statbuf_t* curr); + const uv_stat_t* prev, + const uv_stat_t* curr); void Stop(); uv_fs_poll_t* watcher_;