Skip to content
This repository was archived by the owner on May 30, 2025. It is now read-only.

Commit 7bcbd2d

Browse files
committed
Correctly truncate site path if it does not exist or is not empty
1 parent ad48849 commit 7bcbd2d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

components/Blueprints/bin/blueprint.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
use WordPress\Blueprints\ProgressObserver;
4242
use WordPress\Blueprints\Runner;
4343
use WordPress\Blueprints\RunnerConfiguration;
44+
use WordPress\Filesystem\LocalFilesystem;
4445

4546
// Enable colours on Windows 10+ (safe‑no‑op elsewhere)
4647
if ( PHP_OS_FAMILY === 'Windows' && function_exists( 'sapi_windows_vt100_support' ) ) {
@@ -302,9 +303,14 @@ function cliArgsToRunnerConfiguration( array $positionalArgs, array $options ):
302303
if ( $options['mode'] !== 'create-new-site' ) {
303304
throw new InvalidArgumentException( "--truncate-new-site-directory can only be used with --mode=create-new-site" );
304305
}
305-
if ( ! is_dir( $targetSiteRoot ) ) {
306+
$absoluteTargetSiteRoot = realpath( $targetSiteRoot );
307+
if ( false === $absoluteTargetSiteRoot) {
306308
mkdir( $targetSiteRoot, 0755, true );
307-
}
309+
} else if( is_dir( $absoluteTargetSiteRoot ) ) {
310+
$fs = LocalFilesystem::create( $absoluteTargetSiteRoot );
311+
$fs->rmdir( '/', [ 'recursive' => true ] );
312+
$fs->mkdir( '/', [ 'chmod' => 0755 ] );
313+
}
308314
}
309315

310316
$absoluteTargetSiteRoot = realpath( $targetSiteRoot );

0 commit comments

Comments
 (0)