| 2086 | | /* |
| 2087 | | * If a umask is set that modifies $dir_perms, we'll have to re-set |
| 2088 | | * the $dir_perms correctly with chmod() |
| 2089 | | */ |
| 2090 | | if ( ( $dir_perms & ~umask() ) !== $dir_perms ) { |
| 2091 | | $folder_parts = explode( '/', substr( $target, strlen( $target_parent ) + 1 ) ); |
| 2092 | | for ( $i = 1, $c = count( $folder_parts ); $i <= $c; $i++ ) { |
| 2093 | | chmod( $target_parent . '/' . implode( '/', array_slice( $folder_parts, 0, $i ) ), $dir_perms ); |
| | 2088 | /* |
| | 2089 | * If a umask is set that modifies $dir_perms, we'll have to re-set |
| | 2090 | * the $dir_perms correctly with chmod() |
| | 2091 | */ |
| | 2092 | if ( ( $dir_perms & ~umask() ) !== $dir_perms ) { |
| | 2093 | $is_chmod_required = true; |
| | 2094 | } else { |
| | 2095 | $is_chmod_required = false; |
| | 2096 | } |
| | 2097 | |
| | 2098 | /* |
| | 2099 | * We cannot use mkdir()'s own built-in recursive functionality |
| | 2100 | * (when the third argument is true) because it returns an error |
| | 2101 | * if the directory already exists. |
| | 2102 | * See https://core.trac.wordpress.org/ticket/60855. |
| | 2103 | */ |
| | 2104 | |
| | 2105 | $folder_parts = explode( '/', substr( $target, strlen( $target_parent ) + 1 ) ); |
| | 2106 | for ( $i = 1, $c = count( $folder_parts ); $i <= $c; $i++ ) { |
| | 2107 | $intermediate_dir = $target_parent . '/' . implode( '/', array_slice( $folder_parts, 0, $i ) ); |
| | 2108 | if ( @mkdir( $intermediate_dir ) ) { |
| | 2109 | /* |
| | 2110 | * The mkdir() call succeeded - set permissions if necessary and continue. |
| | 2111 | */ |
| | 2112 | if ( $is_chmod_required ) { |
| | 2113 | chmod( $intermediate_dir, $dir_perms ); |
| | 2114 | } |
| | 2115 | continue; |
| | 2116 | } else { |
| | 2117 | /* |
| | 2118 | * The mkdir() call failed - try to find out why. |
| | 2119 | */ |
| | 2120 | if ( file_exists( $intermediate_dir ) ) { |
| | 2121 | /* |
| | 2122 | * It seems that $intermediate_dir already exists. |
| | 2123 | * If it's a directory, we can simply proceed to the next iteration. |
| | 2124 | * If it's not a directory, then return failure. |
| | 2125 | */ |
| | 2126 | if ( is_dir( $intermediate_dir ) ) { |
| | 2127 | continue; |
| | 2128 | } else { |
| | 2129 | return false; |
| | 2130 | } |
| | 2131 | } else { |
| | 2132 | /* |
| | 2133 | * It seems that $intermediate_dir does not exist. |
| | 2134 | * Return failure. |
| | 2135 | */ |
| | 2136 | return false; |