1
0
Fork 0

Merge pull request #2695 from guillaumelecerf/fix_cache_gc_with_cachedir_devnull

Fix Cache::gc() when COMPOSER_CACHE_DIR=/dev/null
pull/2705/head
Jordi Boggiano 2014-02-13 15:59:07 +01:00
commit 93da24b45a
1 changed files with 23 additions and 18 deletions

View File

@ -144,28 +144,33 @@ class Cache
public function gc($ttl, $maxSize)
{
$expire = new \DateTime();
$expire->modify('-'.$ttl.' seconds');
if ($this->enabled)
{
$expire = new \DateTime();
$expire->modify('-'.$ttl.' seconds');
$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);
if ($totalSize > $maxSize) {
$iterator = $this->getFinder()->sortByAccessedTime()->getIterator();
while ($totalSize > $maxSize && $iterator->valid()) {
$filepath = $iterator->current()->getRealPath();
$totalSize -= $this->filesystem->size($filepath);
unlink($filepath);
$iterator->next();
$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);
if ($totalSize > $maxSize) {
$iterator = $this->getFinder()->sortByAccessedTime()->getIterator();
while ($totalSize > $maxSize && $iterator->valid()) {
$filepath = $iterator->current()->getRealPath();
$totalSize -= $this->filesystem->size($filepath);
unlink($filepath);
$iterator->next();
}
}
self::$cacheCollected = true;
return true;
}
self::$cacheCollected = true;
return true;
return false;
}
public function sha1($file)