diff options
Diffstat (limited to '')
-rw-r--r-- | lib/less.php/Cache.php | 76 |
1 files changed, 40 insertions, 36 deletions
diff --git a/lib/less.php/Cache.php b/lib/less.php/Cache.php index bf5bf92..40d0358 100644 --- a/lib/less.php/Cache.php +++ b/lib/less.php/Cache.php @@ -207,6 +207,7 @@ class Less_Cache{ public static function SetCacheDir( $dir ){ Less_Cache::$cache_dir = $dir; + self::CheckCacheDir(); } public static function CheckCacheDir(){ @@ -237,60 +238,63 @@ class Less_Cache{ public static function CleanCache(){ static $clean = false; - if( $clean ){ + + if( $clean || empty(Less_Cache::$cache_dir) ){ return; } + $clean = true; + + // only remove files with extensions created by less.php + // css files removed based on the list files + $remove_types = array('lesscache'=>1,'list'=>1,'less'=>1,'map'=>1); + $files = scandir(Less_Cache::$cache_dir); - if( $files ){ - $check_time = time() - self::$gc_lifetime; - foreach($files as $file){ + if( !$files ){ + return; + } - // don't delete if the file wasn't created with less.php - if( strpos($file,Less_Cache::$prefix) !== 0 ){ - continue; - } + $check_time = time() - self::$gc_lifetime; + foreach($files as $file){ - $full_path = Less_Cache::$cache_dir . $file; - // make sure the file still exists - // css files may have already been deleted - if( !file_exists($full_path) ){ - continue; - } - $mtime = filemtime($full_path); + // don't delete if the file wasn't created with less.php + if( strpos($file,Less_Cache::$prefix) !== 0 ){ + continue; + } - // don't delete if it's a relatively new file - if( $mtime > $check_time ){ - continue; - } + $parts = explode('.',$file); + $type = array_pop($parts); - $parts = explode('.',$file); - $type = array_pop($parts); + if( !isset($remove_types[$type]) ){ + continue; + } - // delete css files based on the list files - if( $type === 'css' ){ - continue; - } + $full_path = Less_Cache::$cache_dir . $file; + $mtime = filemtime($full_path); + // don't delete if it's a relatively new file + if( $mtime > $check_time ){ + continue; + } - // delete the list file and associated css file - if( $type === 'list' ){ - self::ListFiles($full_path, $list, $css_file_name); - if( $css_file_name ){ - $css_file = Less_Cache::$cache_dir . $css_file_name; - if( file_exists($css_file) ){ - unlink($css_file); - } + + // delete the list file and associated css file + if( $type === 'list' ){ + self::ListFiles($full_path, $list, $css_file_name); + if( $css_file_name ){ + $css_file = Less_Cache::$cache_dir . $css_file_name; + if( file_exists($css_file) ){ + unlink($css_file); } } - - unlink($full_path); } + + unlink($full_path); } - $clean = true; + } |