From 80ecab6fab670ff85339bb204b4c951971e5fd0d Mon Sep 17 00:00:00 2001
From: Paul Biron <paul@sparrowhawkcomputing.com>
Date: Thu, 6 May 2021 19:02:02 -0600
Subject: [PATCH] Refresh patch, and incorporate the Windows-specific changes
to WP_Filesystem_Direct::delete() from
https://core.trac.wordpress.org/attachment/ticket/36710/36710.6.diff.
---
.../includes/class-wp-filesystem-direct.php | 32 ++++++++++++++++---
src/wp-admin/includes/class-wp-upgrader.php | 4 ++-
2 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/src/wp-admin/includes/class-wp-filesystem-direct.php b/src/wp-admin/includes/class-wp-filesystem-direct.php
index 099d9814af..661e52fd1d 100644
a
|
b
|
class WP_Filesystem_Direct extends WP_Filesystem_Base { |
365 | 365 | |
366 | 366 | $file = str_replace( '\\', '/', $file ); // For Win32, occasional problems deleting files otherwise. |
367 | 367 | |
368 | | if ( 'f' === $type || $this->is_file( $file ) ) { |
369 | | return @unlink( $file ); |
| 368 | if ( 'f' === $type || $this->is_file( $file ) || $this->is_link( $file ) ) { |
| 369 | if ( 'WIN' === strtoupper( substr( PHP_OS, 0, 3 ) ) && |
| 370 | $this->is_link( $file ) && $this->is_dir( $file ) ) { |
| 371 | // on windows unlink()'ing a symlink that points to a directory fails. |
| 372 | // @link https://bugs.php.net/bug.php?id=52176 |
| 373 | return @rmdir( $file ); |
| 374 | } else { |
| 375 | // untrailingslashit() needed to remove symlinks successfully. |
| 376 | return @unlink( untrailingslashit( $file ) ); |
| 377 | } |
370 | 378 | } |
371 | 379 | |
372 | 380 | if ( ! $recursive && $this->is_dir( $file ) ) { |
… |
… |
class WP_Filesystem_Direct extends WP_Filesystem_Base { |
454 | 462 | return @is_writable( $file ); |
455 | 463 | } |
456 | 464 | |
| 465 | /** |
| 466 | * Checks if a file or directory is a symbolic link. |
| 467 | * |
| 468 | * @since 5.8.0 |
| 469 | * |
| 470 | * @param string $file Path to file or directory. |
| 471 | * @return bool Whether $file is a symbolic link. |
| 472 | */ |
| 473 | public function is_link( $file ) { |
| 474 | // Strip trailing slashes, to avoid directory symlinks resolving. |
| 475 | return @is_link( untrailingslashit( $file ) ); |
| 476 | } |
| 477 | |
457 | 478 | /** |
458 | 479 | * Gets the file's last access time. |
459 | 480 | * |
… |
… |
class WP_Filesystem_Direct extends WP_Filesystem_Base { |
599 | 620 | * } |
600 | 621 | */ |
601 | 622 | public function dirlist( $path, $include_hidden = true, $recursive = false ) { |
602 | | if ( $this->is_file( $path ) ) { |
| 623 | if ( $this->is_dir( $path ) && $this->is_link( $path ) ) { |
| 624 | // Directory is symlink, therefore return no listing. |
| 625 | return array(); |
| 626 | } elseif ( $this->is_file( $path ) || $this->is_link( $path ) ) { |
603 | 627 | $limit_file = basename( $path ); |
604 | 628 | $path = dirname( $path ); |
605 | 629 | } else { |
… |
… |
class WP_Filesystem_Direct extends WP_Filesystem_Base { |
645 | 669 | $struc['time'] = gmdate( 'h:i:s', $struc['lastmodunix'] ); |
646 | 670 | $struc['type'] = $this->is_dir( $path . '/' . $entry ) ? 'd' : 'f'; |
647 | 671 | |
648 | | if ( 'd' === $struc['type'] ) { |
| 672 | if ( 'd' === $struc['type'] && !$this->is_link( $path . '/' . $struc['name'] )) { |
649 | 673 | if ( $recursive ) { |
650 | 674 | $struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive ); |
651 | 675 | } else { |
diff --git a/src/wp-admin/includes/class-wp-upgrader.php b/src/wp-admin/includes/class-wp-upgrader.php
index e456191dae..3f870d3925 100644
a
|
b
|
class WP_Upgrader { |
402 | 402 | if ( ! $wp_filesystem->is_writable( $remote_destination . $filename ) ) { |
403 | 403 | // Attempt to alter permissions to allow writes and try again. |
404 | 404 | $wp_filesystem->chmod( $remote_destination . $filename, ( 'd' === $file_details['type'] ? FS_CHMOD_DIR : FS_CHMOD_FILE ) ); |
405 | | if ( ! $wp_filesystem->is_writable( $remote_destination . $filename ) ) { |
| 405 | // is_writable() returns false on symlinks for some reason. |
| 406 | if ( ! $wp_filesystem->is_writable( $remote_destination . $filename ) |
| 407 | && ! $wp_filesystem->is_link( $remote_destination . $filename ) ) { |
406 | 408 | $unwritable_files[] = $filename; |
407 | 409 | } |
408 | 410 | } |