You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add FileSystem.lstat for symlink aware path inspection (node:fs/promises.lstat,) #6332
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';constpath='./link-to-file';consta=awaitstat(path);// stats for the target file/directoryconstb=awaitlstat(path);// stats for the symlink itselfconsole.log(a.isSymbolicLink());// usually falseconsole.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?
interfaceFileSystem{readonlystat: (path: string)=>Effect.Effect<File.Info,PlatformError>readonlylstat: (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"){returnyield*Effect.fail(newRefusingToDeleteSymlink({ 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