Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
fs: uv_[fl]stat now reports subsecond resolution
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tjfontaine authored and bnoordhuis committed Mar 23, 2013
1 parent 648a072 commit 51f128d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
22 changes: 12 additions & 10 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
Expand All @@ -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)));
}
}

Expand All @@ -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)));
}
}

Expand All @@ -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)));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/node_stat_watcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/node_stat_watcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down

0 comments on commit 51f128d

Please sign in to comment.