Skip to content

Commit 8cb7361

Browse files
authored
Override default umask in PHP (#555)
* Setup platform-level internal plugins * Add internal plugin to override default umask * Preprend PHP file to override `umask` value This approach replaces the one using a plugin.
1 parent 757cadc commit 8cb7361

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎vendor/wp-now/src/wp-now.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
PHPRequestHandler,
77
proxyFileSystem,
88
rotatePHPRuntime,
9+
getPhpIniEntries,
910
setPhpIniEntries,
1011
} from '@php-wasm/universal';
1112
import { wordPressRewriteRules, getFileNotFoundActionForWordPress } from '@wp-playground/wordpress';
@@ -66,6 +67,8 @@ export default async function startWPNow(
6667

6768
const php = await requestHandler.getPrimaryPhp();
6869

70+
await applyOverrideUmaskWorkaround( php );
71+
6972
prepareDocumentRoot( php, options );
7073

7174
output?.log( `directory: ${ options.projectPath }` );
@@ -563,3 +566,23 @@ export async function moveDatabasesInSitu( projectPath: string ) {
563566
fs.rmSync( wpContentPath, { recursive: true, force: true } );
564567
}
565568
}
569+
570+
/**
571+
* The default `umask` set by Emscripten is 0777 which is too restrictive. This has been updated
572+
* in https://github.com/emscripten-core/emscripten/pull/22589 but is not available in the stable
573+
* version of Emscripten yet. In the meantime, we'll apply a workaround by setting the umask via
574+
* `auto_prepend_file` PHP directive.
575+
*
576+
* Once the Emscripten update is available, a new version of Playground is released using the
577+
* updated Emscripten, and the Playground dependency is updated in the app, this workaround can be removed.
578+
*/
579+
async function applyOverrideUmaskWorkaround( php: PHP ) {
580+
const iniEntries = await getPhpIniEntries( php );
581+
await setPhpIniEntries( php, {
582+
...iniEntries,
583+
auto_prepend_file: '/internal/shared/studio/auto-prepend-file.php',
584+
} );
585+
586+
php.mkdir( '/internal/shared/studio' );
587+
php.writeFile( '/internal/shared/studio/auto-prepend-file.php', '<?php umask(0022);' );
588+
}

0 commit comments

Comments
 (0)