aboutsummaryrefslogtreecommitdiff
path: root/lib/less.php/Cache.php
diff options
context:
space:
mode:
authorderchris2019-02-04 13:11:28 +0100
committerderchris2019-02-04 13:11:28 +0100
commitfd72b0f50a355006069c5a336441f08beb7d3c50 (patch)
tree771ae594586840cb7c7c4fdedeb15e2ca3cf2d2b /lib/less.php/Cache.php
parent2ea11c4a04371adbc865678dd6eca12aefca0013 (diff)
Revert "update less.php to PHP 7.x compatible fork"
This reverts commit 7ad9f272a482802da2d43fe83841adbe9bcd8cb4.
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;
}