From 1b35ea6978f4ca1d3084a4c355037687c9cc225b Mon Sep 17 00:00:00 2001 From: Joe McGill Date: Fri, 12 Apr 2019 20:01:52 +0000 Subject: [PATCH] Media: Fix deletion of files when using stream wrappers. This fixes a bug introduced in [43392] which breaks file deletion on systems using stream wrappers, due to limitations of `realpath()`. Props antonypuckey, pfiled. Fixes #44563. Built from https://develop.svn.wordpress.org/trunk@45177 git-svn-id: http://core.svn.wordpress.org/trunk@44986 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 19 ++++++++++++++++--- wp-includes/version.php | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 6a30a598c3..c222bc52a8 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -1830,6 +1830,14 @@ function wp_mkdir_p( $target ) { * @return bool True if path is absolute, false is not absolute. */ function path_is_absolute( $path ) { + /* + * Check to see if the path is a stream and check to see if its an actual + * path or file as realpath() does not support stream wrappers. + */ + if ( wp_is_stream( $path ) && ( is_dir( $path ) || is_file( $path ) ) ) { + return true; + } + /* * This is definitive if true but fails if $path does not exist or contains * a symbolic link. @@ -6269,10 +6277,15 @@ function wp_delete_file( $file ) { * @return bool True on success, false on failure. */ function wp_delete_file_from_directory( $file, $directory ) { - $real_file = realpath( wp_normalize_path( $file ) ); - $real_directory = realpath( wp_normalize_path( $directory ) ); + if ( wp_is_stream( $file ) ) { + $real_file = wp_normalize_path( $file ); + $real_directory = wp_normalize_path( $directory ); + } else { + $real_file = realpath( wp_normalize_path( $file ) ); + $real_directory = realpath( wp_normalize_path( $directory ) ); + } - if ( false === $real_file || false === $real_directory || strpos( wp_normalize_path( $real_file ), trailingslashit( wp_normalize_path( $real_directory ) ) ) !== 0 ) { + if ( false === $real_file || false === $real_directory || strpos( $real_file, trailingslashit( $real_directory ) ) !== 0 ) { return false; } diff --git a/wp-includes/version.php b/wp-includes/version.php index c09f3fbafb..90176cd21d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.2-beta2-45176'; +$wp_version = '5.2-beta2-45177'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.