Filesystem API: Attempt to create directory in copy_dir().

Adds a check to the start of `copy_dir()` that the destination directory exists and attempts to create it if it does not.

An error is returned if the directory can not be created, either due to a permissions error or the parent directory not existing.

Props caraffande, costdev, zunaid321.
Fixes #41855.



git-svn-id: https://develop.svn.wordpress.org/trunk@55938 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Peter Wilson
2023-06-19 01:58:25 +00:00
parent 1e090291f0
commit 7cfc7a46f9
2 changed files with 91 additions and 0 deletions

View File

@@ -1910,6 +1910,14 @@ function copy_dir( $from, $to, $skip_list = array() ) {
$from = trailingslashit( $from );
$to = trailingslashit( $to );
if ( ! $wp_filesystem->exists( $to ) && ! $wp_filesystem->mkdir( $to ) ) {
return new WP_Error(
'mkdir_destination_failed_copy_dir',
__( 'Could not create the destination directory.' ),
basename( $to )
);
}
foreach ( (array) $dirlist as $filename => $fileinfo ) {
if ( in_array( $filename, $skip_list, true ) ) {
continue;