From 42fac405eae4dea2418f0db2701125dcf7238670 Mon Sep 17 00:00:00 2001 From: donncha Date: Thu, 9 Feb 2017 16:11:56 +0000 Subject: [PATCH 1/3] realpath doesn't like array_walk and add file checks to rebuild realpath complained when using it in array_walk so go back to a simple foreach loop. The rebuild or gc function didn't have much checking to make sure it wasn't deleting files it shouldn't be so this adds more, because I'm paranoid. --- wp-cache-phase1.php | 6 ++++-- wp-cache-phase2.php | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/wp-cache-phase1.php b/wp-cache-phase1.php index 734eef414510a..f84efc20a4541 100644 --- a/wp-cache-phase1.php +++ b/wp-cache-phase1.php @@ -645,8 +645,10 @@ function wpsc_delete_files( $dir, $delete = true ) { // only do this once, this function will be called many times if ( $rp_cache_path == '' ) { - $protected = array( $cache_path, $cache_path . $blog_cache_dir, get_supercache_dir() ); - $protected = array_walk( array_walk( $protected, 'realpath' ), 'trailingslashit' ); + $protected = array( $cache_path, $cache_path . "blogs/", get_supercache_dir() ); + foreach( $protected as $id => $directory ) { + $protected[ $id ] = trailingslashit( realpath( $directory ) ); + } $rp_cache_path = trailingslashit( realpath( $cache_path ) ); } diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php index 3d9dfeab68922..238ec5ed50bda 100644 --- a/wp-cache-phase2.php +++ b/wp-cache-phase2.php @@ -78,8 +78,10 @@ function wpcache_do_rebuild( $dir ) { global $do_rebuild_list, $cache_path, $blog_cache_dir; $dir = trailingslashit( realpath( $dir ) ); - $protected = array( $cache_path, $cache_path . $blog_cache_dir, get_supercache_dir() ); - $protected = array_walk( array_walk( $protected, 'realpath' ), 'trailingslashit' ); + $protected = array( $cache_path, $cache_path . "blogs/", get_supercache_dir() ); + foreach( $protected as $id => $directory ) { + $protected[ $id ] = trailingslashit( realpath( $directory ) ); + } $rp_cache_path = trailingslashit( realpath( $cache_path ) ); if ( substr( $dir, 0, strlen( $rp_cache_path ) ) != $rp_cache_path ) @@ -844,12 +846,24 @@ function wp_cache_rebuild_or_delete( $file ) { if ( strpos( $file, '?' ) !== false ) $file = substr( $file, 0, strpos( $file, '?' ) ); + $file = realpath( $file ); + if ( substr( $file, 0, strlen( $rp_cache_path ) ) != $rp_cache_path ) { wp_cache_debug( "rebuild_or_gc quitting because file is not in cache_path: $file" ); return false; } + if ( $protected == '' ) { + $protected = array( $cache_path . "index.html", get_supercache_dir() . "index.html", $cache_path . "blogs/index.html" ); + foreach( $protected as $id => $directory ) { + $protected[ $id ] = trailingslashit( realpath( $directory ) ); + } + } + + if ( in_array( $file, $protected ) ) + return false; + if( $cache_rebuild_files && substr( $file, -14 ) != '.needs-rebuild' ) { if( @rename($file, $file . '.needs-rebuild') ) { @touch( $file . '.needs-rebuild' ); From 14b6ab1e04c416cdb817631e4c90d7c87c779020 Mon Sep 17 00:00:00 2001 From: donncha Date: Thu, 9 Feb 2017 16:18:42 +0000 Subject: [PATCH 2/3] No need for $blog_cache_dir in these functions --- wp-cache-phase1.php | 2 +- wp-cache-phase2.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/wp-cache-phase1.php b/wp-cache-phase1.php index f84efc20a4541..7189f15192868 100644 --- a/wp-cache-phase1.php +++ b/wp-cache-phase1.php @@ -639,7 +639,7 @@ function wpsc_rebuild_files( $dir ) { } function wpsc_delete_files( $dir, $delete = true ) { - global $cache_path, $blog_cache_dir; + global $cache_path; static $rp_cache_path = ''; static $protected = ''; diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php index 238ec5ed50bda..2e0d4975e8108 100644 --- a/wp-cache-phase2.php +++ b/wp-cache-phase2.php @@ -75,7 +75,7 @@ function wp_cache_phase2() { } function wpcache_do_rebuild( $dir ) { - global $do_rebuild_list, $cache_path, $blog_cache_dir; + global $do_rebuild_list, $cache_path; $dir = trailingslashit( realpath( $dir ) ); $protected = array( $cache_path, $cache_path . "blogs/", get_supercache_dir() ); From 7b474adb5ab28a900c37289acc7907495a871862 Mon Sep 17 00:00:00 2001 From: donncha Date: Thu, 9 Feb 2017 16:19:18 +0000 Subject: [PATCH 3/3] Move this check up to avoid more expensive checks --- wp-cache-phase2.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php index 2e0d4975e8108..ab711d3200ffc 100644 --- a/wp-cache-phase2.php +++ b/wp-cache-phase2.php @@ -78,6 +78,10 @@ function wpcache_do_rebuild( $dir ) { global $do_rebuild_list, $cache_path; $dir = trailingslashit( realpath( $dir ) ); + + if ( isset( $do_rebuild_list[ $dir ] ) ) + return false; + $protected = array( $cache_path, $cache_path . "blogs/", get_supercache_dir() ); foreach( $protected as $id => $directory ) { $protected[ $id ] = trailingslashit( realpath( $directory ) ); @@ -90,9 +94,6 @@ function wpcache_do_rebuild( $dir ) { if ( in_array( $dir, $protected ) ) return false; - if ( isset( $do_rebuild_list[ $dir ] ) ) - return false; - if ( is_dir( $dir ) && $dh = @opendir( $dir ) ) { while ( ( $file = readdir( $dh ) ) !== false ) { if ( $file != '.' && $file != '..' && is_file( $dir . $file ) ) {