Skip to content

Commit 7df16a4

Browse files
committed
Preserve the original root directory when truncating
1 parent 27d34f2 commit 7df16a4

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

components/Blueprints/bin/blueprint.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,19 @@ function cliArgsToRunnerConfiguration( array $positionalArgs, array $options ):
428428
mkdir( $targetSiteRoot, 0755, true );
429429
} else if( is_dir( $absoluteTargetSiteRoot ) ) {
430430
$fs = LocalFilesystem::create( $absoluteTargetSiteRoot );
431-
$fs->rmdir( '/', [ 'recursive' => true ] );
432-
$fs->mkdir( '/', [ 'chmod' => 0755 ] );
431+
// Delete all the files and directories in the target site root, but preserve the
432+
// target directory itself. Why? In Playground CLI, `/wordpress` is likely to be a
433+
// mount removing a mount root throws an Exception.
434+
foreach ( $fs->ls('/') as $file ) {
435+
if( $fs->is_dir( $file ) ) {
436+
$fs->rmdir( $file, [ 'recursive' => true ] );
437+
} else {
438+
$fs->rm( $file );
439+
}
440+
}
441+
if ( ! $fs->is_dir( '/' ) ) {
442+
$fs->mkdir( '/', [ 'chmod' => 0755 ] );
443+
}
433444
}
434445
}
435446

0 commit comments

Comments
 (0)