Skip to content

Commit 3d7f99b

Browse files
committed
[php-wasm] Add support for rm command in sandboxed spawn handler
1 parent bb6fd78 commit 3d7f99b

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

packages/php-wasm/universal/src/lib/sandboxed-spawn-handler-factory.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function sandboxedSpawnHandlerFactory(
6262
return;
6363
}
6464

65-
if (!['php', 'ls', 'pwd'].includes(binaryName ?? '')) {
65+
if (!['php', 'ls', 'pwd', 'rm'].includes(binaryName ?? '')) {
6666
// 127 is the exit code "for command not found".
6767
processApi.exit(127);
6868
return;
@@ -128,6 +128,20 @@ export function sandboxedSpawnHandlerFactory(
128128
processApi.exit(0);
129129
break;
130130
}
131+
case 'rm': {
132+
const target = args[args.length - 1];
133+
if (await php.isDir(target)) {
134+
await php.rmdir(target, { recursive: true });
135+
} else if (await php.isFile(target)) {
136+
await php.unlink(target);
137+
}
138+
// Technical limitation of subprocesses – we need to
139+
// wait before exiting to give consumer a chance to read
140+
// the output.
141+
await new Promise((resolve) => setTimeout(resolve, 10));
142+
processApi.exit(0);
143+
break;
144+
}
131145
}
132146
} catch (e) {
133147
// An exception here means the PHP runtime has crashed.

0 commit comments

Comments
 (0)