Skip to content

Commit 51f128d

Browse files
tjfontainebnoordhuis
authored andcommitted
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
1 parent 648a072 commit 51f128d

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

src/node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ NODE_EXTERN ssize_t DecodeWrite(char *buf,
149149
v8::Handle<v8::Value>,
150150
enum encoding encoding = BINARY);
151151

152-
v8::Local<v8::Object> BuildStatsObject(const uv_statbuf_t* s);
152+
v8::Local<v8::Object> BuildStatsObject(const uv_stat_t* s);
153153

154154

155155
static inline v8::Persistent<v8::Function>* cb_persist(

src/node_file.cc

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static void After(uv_fs_t *req) {
151151
case UV_FS_STAT:
152152
case UV_FS_LSTAT:
153153
case UV_FS_FSTAT:
154-
argv[1] = BuildStatsObject(static_cast<const uv_statbuf_t*>(req->ptr));
154+
argv[1] = BuildStatsObject(static_cast<const uv_stat_t*>(req->ptr));
155155
break;
156156

157157
case UV_FS_READLINK:
@@ -274,7 +274,7 @@ static Persistent<String> atime_symbol;
274274
static Persistent<String> mtime_symbol;
275275
static Persistent<String> ctime_symbol;
276276

277-
Local<Object> BuildStatsObject(const uv_statbuf_t* s) {
277+
Local<Object> BuildStatsObject(const uv_stat_t* s) {
278278
HandleScope scope(node_isolate);
279279

280280
if (dev_symbol.IsEmpty()) {
@@ -339,15 +339,17 @@ Local<Object> BuildStatsObject(const uv_statbuf_t* s) {
339339
# endif
340340
#undef X
341341

342-
#define X(name) \
342+
#define X(name, rec) \
343343
{ \
344-
Local<Value> val = NODE_UNIXTIME_V8(s->st_##name); \
344+
double msecs = static_cast<double>(s->st_##rec.tv_sec) * 1000; \
345+
msecs += static_cast<double>(s->st_##rec.tv_nsec / 1000000); \
346+
Local<Value> val = v8::Date::New(msecs); \
345347
if (val.IsEmpty()) return Local<Object>(); \
346348
stats->Set(name##_symbol, val); \
347349
}
348-
X(atime)
349-
X(mtime)
350-
X(ctime)
350+
X(atime, atim)
351+
X(mtime, mtim)
352+
X(ctime, ctim)
351353
#undef X
352354

353355
return scope.Close(stats);
@@ -366,7 +368,7 @@ static Handle<Value> Stat(const Arguments& args) {
366368
} else {
367369
SYNC_CALL(stat, *path, *path)
368370
return scope.Close(
369-
BuildStatsObject(static_cast<const uv_statbuf_t*>(SYNC_REQ.ptr)));
371+
BuildStatsObject(static_cast<const uv_stat_t*>(SYNC_REQ.ptr)));
370372
}
371373
}
372374

@@ -383,7 +385,7 @@ static Handle<Value> LStat(const Arguments& args) {
383385
} else {
384386
SYNC_CALL(lstat, *path, *path)
385387
return scope.Close(
386-
BuildStatsObject(static_cast<const uv_statbuf_t*>(SYNC_REQ.ptr)));
388+
BuildStatsObject(static_cast<const uv_stat_t*>(SYNC_REQ.ptr)));
387389
}
388390
}
389391

@@ -401,7 +403,7 @@ static Handle<Value> FStat(const Arguments& args) {
401403
} else {
402404
SYNC_CALL(fstat, 0, fd)
403405
return scope.Close(
404-
BuildStatsObject(static_cast<const uv_statbuf_t*>(SYNC_REQ.ptr)));
406+
BuildStatsObject(static_cast<const uv_stat_t*>(SYNC_REQ.ptr)));
405407
}
406408
}
407409

src/node_stat_watcher.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ StatWatcher::~StatWatcher() {
7171

7272
void StatWatcher::Callback(uv_fs_poll_t* handle,
7373
int status,
74-
const uv_statbuf_t* prev,
75-
const uv_statbuf_t* curr) {
74+
const uv_stat_t* prev,
75+
const uv_stat_t* curr) {
7676
StatWatcher* wrap = static_cast<StatWatcher*>(handle->data);
7777
assert(wrap->watcher_ == handle);
7878
HandleScope scope(node_isolate);

src/node_stat_watcher.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class StatWatcher : ObjectWrap {
4444
private:
4545
static void Callback(uv_fs_poll_t* handle,
4646
int status,
47-
const uv_statbuf_t* prev,
48-
const uv_statbuf_t* curr);
47+
const uv_stat_t* prev,
48+
const uv_stat_t* curr);
4949
void Stop();
5050

5151
uv_fs_poll_t* watcher_;

0 commit comments

Comments
 (0)