Skip to content

Add FileSystem.lstat for symlink aware path inspection (node:fs/promises.lstat,) #6332

Closed

Description

@eersnington

What is the problem this feature would solve?

I'd love for there to be a FileSystem.lstat(path) within platform-node which would call node:fs.lstat (or bun docs of the same(

Why

I hit this for a usecase where I needed to remove a directory but only if it's a real directory and not a symlink.

Right now FileSystem.stat calls node's fs.stat, so a symlink to a directory comes back as Directory and not a SymbolicLink.

import { stat, lstat } from 'node:fs/promises';

const path = './link-to-file';

const a = await stat(path);   // stats for the target file/directory
const b = await lstat(path);  // stats for the symlink itself

console.log(a.isSymbolicLink()); // usually false
console.log(b.isSymbolicLink()); // true, if path is a symlink

The only way to write the check today is to leave Effect's FileSystem service and call node:fs.lstat directly (or build a custom service on top of fs.lstat).

This is useful for building tools, package managers, archive extraction, workspace cleanup, and sandbox code all need to decide whether a path should be followed, rejected, preserved, or handled as a symlink.

What is the feature you are proposing to solve the problem?

Here's a slop code example of what would go in packages/effect/src/FileSystem.ts

interface FileSystem {
  readonly stat: (
    path: string
  ) => Effect.Effect<File.Info, PlatformError>

  readonly lstat: (
    path: string
  ) => Effect.Effect<File.Info, PlatformError>
}

/*
On Node, implement it with fs.lstat and reuse the existing makeFileInfo conversion.
Then callers can keep the whole safety check inside FileSystem:
const info = yield* fs.lstat(path)
*/

if (info.type === "SymbolicLink") {
  return yield* Effect.fail(new RefusingToDeleteSymlink({ path }))
}

yield* fs.remove(path, { recursive: true, force: true })

What alternatives have you considered?

build a custom local service around node:fs/promises.lstat, but every project that needs this check would have to repeat the same adapter. goes against the mission of effect

Activity

  1. added
    enhancement
    on Jul 8, 2026
  2. added
    enhancement
    on Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    4.0enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions