Changeset 41821
- Timestamp:
- 10/11/2017 04:23:49 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-wp-upgrader.php
r41289 r41821 324 324 325 325 /** 326 * Flatten the results of WP_Filesystem::dirlist() for iterating over. 327 * 328 * @since 4.9.0 329 * @access protected 330 * 331 * @param array $nested_files Array of files as returned by WP_Filesystem::dirlist() 332 * @param string $path Relative path to prepend to child nodes. Optional. 333 * @return array $files A flattened array of the $nested_files specified. 334 */ 335 protected function flatten_dirlist( $nested_files, $path = '' ) { 336 $files = array(); 337 338 foreach ( $nested_files as $name => $details ) { 339 $files[ $path . $name ] = $details; 340 341 // Append children recursively 342 if ( ! empty( $details['files'] ) ) { 343 $children = $this->flatten_dirlist( $details['files'], $path . $name . '/' ); 344 345 $files = array_merge( $files, $children ); 346 } 347 } 348 349 return $files; 350 } 351 352 /** 326 353 * Clears the directory where this item is going to be installed into. 327 354 * … … 336 363 global $wp_filesystem; 337 364 338 if ( ! $wp_filesystem->exists( $remote_destination ) ) { 365 $files = $wp_filesystem->dirlist( $remote_destination, true, true ); 366 367 // False indicates that the $remote_destination doesn't exist. 368 if ( false === $files ) { 339 369 return true; 340 370 } 371 372 // Flatten the file list to iterate over 373 $files = $this->flatten_dirlist( $files ); 341 374 342 375 // Check all files are writable before attempting to clear the destination. 343 376 $unwritable_files = array(); 344 377 345 $_files = $wp_filesystem->dirlist( $remote_destination, true, true );346 347 // Flatten the resulting array, iterate using each as we append to the array during iteration.348 while ( $f = each( $_files ) ) {349 $file = $f['value'];350 $name = $f['key'];351 352 if ( ! isset( $file['files'] ) ) {353 continue;354 }355 356 foreach ( $file['files'] as $filename => $details ) {357 $_files[ $name . '/' . $filename ] = $details;358 }359 }360 361 378 // Check writability. 362 foreach ( $ _files as $filename => $file_details ) {379 foreach ( $files as $filename => $file_details ) { 363 380 if ( ! $wp_filesystem->is_writable( $remote_destination . $filename ) ) { 364 365 381 // Attempt to alter permissions to allow writes and try again. 366 382 $wp_filesystem->chmod( $remote_destination . $filename, ( 'd' == $file_details['type'] ? FS_CHMOD_DIR : FS_CHMOD_FILE ) );
Note: See TracChangeset
for help on using the changeset viewer.