diff --git a/src/bun.js/bindings/NodeDirent.cpp b/src/bun.js/bindings/NodeDirent.cpp index ac05a49417..fbfc26ff63 100644 --- a/src/bun.js/bindings/NodeDirent.cpp +++ b/src/bun.js/bindings/NodeDirent.cpp @@ -277,7 +277,7 @@ JSC_DEFINE_HOST_FUNCTION(jsDirentProtoFuncIsFIFO, (JSC::JSGlobalObject * globalO int32_t type = getType(vm, callFrame->thisValue(), defaultGlobalObject(globalObject)); RETURN_IF_EXCEPTION(scope, {}); - return JSValue::encode(jsBoolean(type == static_cast(DirEntType::NamedPipe) || type == static_cast(DirEntType::EventPort))); + return JSValue::encode(jsBoolean(type == static_cast(DirEntType::NamedPipe))); } JSC_DEFINE_HOST_FUNCTION(jsDirentProtoFuncIsFile, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) diff --git a/test/regression/issue/24129.test.ts b/test/regression/issue/24129.test.ts new file mode 100644 index 0000000000..5e66443520 --- /dev/null +++ b/test/regression/issue/24129.test.ts @@ -0,0 +1,40 @@ +import { expect, test } from "bun:test"; +import fs from "node:fs"; + +// Test for GitHub issue #24129 +// When a filesystem returns DT_UNKNOWN (like sshfs, NFS, or other remote/virtual filesystems), +// fs.Dirent.isFIFO() was incorrectly returning true because the EventPort type (value 0) +// was being checked in isFIFO(), and Unknown also maps to 0. + +test("Dirent with unknown type should return false for all type checks", () => { + const UV_DIRENT_UNKNOWN = fs.constants.UV_DIRENT_UNKNOWN; + expect(UV_DIRENT_UNKNOWN).toBe(0); + + // Create a Dirent with unknown type (simulates what happens on sshfs/NFS mounts) + const dirent = new fs.Dirent("test-file", UV_DIRENT_UNKNOWN); + + // All type checks should return false for unknown type + expect(dirent.isFile()).toBe(false); + expect(dirent.isDirectory()).toBe(false); + expect(dirent.isSymbolicLink()).toBe(false); + expect(dirent.isSocket()).toBe(false); + expect(dirent.isBlockDevice()).toBe(false); + expect(dirent.isCharacterDevice()).toBe(false); + + // This is the bug fix - isFIFO() should return false for unknown type + // Previously it returned true because EventPort (0) was checked + expect(dirent.isFIFO()).toBe(false); +}); + +test("Dirent.isFIFO() should only return true for actual FIFO/named pipe", () => { + const UV_DIRENT_FIFO = fs.constants.UV_DIRENT_FIFO; + expect(UV_DIRENT_FIFO).toBe(4); + + // Create a Dirent with FIFO type + const fifoDirent = new fs.Dirent("test-fifo", UV_DIRENT_FIFO); + expect(fifoDirent.isFIFO()).toBe(true); + + // Verify other type checks return false + expect(fifoDirent.isFile()).toBe(false); + expect(fifoDirent.isDirectory()).toBe(false); +});