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>,
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(

22
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<const uv_statbuf_t*>(req->ptr));
argv[1] = BuildStatsObject(static_cast<const uv_stat_t*>(req->ptr));
break;
case UV_FS_READLINK:
@ -274,7 +274,7 @@ static Persistent<String> atime_symbol;
static Persistent<String> mtime_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);
if (dev_symbol.IsEmpty()) {
@ -339,15 +339,17 @@ Local<Object> BuildStatsObject(const uv_statbuf_t* s) {
# endif
#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>(); \
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<Value> Stat(const Arguments& args) {
} else {
SYNC_CALL(stat, *path, *path)
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 {
SYNC_CALL(lstat, *path, *path)
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 {
SYNC_CALL(fstat, 0, fd)
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,
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<StatWatcher*>(handle->data);
assert(wrap->watcher_ == handle);
HandleScope scope(node_isolate);

4
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_;

Loading…
Cancel
Save