MCPcopy Create free account
hub / github.com/Effect-TS/effect / removeFactory

Function removeFactory

packages/platform/node-shared/src/NodeFileSystem.ts:184–205  ·  view source on GitHub ↗
(method: string)

Source from the content-addressed store, hash-verified

182 (error.reason.cause as NodeJS.ErrnoException | undefined)?.code === "ERR_FS_EISDIR"
183
184const removeFactory = (method: string): FileSystem.FileSystem["remove"] => {
185 const nodeRm = effectify(
186 NFS.rm,
187 handleErrnoException("FileSystem", method),
188 handleBadArgument(method)
189 )
190 const nodeRmdir = effectify(
191 NFS.rmdir,
192 handleErrnoException("FileSystem", method),
193 handleBadArgument(method)
194 )
195 return (path, options) => {
196 const force = options?.force ?? false
197 const effect = nodeRm(path, { recursive: options?.recursive ?? false, force })
198 if (options?.recursive) return effect
199 // `rm` rejects all directories; `rmdir` atomically removes only empty ones
200 return Effect.catchIf(effect, isEisdir, () => {
201 const rmdir = nodeRmdir(path)
202 return force ? Effect.catchIf(rmdir, (error) => error.reason._tag === "NotFound", () => Effect.void) : rmdir
203 })
204 }
205}
206
207const remove = removeFactory("remove")
208

Callers 1

NodeFileSystem.tsFile · 0.70

Calls 2

handleErrnoExceptionFunction · 0.90
handleBadArgumentFunction · 0.85

Tested by

no test coverage detected