From 0dc29dada36f8bcbeea7de34675afd0a2659cdd6 Mon Sep 17 00:00:00 2001
From: Paul Biron <paul@sparrowhawkcomputing.com>
Date: Wed, 5 May 2021 19:37:12 -0600
Subject: [PATCH] Refresh patch so that it cleanly applies.
---
.../includes/class-wp-filesystem-direct.php | 34 ++++++++++++++++---
1 file changed, 30 insertions(+), 4 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..8e409a61d8 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 | } |
| 375 | else { |
| 376 | // untrailingslashit() needed to remove symlinks successfully. |
| 377 | return @unlink( untrailingslashit( $file ) ); |
| 378 | } |
370 | 379 | } |
371 | 380 | |
372 | 381 | if ( ! $recursive && $this->is_dir( $file ) ) { |
… |
… |
class WP_Filesystem_Direct extends WP_Filesystem_Base { |
406 | 415 | return @file_exists( $file ); |
407 | 416 | } |
408 | 417 | |
| 418 | /** |
| 419 | * Checks if resource is a symbolic link. |
| 420 | * |
| 421 | * @since 5.5.0 |
| 422 | * |
| 423 | * @param string $file File path. |
| 424 | * @return bool Whther `$file` is a symbolic link. |
| 425 | */ |
| 426 | public function is_link( $file ) { |
| 427 | // Strip trailing slashes, to avoid directory symlinks resolving. |
| 428 | return @is_link( untrailingslashit( $file ) ); |
| 429 | } |
| 430 | |
409 | 431 | /** |
410 | 432 | * Checks if resource is a file. |
411 | 433 | * |
… |
… |
class WP_Filesystem_Direct extends WP_Filesystem_Base { |
599 | 621 | * } |
600 | 622 | */ |
601 | 623 | public function dirlist( $path, $include_hidden = true, $recursive = false ) { |
602 | | if ( $this->is_file( $path ) ) { |
| 624 | if ( $this->is_dir( $path ) && $this->is_link( $path ) ) { |
| 625 | // Directory is a symlink, therefore return no listing. |
| 626 | return array(); |
| 627 | } |
| 628 | elseif ( $this->is_file( $path ) || $this->is_link( $path ) ) { |
603 | 629 | $limit_file = basename( $path ); |
604 | 630 | $path = dirname( $path ); |
605 | 631 | } else { |
… |
… |
class WP_Filesystem_Direct extends WP_Filesystem_Base { |
645 | 671 | $struc['time'] = gmdate( 'h:i:s', $struc['lastmodunix'] ); |
646 | 672 | $struc['type'] = $this->is_dir( $path . '/' . $entry ) ? 'd' : 'f'; |
647 | 673 | |
648 | | if ( 'd' === $struc['type'] ) { |
| 674 | if ( 'd' === $struc['type'] && ! $this->is_link( $path . '/' . $struc['name'] ) ) { |
649 | 675 | if ( $recursive ) { |
650 | 676 | $struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive ); |
651 | 677 | } else { |