Skip to content

Commit

Permalink
fs, src, lib: fix blksize & blocks on Windows
Browse files Browse the repository at this point in the history
libuv returns values for `blksize` and `blocks` on stat calls so
do not coerce them into `undefined` on Windows.

PR-URL: #26056
Fixes: #25913
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
richardlau authored and rvagg committed Feb 28, 2019
1 parent 2d0242a commit 14cf22f
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 25 deletions.
3 changes: 1 addition & 2 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -3414,8 +3414,7 @@ to compare `curr.mtime` and `prev.mtime`.

When an `fs.watchFile` operation results in an `ENOENT` error, it
will invoke the listener once, with all the fields zeroed (or, for dates, the
Unix Epoch). In Windows, `blksize` and `blocks` fields will be `undefined`,
instead of zero. If the file is created later on, the listener will be called
Unix Epoch). If the file is created later on, the listener will be called
again, with the latest stat objects. This is a change in functionality since
v0.10.

Expand Down
4 changes: 2 additions & 2 deletions lib/internal/fs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,9 @@ Stats.prototype.isSocket = function() {
function getStatsFromBinding(stats, offset = 0) {
return new Stats(stats[0 + offset], stats[1 + offset], stats[2 + offset],
stats[3 + offset], stats[4 + offset], stats[5 + offset],
isWindows ? undefined : stats[6 + offset], // blksize
stats[6 + offset], // blksize
stats[7 + offset], stats[8 + offset],
isWindows ? undefined : stats[9 + offset], // blocks
stats[9 + offset], // blocks
stats[10 + offset], stats[11 + offset],
stats[12 + offset], stats[13 + offset]);
}
Expand Down
8 changes: 0 additions & 8 deletions src/node_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,10 @@ constexpr void FillStatsArray(AliasedBuffer<NativeT, V8T>* fields,
fields->SetValue(offset + 3, s->st_uid);
fields->SetValue(offset + 4, s->st_gid);
fields->SetValue(offset + 5, s->st_rdev);
#if defined(__POSIX__)
fields->SetValue(offset + 6, s->st_blksize);
#else
fields->SetValue(offset + 6, 0);
#endif
fields->SetValue(offset + 7, s->st_ino);
fields->SetValue(offset + 8, s->st_size);
#if defined(__POSIX__)
fields->SetValue(offset + 9, s->st_blocks);
#else
fields->SetValue(offset + 9, 0);
#endif
// Dates.
fields->SetValue(offset + 10, ToNative<NativeT>(s->st_atim));
fields->SetValue(offset + 11, ToNative<NativeT>(s->st_mtim));
Expand Down
3 changes: 0 additions & 3 deletions test/parallel/test-fs-stat-bigint.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ function verifyStats(bigintStats, numStats) {
bigintStats.isSymbolicLink(),
numStats.isSymbolicLink()
);
} else if (common.isWindows && (key === 'blksize' || key === 'blocks')) {
assert.strictEqual(bigintStats[key], undefined);
assert.strictEqual(numStats[key], undefined);
} else if (Number.isSafeInteger(val)) {
assert.strictEqual(
bigintStats[key], BigInt(val),
Expand Down
9 changes: 3 additions & 6 deletions test/parallel/test-fs-stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,13 @@ fs.stat(__filename, common.mustCall(function(err, s) {
assert.strictEqual(s.isSymbolicLink(), false);
const keys = [
'dev', 'mode', 'nlink', 'uid',
'gid', 'rdev', 'ino', 'size',
'gid', 'rdev', 'blksize', 'ino', 'size', 'blocks',
'atime', 'mtime', 'ctime', 'birthtime',
'atimeMs', 'mtimeMs', 'ctimeMs', 'birthtimeMs'
];
if (!common.isWindows) {
keys.push('blocks', 'blksize');
}
const numberFields = [
'dev', 'mode', 'nlink', 'uid', 'gid', 'rdev', 'ino', 'size',
'atimeMs', 'mtimeMs', 'ctimeMs', 'birthtimeMs'
'dev', 'mode', 'nlink', 'uid', 'gid', 'rdev', 'blksize', 'ino', 'size',
'blocks', 'atimeMs', 'mtimeMs', 'ctimeMs', 'birthtimeMs'
];
const dateFields = ['atime', 'mtime', 'ctime', 'birthtime'];
keys.forEach(function(k) {
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-fs-watchfile-bigint.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ const expectedStatObject = new fs.Stats(
0n, // uid
0n, // gid
0n, // rdev
common.isWindows ? undefined : 0n, // blksize
0n, // blksize
0n, // ino
0n, // size
common.isWindows ? undefined : 0n, // blocks
0n, // blocks
0n, // atim_msec
0n, // mtim_msec
0n, // ctim_msec
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-fs-watchfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ const expectedStatObject = new fs.Stats(
0, // uid
0, // gid
0, // rdev
common.isWindows ? undefined : 0, // blksize
0, // blksize
0, // ino
0, // size
common.isWindows ? undefined : 0, // blocks
0, // blocks
Date.UTC(1970, 0, 1, 0, 0, 0), // atime
Date.UTC(1970, 0, 1, 0, 0, 0), // mtime
Date.UTC(1970, 0, 1, 0, 0, 0), // ctime
Expand Down

0 comments on commit 14cf22f

Please sign in to comment.