Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override default umask in PHP #555

Merged
merged 3 commits into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions vendor/wp-now/src/wp-now.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
PHPRequestHandler,
proxyFileSystem,
rotatePHPRuntime,
getPhpIniEntries,
setPhpIniEntries,
} from '@php-wasm/universal';
import { wordPressRewriteRules, getFileNotFoundActionForWordPress } from '@wp-playground/wordpress';
Expand Down Expand Up @@ -66,6 +67,8 @@ export default async function startWPNow(

const php = await requestHandler.getPrimaryPhp();

await applyOverrideUmaskWorkaround( php );

prepareDocumentRoot( php, options );

output?.log( `directory: ${ options.projectPath }` );
Expand Down Expand Up @@ -563,3 +566,23 @@ export async function moveDatabasesInSitu( projectPath: string ) {
fs.rmSync( wpContentPath, { recursive: true, force: true } );
}
}

/**
* The default `umask` set by Emscripten is 0777 which is too restrictive. This has been updated
* in https://github.com/emscripten-core/emscripten/pull/22589 but is not available in the stable
* version of Emscripten yet. In the meantime, we'll apply a workaround by setting the umask via
* `auto_prepend_file` PHP directive.
*
* Once the Emscripten update is available, a new version of Playground is released using the
* updated Emscripten, and the Playground dependency is updated in the app, this workaround can be removed.
*/
async function applyOverrideUmaskWorkaround( php: PHP ) {
const iniEntries = await getPhpIniEntries( php );
await setPhpIniEntries( php, {
...iniEntries,
auto_prepend_file: '/internal/shared/studio/auto-prepend-file.php',
} );

php.mkdir( '/internal/shared/studio' );
php.writeFile( '/internal/shared/studio/auto-prepend-file.php', '<?php umask(0022);' );
}
Loading