Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ node_js:
- "6"
- "8"
- "10"
- "12.9" # 12.10 introduced a breaking change on fs stat internal storage.
- "12"
32 changes: 27 additions & 5 deletions lib/binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ const fsBinding = process.binding('fs');
const kUsePromises = fsBinding.kUsePromises;
let statValues;
if (fsBinding.statValues) {
statValues = fsBinding.statValues; // node 10
statValues = fsBinding.statValues; // node 10+
} else if (fsBinding.getStatValues) {
statValues = fsBinding.getStatValues(); // node 8
} else {
statValues = [];
}

// nodejs v6,8,10 and v12 before v12.10.0 has length 28
// nodejs v12.10.0+ has length 36
const statContainsNs = statValues.length > 28;

/** Introduction of BigUint64Array in 10.5 */
let BigUint64Array;
if (global.BigUint64Array) {
Expand Down Expand Up @@ -378,10 +382,28 @@ function fillStatsArray(stats, statValues) {
statValues[7] = stats.ino;
statValues[8] = stats.size;
statValues[9] = stats.blocks;
statValues[10] = +stats.atime;
statValues[11] = +stats.mtime;
statValues[12] = +stats.ctime;
statValues[13] = +stats.birthtime;

if (statContainsNs) {
// nodejs v12.10.0+
// This is based on the internal FillStatsArray function in Node.
// https://github.com/nodejs/node/blob/3a2e75d9a5c31d20e429d505b82dd182e33f459a/src/node_file.h#L153-L187
statValues[10] = Math.floor(stats.atimeMs / 1000);
statValues[11] = (stats.atimeMs % 1000) * 1000000;
statValues[12] = Math.floor(stats.mtimeMs / 1000);
statValues[13] = (stats.mtimeMs % 1000) * 1000000;
statValues[14] = Math.floor(stats.ctimeMs / 1000);
statValues[15] = (stats.ctimeMs % 1000) * 1000000;
statValues[16] = Math.floor(stats.birthtimeMs / 1000);
statValues[17] = (stats.birthtimeMs % 1000) * 1000000;
} else {
// nodejs before v12.10.0
// This is based on the internal FillStatsArray function in Node.
// https://github.com/nodejs/node/blob/4e05952a8a75af6df625415db612d3a9a1322682/src/node_file.cc#L533
statValues[10] = stats.atimeMs;
statValues[11] = stats.mtimeMs;
statValues[12] = stats.ctimeMs;
statValues[13] = stats.birthtimeMs;
}
}

/**
Expand Down
6 changes: 5 additions & 1 deletion lib/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,11 @@ Item.prototype.getStats = function() {
atime: this.getATime(),
mtime: this.getMTime(),
ctime: this.getCTime(),
birthtime: this.getBirthtime()
birthtime: this.getBirthtime(),
atimeMs: +this.getATime(),
mtimeMs: +this.getMTime(),
ctimeMs: +this.getCTime(),
birthtimeMs: +this.getBirthtime()
};
};

Expand Down