From 0b9f2a02ab8b74a03e8b9c42f30120b5861fb61c Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sat, 19 Nov 2011 10:36:37 +0100 Subject: [PATCH 1/2] MDL-30349 make sure file stat cache is reset properly after each remove_dir() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Typo3 does this, maybe it works around some PHP bugs… --- lib/moodlelib.php | 7 ++++--- lib/setuplib.php | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index b5ea4586750..71ae951b076 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -1437,8 +1437,6 @@ function purge_all_caches() { // hack: this script may get called after the purifier was initialised, // but we do not want to verify repeatedly this exists in each call make_cache_directory('htmlpurifier'); - - clearstatcache(); } /** @@ -9867,9 +9865,12 @@ function remove_dir($dir, $content_only=false) { } closedir($handle); if ($content_only) { + clearstatcache(); // make sure file stat cache is properly invalidated return $result; } - return rmdir($dir); // if anything left the result will be false, no need for && $result + $result = rmdir($dir); // if anything left the result will be false, no need for && $result + clearstatcache(); // make sure file stat cache is properly invalidated + return $result; } /** diff --git a/lib/setuplib.php b/lib/setuplib.php index bdb287d50dd..4d60011a1b6 100644 --- a/lib/setuplib.php +++ b/lib/setuplib.php @@ -1077,6 +1077,10 @@ function redirect_if_major_upgrade_required() { * files outside of dataroot if you supply custom paths for some settings in config.php. * This function does not verify that the directory is writable. * + * NOTE: this function uses current file stat cache, + * please use clearstatcache() before this if you expect that the + * directories may have been removed recently from a different request. + * * @param string $dir absolute directory path * @param boolean $create directory if does not exist * @param boolean $recursive create directory recursively From e164a0dfeaefcf654d1d5d2cda729f3123fa178a Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sat, 19 Nov 2011 10:40:56 +0100 Subject: [PATCH 2/2] MDL-30349 clear file stat cache when adding new theme cache files Hopefully this will resolve some cache reset problems. --- theme/image.php | 3 +++ theme/javascript.php | 3 +++ theme/styles.php | 3 +++ 3 files changed, 9 insertions(+) diff --git a/theme/image.php b/theme/image.php index e00f5592f7f..db469793989 100644 --- a/theme/image.php +++ b/theme/image.php @@ -115,6 +115,9 @@ if ($rev > -1) { $pathinfo = pathinfo($imagefile); $cacheimage = "$candidatelocation/$image.".$pathinfo['extension']; if (!file_exists($cacheimage)) { + // note: cache reset might have purged our cache dir structure, + // make sure we do not use stale file stat cache in the next check_dir_exists() + clearstatcache(); check_dir_exists(dirname($cacheimage)); copy($imagefile, $cacheimage); } diff --git a/theme/javascript.php b/theme/javascript.php index 6e8a79d785b..986c25c20f8 100644 --- a/theme/javascript.php +++ b/theme/javascript.php @@ -77,6 +77,9 @@ require_once('Minify.php'); $theme = theme_config::load($themename); if ($rev > -1) { + // note: cache reset might have purged our cache dir structure, + // make sure we do not use stale file stat cache in the next check_dir_exists() + clearstatcache(); check_dir_exists(dirname($candidate)); $fp = fopen($candidate, 'w'); fwrite($fp, minify($theme->javascript_files($type))); diff --git a/theme/styles.php b/theme/styles.php index 6fcde59e1b6..7f68abacb97 100644 --- a/theme/styles.php +++ b/theme/styles.php @@ -113,6 +113,9 @@ send_cached_css($candidatesheet, $rev); function store_css(theme_config $theme, $csspath, $cssfiles) { $css = $theme->post_process(minify($cssfiles)); + // note: cache reset might have purged our cache dir structure, + // make sure we do not use stale file stat cache in the next check_dir_exists() + clearstatcache(); check_dir_exists(dirname($csspath)); $fp = fopen($csspath, 'w'); fwrite($fp, $css);