Fix Cache::gc() when COMPOSER_CACHE_DIR=/dev/null
If we set COMPOSER_CACHE_DIR=/dev/null, and the garbage collector is triggered, we end up with the following error : The "/dev/null/" directory does not exist. This is because the Cache::gc() function does not check for Cache::enabled and instanciates a Finder unconditionnaly. Fix this by adding a check on Cache::enabled.pull/2695/head
parent
7343198817
commit
44fd75ef38
|
@ -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();
|
||||||
|
$expire->modify('-'.$ttl.' seconds');
|
||||||
|
|
||||||
$finder = $this->getFinder()->date('until '.$expire->format('Y-m-d H:i:s'));
|
$finder = $this->getFinder()->date('until '.$expire->format('Y-m-d H:i:s'));
|
||||||
foreach ($finder as $file) {
|
foreach ($finder as $file) {
|
||||||
unlink($file->getRealPath());
|
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$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 false;
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sha1($file)
|
public function sha1($file)
|
||||||
|
|
Loading…
Reference in New Issue