Merge branch 'hotfix/#1072-fix-iteration-of-file-lock-region-on-no-match'
Close #1072
This commit is contained in:
commit
a88726d84e
@ -201,9 +201,15 @@ class FileLockRegion implements ConcurrentRegion
|
||||
*/
|
||||
public function evictAll()
|
||||
{
|
||||
foreach (glob(sprintf("%s/*.%s" , $this->directory, self::LOCK_EXTENSION)) as $filename) {
|
||||
// The check below is necessary because on some platforms glob returns false
|
||||
// when nothing matched (even though no errors occurred)
|
||||
$filenames = glob(sprintf("%s/*.%s" , $this->directory, self::LOCK_EXTENSION));
|
||||
|
||||
if ($filenames) {
|
||||
foreach ($filenames as $filename) {
|
||||
@unlink($filename);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->region->evictAll();
|
||||
}
|
||||
|
@ -27,17 +27,12 @@ class FileLockRegionTest extends AbstractRegionTest
|
||||
*/
|
||||
protected $directory;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
if ( ! is_dir($this->directory)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->directory), RecursiveIteratorIterator::CHILD_FIRST) as $file) {
|
||||
$file->isFile()
|
||||
? @unlink($file->getRealPath())
|
||||
: @rmdir($file->getRealPath());
|
||||
}
|
||||
$this->cleanTestDirectory($this->directory);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -247,4 +242,46 @@ class FileLockRegionTest extends AbstractRegionTest
|
||||
$this->assertNotNull($this->region->get($key));
|
||||
$this->assertFileNotExists($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group 1072
|
||||
* @group DDC-3191
|
||||
*/
|
||||
public function testHandlesScanErrorsGracefullyOnEvictAll()
|
||||
{
|
||||
$region = $this->createRegion();
|
||||
$reflectionDirectory = new \ReflectionProperty($region, 'directory');
|
||||
|
||||
$reflectionDirectory->setAccessible(true);
|
||||
$reflectionDirectory->setValue($region, str_repeat('a', 10000));
|
||||
|
||||
set_error_handler(function () {}, E_WARNING);
|
||||
$this->assertTrue($region->evictAll());
|
||||
restore_error_handler();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $path directory to clean
|
||||
*/
|
||||
private function cleanTestDirectory($path)
|
||||
{
|
||||
$path = $path ?: $this->directory;
|
||||
|
||||
if ( ! is_dir($path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$directoryIterator = new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($path),
|
||||
RecursiveIteratorIterator::CHILD_FIRST
|
||||
);
|
||||
|
||||
foreach ($directoryIterator as $file) {
|
||||
if ($file->isFile()) {
|
||||
@unlink($file->getRealPath());
|
||||
} else {
|
||||
@rmdir($file->getRealPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -393,9 +393,11 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
|
||||
return unlink($path);
|
||||
} else if (is_dir($path)) {
|
||||
$files = glob(rtrim($path,'/').'/*');
|
||||
if (is_array($files)) {
|
||||
foreach ($files as $file){
|
||||
$this->_deleteDirectory($file);
|
||||
}
|
||||
}
|
||||
return rmdir($path);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user