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
This commit is contained in:
parent
05981179e4
commit
5021d218ef
|
@ -1830,6 +1830,14 @@ function wp_mkdir_p( $target ) {
|
||||||
* @return bool True if path is absolute, false is not absolute.
|
* @return bool True if path is absolute, false is not absolute.
|
||||||
*/
|
*/
|
||||||
function path_is_absolute( $path ) {
|
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
|
* This is definitive if true but fails if $path does not exist or contains
|
||||||
* a symbolic link.
|
* a symbolic link.
|
||||||
|
@ -6269,10 +6277,15 @@ function wp_delete_file( $file ) {
|
||||||
* @return bool True on success, false on failure.
|
* @return bool True on success, false on failure.
|
||||||
*/
|
*/
|
||||||
function wp_delete_file_from_directory( $file, $directory ) {
|
function wp_delete_file_from_directory( $file, $directory ) {
|
||||||
$real_file = realpath( wp_normalize_path( $file ) );
|
if ( wp_is_stream( $file ) ) {
|
||||||
$real_directory = realpath( wp_normalize_path( $directory ) );
|
$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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue