effect icon indicating copy to clipboard operation
effect copied to clipboard

[Feature request] Add `force` option to `RemoveOptions` in `FileSystem` API

Open glacius-mitchell opened this issue 2 years ago • 0 comments

What is the problem this feature would solve?

There's currently no equivalent of rm -rf available in the FileSystem API.

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

I'd suggest adding readonly force?: boolean to RemoveOptions and propagating it through to the underlying NFS.rm call.

https://github.com/Effect-TS/effect/blob/9f2bc5a19e0b678a0a85e84daac290922b0fd57d/packages/platform/src/FileSystem.ts#L385-L387

https://github.com/Effect-TS/effect/blob/9f2bc5a19e0b678a0a85e84daac290922b0fd57d/packages/platform-node/src/internal/fileSystem.ts#L138-L149

https://nodejs.org/api/fs.html#fsrmpath-options-callback

Screenshot

What alternatives have you considered?

You can avoid an ENOENT: no such file or directory error in a call like fileSystem.remove(directoryPath, { recursive: true }) on a non-existent directoryPath by doing a fileSystem.exists(directoryPath) check first, but this splits things into two file system calls and introduces an unnecessary race condition, so it would be better if we could directly write fileSystem.remove(directoryPath, { force: true, recursive: true }).

glacius-mitchell avatar Dec 25 '23 03:12 glacius-mitchell