Skip to content

Commit 2ecba1b

Browse files
committed
[php-wasm] Add support for rm command in sandboxed spawn handler
1 parent 42ea377 commit 2ecba1b

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
@@ -81,7 +81,7 @@ export function sandboxedSpawnHandlerFactory(
8181
return;
8282
}
8383

84-
if (!['php', 'ls', 'pwd'].includes(binaryName ?? '')) {
84+
if (!['php', 'ls', 'pwd', 'rm'].includes(binaryName ?? '')) {
8585
// 127 is the exit code "for command not found".
8686
processApi.exit(127);
8787
return;
@@ -155,6 +155,20 @@ export function sandboxedSpawnHandlerFactory(
155155
processApi.exit(0);
156156
break;
157157
}
158+
case 'rm': {
159+
const target = args[args.length - 1];
160+
if (await php.isDir(target)) {
161+
await php.rmdir(target, { recursive: true });
162+
} else if (await php.isFile(target)) {
163+
await php.unlink(target);
164+
}
165+
// Technical limitation of subprocesses – we need to
166+
// wait before exiting to give consumer a chance to read
167+
// the output.
168+
await new Promise((resolve) => setTimeout(resolve, 10));
169+
processApi.exit(0);
170+
break;
171+
}
158172
}
159173
} catch (e) {
160174
// An exception here means the PHP runtime has crashed.

0 commit comments

Comments
 (0)