Skip to content

Commit 645418e

Browse files
committed
fs: Expose birthtime on stat objects
Just do the best we can with whatever libuv gives us. Also, document the semantics of `ctime` and the compatibility with Windows.
1 parent 474d58c commit 645418e

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

doc/api/fs.markdown

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -672,21 +672,45 @@ similar to this:
672672
blocks: 8,
673673
atime: Mon, 10 Oct 2011 23:24:11 GMT,
674674
mtime: Mon, 10 Oct 2011 23:24:11 GMT,
675-
ctime: Mon, 10 Oct 2011 23:24:11 GMT }
676-
677-
Please note that `atime`, `mtime` and `ctime` are instances
678-
of [Date][MDN-Date] object and to compare the values of
679-
these objects you should use appropriate methods. For most
680-
general uses [getTime()][MDN-Date-getTime] will return
681-
the number of milliseconds elapsed since _1 January 1970
682-
00:00:00 UTC_ and this integer should be sufficient for
683-
any comparison, however there additional methods which can
684-
be used for displaying fuzzy information. More details can
685-
be found in the [MDN JavaScript Reference][MDN-Date] page.
675+
ctime: Mon, 10 Oct 2011 23:24:11 GMT,
676+
birthtime: Mon, 10 Oct 2011 23:24:11 GMT }
677+
678+
Please note that `atime`, `mtime`, `birthtime`, and `ctime` are
679+
instances of [Date][MDN-Date] object and to compare the values of
680+
these objects you should use appropriate methods. For most general
681+
uses [getTime()][MDN-Date-getTime] will return the number of
682+
milliseconds elapsed since _1 January 1970 00:00:00 UTC_ and this
683+
integer should be sufficient for any comparison, however there
684+
additional methods which can be used for displaying fuzzy information.
685+
More details can be found in the [MDN JavaScript Reference][MDN-Date]
686+
page.
686687

687688
[MDN-Date]: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date
688689
[MDN-Date-getTime]: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/getTime
689690

691+
### Stat Time Values
692+
693+
The times in the stat object have the following semantics:
694+
695+
* `atime` "Access Time" - Time when file data last accessed. Changed
696+
by the `mknod(2)`, `utimes(2)`, and `read(2)` system calls.
697+
* `mtime` "Modified Time" - Time when file data last modified.
698+
Changed by the `mknod(2)`, `utimes(2)`, and `write(2)` system calls.
699+
* `ctime` "Change Time" - Time when file status was last changed
700+
(inode data modification). Changed by the `chmod(2)`, `chown(2)`,
701+
`link(2)`, `mknod(2)`, `rename(2)`, `unlink(2)`, `utimes(2)`,
702+
`read(2)`, and `write(2)` system calls.
703+
* `birthtime` "Birth Time" - Time of file creation. Set once when the
704+
file is created. On filesystems where birthtime is not available,
705+
this field may instead hold either the `ctime` or
706+
`1970-01-01T00:00Z` (ie, unix epoch timestamp `0`). On Darwin and
707+
other FreeBSD variants, also set if the `atime` is explicitly set to
708+
an earlier value than the current `birthtime` using the `utimes(2)`
709+
system call.
710+
711+
Prior to Node v0.12, the `ctime` held the `birthtime` on Windows
712+
systems. Note that as of v0.12, `ctime` is not "creation time", and
713+
on Unix systems, it never was.
690714

691715
## fs.createReadStream(path, [options])
692716

src/node_file.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ static Cached<String> blocks_symbol;
286286
static Cached<String> atime_symbol;
287287
static Cached<String> mtime_symbol;
288288
static Cached<String> ctime_symbol;
289+
static Cached<String> birthtime_symbol;
289290

290291
Local<Object> BuildStatsObject(const uv_stat_t* s) {
291292
HandleScope scope(node_isolate);
@@ -304,6 +305,7 @@ Local<Object> BuildStatsObject(const uv_stat_t* s) {
304305
atime_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "atime");
305306
mtime_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "mtime");
306307
ctime_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "ctime");
308+
birthtime_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "birthtime");
307309
}
308310

309311
Local<Function> constructor =
@@ -363,6 +365,7 @@ Local<Object> BuildStatsObject(const uv_stat_t* s) {
363365
X(atime, atim)
364366
X(mtime, mtim)
365367
X(ctime, ctim)
368+
X(birthtime, birthtim)
366369
#undef X
367370

368371
return scope.Close(stats);

0 commit comments

Comments
 (0)