diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index a1ce4a6cc0a63f..7092bbcb633d81 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -155,6 +155,10 @@ function Stats( } Stats.prototype._checkModeProperty = function(property) { + if (isWindows && (property === S_IFIFO || property === S_IFBLK || + property === S_IFSOCK)) { + return false; // Some types are not available on Windows + } if (typeof this.mode === 'bigint') { // eslint-disable-line valid-typeof // eslint-disable-next-line no-undef return (this.mode & BigInt(S_IFMT)) === BigInt(property); @@ -193,9 +197,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], - stats[6 + offset] < 0 ? undefined : stats[6 + offset], + isWindows ? undefined : stats[6 + offset], // blksize stats[7 + offset], stats[8 + offset], - stats[9 + offset] < 0 ? undefined : stats[9 + offset], + isWindows ? undefined : stats[9 + offset], // blocks stats[10 + offset], stats[11 + offset], stats[12 + offset], stats[13 + offset]); } diff --git a/src/node_internals.h b/src/node_internals.h index d257de57366d73..b7cbfa94053343 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -325,14 +325,14 @@ v8::Local FillStatsArray(AliasedBuffer* fields_ptr, #if defined(__POSIX__) fields[offset + 6] = s->st_blksize; #else - fields[offset + 6] = -1; + fields[offset + 6] = 0; #endif fields[offset + 7] = s->st_ino; fields[offset + 8] = s->st_size; #if defined(__POSIX__) fields[offset + 9] = s->st_blocks; #else - fields[offset + 9] = -1; + fields[offset + 9] = 0; #endif // Dates. // NO-LINT because the fields are 'long' and we just want to cast to `unsigned` diff --git a/test/parallel/test-fs-stat-bigint.js b/test/parallel/test-fs-stat-bigint.js index 0b178b3a2579a7..eba238a81bab4e 100644 --- a/test/parallel/test-fs-stat-bigint.js +++ b/test/parallel/test-fs-stat-bigint.js @@ -15,8 +15,11 @@ tmpdir.refresh(); const fn = path.join(tmpdir.path, 'test-file'); fs.writeFileSync(fn, 'test'); -const link = path.join(tmpdir.path, 'symbolic-link'); -fs.symlinkSync(fn, link); +let link; +if (!common.isWindows) { + link = path.join(tmpdir.path, 'symbolic-link'); + fs.symlinkSync(fn, link); +} function verifyStats(bigintStats, numStats) { for (const key of Object.keys(numStats)) { @@ -59,6 +62,9 @@ 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)) { // eslint-disable-next-line no-undef assert.strictEqual(bigintStats[key], BigInt(val)); @@ -77,7 +83,7 @@ function verifyStats(bigintStats, numStats) { verifyStats(bigintStats, numStats); } -{ +if (!common.isWindows) { const bigintStats = fs.lstatSync(link, { bigint: true }); const numStats = fs.lstatSync(link); verifyStats(bigintStats, numStats); @@ -99,7 +105,7 @@ function verifyStats(bigintStats, numStats) { }); } -{ +if (!common.isWindows) { fs.lstat(link, { bigint: true }, (err, bigintStats) => { fs.lstat(link, (err, numStats) => { verifyStats(bigintStats, numStats); @@ -123,11 +129,13 @@ function verifyStats(bigintStats, numStats) { verifyStats(bigintStats, numStats); })(); -(async function() { - const bigintStats = await promiseFs.lstat(link, { bigint: true }); - const numStats = await promiseFs.lstat(link); - verifyStats(bigintStats, numStats); -})(); +if (!common.isWindows) { + (async function() { + const bigintStats = await promiseFs.lstat(link, { bigint: true }); + const numStats = await promiseFs.lstat(link); + verifyStats(bigintStats, numStats); + })(); +} (async function() { const handle = await promiseFs.open(fn, 'r');