Skip to content
Open
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
8 changes: 7 additions & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2076,7 +2076,13 @@ function statfs(path, options = { __proto__: null, bigint: false }, callback) {

const h = vfsState.handlers;
if (h !== null) {
const result = h.statfsSync(path, options);
let result;
try {
result = h.statfsSync(path, options);
} catch (err) {
process.nextTick(callback, err);
return;
}
if (result !== undefined) {
process.nextTick(callback, null, result);
return;
Expand Down
5 changes: 3 additions & 2 deletions lib/internal/vfs/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ function findVFSWith(filename, syscall, fn) {
const r = findVFS(filename);
if (r === null) return undefined;
if (r.vfs.existsSync(filename)) {
if (fn === undefined) return true;
return fn(r.vfs, filename);
}
throw createENOENT(syscall, filename);
Expand Down Expand Up @@ -410,7 +411,7 @@ function createVfsHandlers() {
},
statfsSync(path, options) {
const pathStr = toPathStr(path);
if (pathStr !== null && findVFSForPath(pathStr) !== null) {
if (pathStr !== null && findVFSWith(pathStr, 'statfs')) {
if (options?.bigint) {
return {
type: 0n, bsize: 4096n, blocks: 0n,
Expand Down Expand Up @@ -687,7 +688,7 @@ function createVfsHandlers() {
vfsOp(path, (vfs, n) => vfs.promises.lutimes(n, atime, mtime).then(() => true)),
statfs(path, options) {
const pathStr = toPathStr(path);
if (pathStr !== null && findVFSForPath(pathStr) !== null) {
if (pathStr !== null && findVFSWith(pathStr, 'statfs')) {
if (options?.bigint) {
return {
__proto__: null,
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-vfs-fs-promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ const vfs = require('node:vfs');
// statfs
const sfs = await fsp.statfs(p('src/hello.txt'));
assert.strictEqual(typeof sfs.bsize, 'number');
await assert.rejects(fsp.statfs(p('missing')), {
code: 'ENOENT',
syscall: 'statfs',
path: p('missing'),
});

// Path-based writes
await fsp.writeFile(p('src/pw.txt'), 'pdata');
Expand Down
17 changes: 16 additions & 1 deletion test/parallel/test-vfs-fs-statSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// fs.statSync / fs.lstatSync / fs.statfsSync dispatch through the VFS layer,
// including the `throwIfNoEntry: false` option.

require('../common');
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
Expand Down Expand Up @@ -57,4 +57,19 @@ assert.strictEqual(
assert.strictEqual(typeof s.bsize, 'bigint');
}

// statfsSync on a missing path throws ENOENT
assert.throws(() => fs.statfsSync(path.join(mountPoint, 'missing')),
{
code: 'ENOENT',
syscall: 'statfs',
path: path.join(mountPoint, 'missing'),
});

// Statfs on a missing path reports ENOENT through the callback
fs.statfs(path.join(mountPoint, 'missing'), common.mustCall((err) => {
assert.strictEqual(err.code, 'ENOENT');
assert.strictEqual(err.syscall, 'statfs');
assert.strictEqual(err.path, path.join(mountPoint, 'missing'));
}));

myVfs.unmount();
Loading