Skip to content

Commit

Permalink
Refactor method for better windows compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
reimic committed Mar 5, 2024
1 parent 4f3104c commit a44e523
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/WordPress/Blueprints/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace WordPress\Blueprints;

use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Path;
use Symfony\Component\Filesystem\Exception\IOException;
use WordPress\Blueprints\Runtime\Runtime;

Expand Down Expand Up @@ -42,16 +44,18 @@ function list_files( string $path, $omitDotFiles = false ): array {
}

function move_files_from_directory_to_directory( string $from, string $to ) {
$fs = new Filesystem();
$files = scandir( $from );
foreach ( $files as $file ) {
if ( '.' === $file || '..' === $file ) {
continue;
}
$fromPath = $from . '/' . $file;
$toPath = $to . '/' . $file;
$success = rename( $fromPath, $toPath );
if ( ! $success ) {
throw new IOException( "Failed to move the file from {$fromPath} at {$toPath}" );
$fromPath = Path::canonicalize($from . '/' . $file);
$toPath = Path::canonicalize($to . '/' . $file);
try {
$fs->rename($fromPath, $toPath);
} catch (IOException $exception) {
throw new BlueprintException("Failed to move the file from {$fromPath} at {$toPath}", 0, $exception);
}
}
}
Expand Down

0 comments on commit a44e523

Please sign in to comment.