diff --git a/cli/ops/fs.rs b/cli/ops/fs.rs index 499340deb9..ee52f88b80 100644 --- a/cli/ops/fs.rs +++ b/cli/ops/fs.rs @@ -417,8 +417,11 @@ fn op_remove( std::fs::remove_file(&path)?; } } - } else { + } else if file_type.is_dir() { std::fs::remove_dir(&path)?; + } else { + // pipes, sockets, etc... + std::fs::remove_file(&path)?; } Ok(json!({})) }) diff --git a/cli/tests/unit/remove_test.ts b/cli/tests/unit/remove_test.ts index 35e5c821e1..5d293ec51a 100644 --- a/cli/tests/unit/remove_test.ts +++ b/cli/tests/unit/remove_test.ts @@ -460,6 +460,31 @@ unitTest({ perms: { write: false } }, async function removeAllPerm(): Promise< assertEquals(err.name, "PermissionDenied"); }); +unitTest( + { + ignore: Deno.build.os === "windows", + perms: { write: true, read: true }, + }, + async function removeUnixSocketSuccess(): Promise { + for (const method of ["remove", "removeSync"] as const) { + // MAKE TEMPORARY UNIX SOCKET + const path = Deno.makeTempDirSync() + "/test.sock"; + const listener = Deno.listen({ transport: "unix", path }); + listener.close(); + Deno.statSync(path); // check if unix socket exists + + await Deno[method](path); + let err; + try { + Deno.statSync(path); + } catch (e) { + err = e; + } + assert(err instanceof Deno.errors.NotFound); + } + } +); + if (Deno.build.os === "windows") { unitTest( { perms: { run: true, write: true, read: true } },