aboutsummaryrefslogtreecommitdiff
path: root/lib/less.php/Cache.php
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/less.php/Cache.php76
1 files changed, 36 insertions, 40 deletions
diff --git a/lib/less.php/Cache.php b/lib/less.php/Cache.php
index 40d0358..bf5bf92 100644
--- a/lib/less.php/Cache.php
+++ b/lib/less.php/Cache.php
@@ -207,7 +207,6 @@ class Less_Cache{
public static function SetCacheDir( $dir ){
Less_Cache::$cache_dir = $dir;
- self::CheckCacheDir();
}
public static function CheckCacheDir(){
@@ -238,63 +237,60 @@ class Less_Cache{
public static function CleanCache(){
static $clean = false;
-
- if( $clean || empty(Less_Cache::$cache_dir) ){
+ if( $clean ){
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 ){
- return;
- }
-
- $check_time = time() - self::$gc_lifetime;
- foreach($files as $file){
+ if( $files ){
+ $check_time = time() - self::$gc_lifetime;
+ foreach($files as $file){
+ // don't delete if the file wasn't created with less.php
+ if( strpos($file,Less_Cache::$prefix) !== 0 ){
+ continue;
+ }
- // don't delete if the file wasn't created with less.php
- if( strpos($file,Less_Cache::$prefix) !== 0 ){
- continue;
- }
+ $full_path = Less_Cache::$cache_dir . $file;
- $parts = explode('.',$file);
- $type = array_pop($parts);
+ // 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 it's a relatively new file
+ if( $mtime > $check_time ){
+ continue;
+ }
- if( !isset($remove_types[$type]) ){
- continue;
- }
+ $parts = explode('.',$file);
+ $type = array_pop($parts);
- $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 css files based on the list files
+ if( $type === 'css' ){
+ 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;
}