Merge pull request #2695 from guillaumelecerf/fix_cache_gc_with_cachedir_devnull

Fix Cache::gc() when COMPOSER_CACHE_DIR=/dev/null
main
Jordi Boggiano 11 years ago
commit 93da24b45a

@ -144,28 +144,33 @@ class Cache
public function gc($ttl, $maxSize) public function gc($ttl, $maxSize)
{ {
$expire = new \DateTime(); if ($this->enabled)
$expire->modify('-'.$ttl.' seconds'); {
$expire = new \DateTime();
$finder = $this->getFinder()->date('until '.$expire->format('Y-m-d H:i:s')); $expire->modify('-'.$ttl.' seconds');
foreach ($finder as $file) {
unlink($file->getRealPath()); $finder = $this->getFinder()->date('until '.$expire->format('Y-m-d H:i:s'));
} foreach ($finder as $file) {
unlink($file->getRealPath());
}
$totalSize = $this->filesystem->size($this->root); $totalSize = $this->filesystem->size($this->root);
if ($totalSize > $maxSize) { if ($totalSize > $maxSize) {
$iterator = $this->getFinder()->sortByAccessedTime()->getIterator(); $iterator = $this->getFinder()->sortByAccessedTime()->getIterator();
while ($totalSize > $maxSize && $iterator->valid()) { while ($totalSize > $maxSize && $iterator->valid()) {
$filepath = $iterator->current()->getRealPath(); $filepath = $iterator->current()->getRealPath();
$totalSize -= $this->filesystem->size($filepath); $totalSize -= $this->filesystem->size($filepath);
unlink($filepath); unlink($filepath);
$iterator->next(); $iterator->next();
}
} }
}
self::$cacheCollected = true; self::$cacheCollected = true;
return true; return true;
}
return false;
} }
public function sha1($file) public function sha1($file)

Loading…
Cancel
Save