Skip to content

Commit 5b7a0d6

Browse files
committed
resolve_path in MkdirRecursive
1 parent d1f1f3a commit 5b7a0d6

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

components/Filesystem/LocalFilesystem.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,19 @@ public function copy_file( $from_path, $to_path, $options ) {
109109
}
110110

111111
protected function mkdir_single( $path, $options = array() ) {
112-
$path = $this->resolve_path( $path );
112+
$resolved_path = $this->resolve_path( $path );
113113
if ( $this->exists( $path ) ) {
114114
throw new FilesystemException(
115115
sprintf( 'Path already exists: %s', $path )
116116
);
117117
}
118-
if ( false === mkdir( $path ) ) {
118+
if ( false === @mkdir( $resolved_path ) ) {
119119
throw new FilesystemException(
120-
sprintf( 'Failed to create directory: %s', $path )
120+
sprintf( 'Failed to create directory: %s (%s)', $resolved_path, $path )
121121
);
122122
}
123123
if ( isset( $options['chmod'] ) ) {
124-
if ( false === chmod( $path, $options['chmod'] ) ) {
124+
if ( false === @chmod( $path, $options['chmod'] ) ) {
125125
throw new FilesystemException(
126126
sprintf( 'Failed to chmod directory: %s', $path )
127127
);

components/Filesystem/Mixin/MkdirRecursive.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
trait MkdirRecursive {
1414

1515
public function mkdir( $path, $options = array() ) {
16+
// Windows paths compatibility for LocalFilesystem:
17+
if(method_exists($this, 'resolve_path')) {
18+
$path = $this->resolve_path( $path );
19+
}
20+
1621
$recursive = $options['recursive'] ?? false;
1722
if ( ! $recursive ) {
1823
$this->mkdir_single( $path, $options );
@@ -33,6 +38,12 @@ public function mkdir( $path, $options = array() ) {
3338
*/
3439
$root = rtrim( $this->get_root(), '/' ) . '/';
3540
$path = rtrim( $path, '/' ) . '/';
41+
42+
// Windows paths compatibility for LocalFilesystem:
43+
if(method_exists($this, 'resolve_path')) {
44+
$root = $this->resolve_path( $root );
45+
$path = $this->resolve_path( $path );
46+
}
3647
if ( strncmp( $path, $root, strlen( $root ) ) !== 0 ) {
3748
throw new FilesystemException( sprintf( 'Path %s is not within the root %s', $path, $root ) );
3849
}

0 commit comments

Comments
 (0)