Skip to content

Playground CLI Allow /wordpress subdirs to be mounted before WP install #2382

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

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

brandonpayton
Copy link
Member

Motivation for the change, related issues

In Playground CLI, /wordpress subdirs cannot currently be mounted before WP install because unzipping the WordPress zip fails. See #2381 for details.

Fixes #2381

Implementation details

The PR allows moving WordPress source files over an existing directory structure with some restrictions.

I'm a bit concerned it could lead to folks unintentionally overwriting their own files, so I'm not 100% we should land this. But let's discuss and find a path forward.

Testing Instructions (or ideally a Blueprint)

TBD

@brandonpayton brandonpayton requested a review from a team July 17, 2025 21:53
@brandonpayton brandonpayton self-assigned this Jul 17, 2025
@brandonpayton brandonpayton added [Type] Bug An existing feature does not function as intended [Package][@wp-playground] CLI labels Jul 17, 2025
@brandonpayton brandonpayton marked this pull request as draft July 17, 2025 21:53
@mjangda
Copy link

mjangda commented Jul 18, 2025

Confirming that this PR fixes the issue I was having (trying to mount an existing database folder to allow persistence).

Comment on lines +533 to 576
const moveRecursively = (source: string, target: string, php: PHP) => {
if (php.fileExists(target)) {
/*
* Something exists at the target path.
* Let's check to make sure we aren't copying conflicting types.
*
* In this context, if the source path points to a file and the
* target path points to a directory, we do not intend for the file
* to be moved into the directory.
*/

if (!php.isDir(source) && php.isDir(target)) {
throw new Error(
`The target ${target} is a directory but the source ${source} is not. This is not supported.`
);
}
if (php.isDir(source) && !php.isDir(target)) {
throw new Error(
`The source ${source} is a directory but the target ${target} is not. This is not supported.`
);
}
}

if (isNonEmptyDir(target, php)) {
// We cannot move a directory over a non-empty directory,
// so we move the children one by one.
for (const file of php.listFiles(source)) {
const sourcePath = joinPaths(source, file);
const targetPath = joinPaths(target, file);
moveRecursively(sourcePath, targetPath, php);
}
} else {
php.mv(source, target);
}
php.rmdir(wpPath, { recursive: true });
} else {
php.mv(wpPath, php.documentRoot);
};
try {
moveRecursively(wpPath, php.documentRoot, php);
// Remove any directories left because there were existing dirs at the target path.
if (php.fileExists(wpPath)) {
php.rmdir(wpPath, { recursive: true });
}
} catch (e) {
throw e;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would fit nicely into FSHelpers, similarly to how we have copyRecursive.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And mount tests have a bunch of FS related tests, so they could be a good fit for adding tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package][@wp-playground] CLI [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Playground CLI: /wordpress subdirs cannot be mounted before WP install
3 participants