From 5021d218efc445f963a75d158bc48ab68ba44d26 Mon Sep 17 00:00:00 2001 From: Joe McGill Date: Fri, 12 Apr 2019 20:00:42 +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. git-svn-id: https://develop.svn.wordpress.org/trunk@45177 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/functions.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 6a30a598c3..c222bc52a8 100644 --- a/src/wp-includes/functions.php +++ b/src/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; }